-
Notifications
You must be signed in to change notification settings - Fork 133
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
Use [String: Any]
attributes instead of [String: Encodable]
?
#1422
Comments
Hello @crewshin 👋. The choice of Then, The problem you're hitting can be solved in a generic way with type erasures, not requiring so much hassle. To get some idea, I recommend you to look at our generic implementation of: and the Last resort, you can use our Objective-C SDK, which uses the notion of
I hope this answers the question. |
[AttributeKey: AttributeValue]
not [String: Any]
?
Hey thanks for the thoughtful response @ncreated! I understand that you would like to have a guarantee that you can decode the incoming data. However you have chosen to offload all this work to the end user. I would think the scenario I hit is almost certainly the most common one for developers using this library. Why not make it easier for them to work with? This feels like it was built for DD and not with the end user in mind. I'd still recommend one of the following:
Or
Remember that onboarding new users should be (imo) as easy as possible and I almost bailed on using this service because it was "too difficult" to get a simple dictionary passed into the API. I have a feeling I'm not alone on this. So instead of just passing in a simple dictionary, my workaround was to copy those two files mentioned above into my project and maintain ownership. None of which seems to be documented anywhere. Random note: The Android lib didn't seem to have this requirement and is inconsistent. Thanks again for the help. I appreciate your time. |
@crewshin Again, having
AFAIK, it's the first feedback we hear on this. We will consider it a feature request, so we can track how much it is popular - I'll tag this issue accordingly. |
[AttributeKey: AttributeValue]
not [String: Any]
?[String: Any]
attributes instead of [String: Encodable]
?
Because [String: Encodable] is not encodable conformant itself, I've had to go through many, many contortions in my codebase to be able to encode something equivalent to [String : [String: [String: Encodable]]] in my codebase. Like the output of MetricKit's dictionaryRepresentation(). jsonRepsentation() returns a Data blob, and putting it directly into datadog makes the web interface show a list of numbers vs. decoding it as json. And it's not that easy to wrap it into an |
Just a quick heads-up that we've closed the GitHub issue you reported due to inactivity. If you've updated your SDK to the latest version and the problem still persists, feel free to open a new issue and we'll be happy to help out. |
@maciejburda Was anything related to this changed in the SDK? Or just closed because old? |
@crewshin Thanks for checking! I closed this issue as a part of the clean up. GH Issues are becoming quite busy - being a mix of feature requests, bug reports, configuration issues and questions. This together with our internal channels make things difficult to track, both to us and the customers. I highly recommend sending feature request through the official form. Although, after second look I agree with @ncreated. Let's keep it open and see if we can get more feedback on this matter, so we can prioritise in the future. |
I just found this thread and would like to leave a +1. While I don't feel it's an absolute necessity (we also wrote our own abstractions to make working with attributes easier), it would definitely be appreciated if the SDK provided helpers that allow sending nested data/JSON more easily. I think I prefer a public conversion helper function over |
I have to admit the fact that this library implements AttributeKey and AttributeValue is a bit confusing. Why not just accept a [String: Any] and if the end user happens to pass in something other than a basic data type that you can understand... ignore it server side? The
any
aspect of this whole thing is blowing me up from the typealias' existential jazz.In my app, I want to pass in [String: Any]'s of data as attributes. I have a lot of data that I want to log which spreads across data types and namespaces.
Simple [String: Any] data I would like to send:
We have a simple wrapper class to organize a bit of the data we want to pass in. This looping logic is purely here to type cast and maintain the object hierarchy.
foo: family_list, etc
Which uses this type caster func just to build the expected dictionary:
And sends data to:
I can pass in any dictionary I want and cast to AttributeValue easily... as long as the data types are not
Any
. So [String: String], [String: Double], [String: Bool]... they all work great, but as soon as I want to use a [String: Any], things fail.In the above json example, "device" has mixed value types. As does "foo".
This seems to be the issue here: https://stackoverflow.com/a/76924488/2966596
I'm either A: missing something basic here that makes life easy for a developer. Or B: the developers of this library haven't used this in production or on anything other than unit tests with simple mocked data. Please tell me it's A.
I also hope the solution isn't to create an Encodable struct for everything I want to use.
The text was updated successfully, but these errors were encountered: