-
Notifications
You must be signed in to change notification settings - Fork 121
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 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.
![image](https://private-user-images.githubusercontent.com/273809/261420929-b43942f8-bff3-4591-8f12-54d888534b55.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMTA0NTksIm5iZiI6MTcyNDAxMDE1OSwicGF0aCI6Ii8yNzM4MDkvMjYxNDIwOTI5LWI0Mzk0MmY4LWJmZjMtNDU5MS04ZjEyLTU0ZDg4ODUzNGI1NS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxOFQxOTQyMzlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT01OTE0N2VmMGFlNmMxMTM3NTE2ZDMyMTA5OGI5NTVmZWRlMTE0Y2NlMzQyMTEwYzAyYjBjMDFmMzJhMWU1NmVkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.M8ni3rFu8wxk6bTXXCAEQHKu4J7YG923glxD0LTvBTo)
foo: family_list, etc
Which uses this type caster func just to build the expected dictionary:
![image](https://private-user-images.githubusercontent.com/273809/261421204-f9b6b142-d2ad-43cd-a39a-02df811c45ba.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMTA0NTksIm5iZiI6MTcyNDAxMDE1OSwicGF0aCI6Ii8yNzM4MDkvMjYxNDIxMjA0LWY5YjZiMTQyLWQyYWQtNDNjZC1hMzlhLTAyZGY4MTFjNDViYS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxOFQxOTQyMzlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mM2M4MGEyMzVkNThmNjk2YzY3MGIyODg0YjM5MzBjMGQ5MDJmZWNiYmQxZTQ1NjcwNThkOTkxNzgxNmEwZDJjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.bLNWZcnMP8229NrrYJuM6fibULNX6nT_8oKVdZGxE8M)
And sends data to:
![image](https://private-user-images.githubusercontent.com/273809/261421028-f40348a5-4aa1-4e76-8961-f6543cb1b4e8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwMTA0NTksIm5iZiI6MTcyNDAxMDE1OSwicGF0aCI6Ii8yNzM4MDkvMjYxNDIxMDI4LWY0MDM0OGE1LTRhYTEtNGU3Ni04OTYxLWY2NTQzY2IxYjRlOC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODE4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxOFQxOTQyMzlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02ZGVmZGY2NTUwMmIxMmE1NTFmZTU3ZWYzYTNmZjdmODQ4ZTFhZmYyM2U5YmE3NjQ4MWVhNTc2N2QzYzk1ZjkyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.lOzgosNY3K-tVCmJParmbnJ1cWmSuurZBSQKen633Hw)
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: