Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more serialization libraries (kotlinx.serialization) and not only gson #885

Open
dnhyde opened this issue Mar 28, 2022 · 2 comments
Labels
enhancement New feature or request good-first-issue

Comments

@dnhyde
Copy link

dnhyde commented Mar 28, 2022

Are you requesting automatic instrumentation for a framework or library? Please describe.

Is your feature request related to a problem? Please describe.
When using JsonObject from kotlinx.serialization.json.JsonObject I end up having quotes in my logger "attributes" after using logger.addAttribute. I found out that your SDK uses gson internally in your Logger.kt. This forces integrators to add gson dependency as well to have attributes without quotes " (the expected result in the second image).

kotlinx.serialization google.gson
attributesKotlinxSerialization attributesGson

Describe the solution you'd like
I would love to have support for several serialization libraries (so that I am not dependent on gson). In particular it would be nice to have support for Kotlinx.serialization so that I can pass kotlinx.serialization.json.JsonObject as parameter.
Supporting:

kotlinx.serialization google.gson
logger.addAttribute(
   attribute, 
   parseToJsonElement(attributeJsonString).jsonObject
)
logger.addAttribute(
   attribute,
   gson.fromJson(attributeJsonString, JsonObject::class.java)
)

Describe alternatives you've considered
For now the only alternative that was feasible was to integrate gson in my code.
I think an alternative would be to add every field of the attribute manually but it sounds cumbersome and error prone.

@dnhyde dnhyde added the enhancement New feature or request label Mar 28, 2022
@xgouchet
Copy link
Member

Hi @dnhyde , thanks a lot for this feature request.
We totally understand that this would be an interesting feature, but we would need to find a way to support more serialization libraries with no added cost for our users. We do use Gson internally meaning that this is a dependency we will have no matter what, but adding support to other libraries (kotlinx.serialization, Moshi, …) will be an added cost for all of our customers, most of which won't use either.
We'll keep this feature request in mind and try to come up with a satisfying solution

@dnhyde
Copy link
Author

dnhyde commented Mar 28, 2022

Sure, I understand, maybe the approach that retrofit uses for converters could be a solution. Ideally it is possible to add even external converters on top of the existing ones as they did for kotlinx.serialization converter. Not sure if it feasible in your case, just an idea for the future :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good-first-issue
Projects
None yet
Development

No branches or pull requests

2 participants