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

RUMM-1583 Fix attributes reading in Objective-C #654

Merged

Conversation

ncreated
Copy link
Member

@ncreated ncreated commented Nov 4, 2021

What and why?

📦 This PR fixes DatadogObjc issue with retrieving back attribute values in public APIs.

It was not possible to obtain the value of Any attribute, i.e. this would fail:

let view = DDRUMView(name: "name", attributes: ["foo": "bar"])
XCTAssertEqual(view.attributes["foo"] as? String, "bar") // 🐞 fail

It would fail because "bar" is wrapped into AnyEncodable(value: "bar") type erasure as part of our Objective-C <> Swift interoperability (Swift SDK represents attributes as Encodable). AnyEncodable is internal type to DatadogObjc so it was not even possible to read the attribute value back in any other way.

How?

I introduced func castAttributesToObjectiveC(_ attributes: [String: Encodable]) -> [String: Any] function to unpack AnyEncodable values before they are passed to the user.

This had to be used in DDRUMView, DDRUMAction and all generated RUMDataModels for Objective-C.

Now, users will get exactly what they set through our Objective-C API.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • Make sure each commit and the PR mention the Issue number or JIRA reference

…jective-C

This requires calling `.castToObjectiveC()` in generated Objc interop code for RUM data models.
@ncreated ncreated requested a review from a team as a code owner November 4, 2021 15:33
@ncreated ncreated self-assigned this Nov 4, 2021
Copy link
Member

@maxep maxep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ncreated ncreated merged commit 7019861 into master Nov 8, 2021
@ncreated ncreated deleted the ncreated/RUMM-1583-fix-reading-attributes-in-ObjectiveC branch November 8, 2021 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants