-
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
RUMM-886 setUserInfo(..., extraInfo)
added
#315
Conversation
What exactly is inconsistent?
Having single
In all other places (see: |
ce3ada5
to
78cff21
Compare
78cff21
to
61246f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good 👌, but needs the fix for Tracing.
@@ -78,9 +78,15 @@ public class Datadog { | |||
public static func setUserInfo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This public API is missing the comment.
@@ -198,5 +198,8 @@ internal struct SpanEncoder { | |||
let metaKey = "meta.\($0.key)" | |||
try container.encode($0.value, forKey: DynamicCodingKey(metaKey)) | |||
} | |||
try span.userInfo.extraInfo.forEach { | |||
try container.encode(EncodableValue($1), forKey: DynamicCodingKey("meta.usr.\($0)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leads to all spans being rejected by Intake if the user extra attribute is not String
, e.g.:
Datadog.setUserInfo(
id: "abcd-1234",
name: "foo",
email: "foo@example.com",
extraInfo: [
"is-registered": true
]
)
As stated in this method comment:
// NOTE: RUMM-299 only string values are supported for `meta.*` attributes
Whatever we encode on meta.*
key must be serialised to String
representation. We should use JSONStringEncodableValue
in SpanBuilder
as it is done for span.tags
.
id: "abc-123", | ||
name: "Foo", | ||
email: "foo@bar.com", | ||
extraInfo: ["extra_key": "extra_value"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because extraInfo
encoding depends on the feature (Logging and RUM supports multiple Encodable
types, but Tracing encodes all values as String
), it seems better to mix few types in this test:
extraInfo: ["extra_string": "string_value", "extra_int": 42, "extra_bool": true]
and document the expected encoding result in test assertions.
@@ -335,8 +335,8 @@ class TracerTests: XCTestCase { | |||
Datadog.setUserInfo(id: "abc-123", name: "Foo") | |||
tracer.startSpan(operationName: "span with user `id` and `name`").finish() | |||
|
|||
Datadog.setUserInfo(id: "abc-123", name: "Foo", email: "foo@example.com") | |||
tracer.startSpan(operationName: "span with user `id`, `name` and `email`").finish() | |||
Datadog.setUserInfo(id: "abc-123", name: "Foo", email: "foo@example.com", extraInfo: ["extra_key": "extra_value"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because extraInfo
encoding depends on the feature (Logging and RUM supports multiple Encodable
types, but Tracing encodes all values as String
), it seems better to mix few types in this test:
extraInfo: ["extra_string": "string_value", "extra_int": 42, "extra_bool": true]
and document the expected encoding result in test assertions.
@@ -186,16 +186,16 @@ class LoggerTests: XCTestCase { | |||
Datadog.setUserInfo(id: "abc-123", name: "Foo") | |||
logger.debug("message with user `id` and `name`") | |||
|
|||
Datadog.setUserInfo(id: "abc-123", name: "Foo", email: "foo@example.com") | |||
logger.debug("message with user `id`, `name` and `email`") | |||
Datadog.setUserInfo(id: "abc-123", name: "Foo", email: "foo@example.com", extraInfo: ["extra_key": "extra_value"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because extraInfo
encoding depends on the feature (Logging and RUM supports multiple Encodable
types, but Tracing encodes all values as String
), it seems better to mix few types in this test:
extraInfo: ["extra_string": "string_value", "extra_int": 42, "extra_bool": true]
and document the expected encoding result in test assertions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can't pass different types in a dict to assertUserInfo
method below
i will need to use matcher.assertValue(forKey:value:)
482a35c
to
daa2209
Compare
daa2209
to
72a19f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good 🚀
What and why?
Datadog.UserInfo
has arbitrary attributes viaextraInfo
How?
UserInfoProvider
keepsextraInfo
dictionary along withuserInfo
Features (Logs, APM and RUM) encode
extraInfo
according to their own rulesLogs:
APM:
RUM:
Discussion 💭
In this PR, I put
usr.
prefix toextraInfo
withinUserInfoProvider
and pass it to features as regular attributes.But
UserInfoProvider
passesUserInfo
value without encoding and the features (LogEncoder
andSpanEncoder
) are responsible for its encoding.This is some sort of inconsistency in
UserInfoProvider
, I didn't like that ❌Can't we make
UserInfo: Encodable
to de-duplicate its encoding logic?Review checklist