-
Notifications
You must be signed in to change notification settings - Fork 142
RUM-9335 Fix missing app ID in Session Ended metric #2324
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
base: develop
Are you sure you want to change the base?
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 1354 Passed, 2606 Skipped, 2m 45.7s Total duration (2m 4.45s time saved) |
ce22ff5
to
0a7740d
Compare
RUM-9335 Fix missing Application ID in Session Ended metric
0a7740d
to
5f3606a
Compare
let sessionIDOverride: String? = attributes.removeValue(forKey: SDKMetricFields.sessionIDOverrideKey)?.dd.decode() | ||
let sessionID = sessionIDOverride ?? rum?.sessionID | ||
|
||
// Override applicationID using standard `SDKMetricFields`, otherwise use current RUM application ID: | ||
let applicationIDOverride: String? = attributes.removeValue(forKey: SDKMetricFields.applicationIDOverrideKey)?.dd.decode() | ||
let applicationID = applicationIDOverride ?? rum?.applicationID | ||
|
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.
food for thought/ While this approach works and reuses the override model originally introduced for sessionIDOverrideKey
, I believe the issue with application.id
is fundamentally different and could be addressed more cleanly - in a way that benefits the broader codebase.
The original purpose of sessionIDOverrideKey
was to reflect session.id
in "session ended" telemetry, even after a new session had started. In that case, the RUM context accessed like this (in line 255):
let rum = context.additionalContext(ofType: RUMCoreContext.self)
already reflects the new session’s ID, so we needed a mechanism to override it when reporting data for the previous session.
However, application.id
doesn’t suffer from the same timing or state issue. It is static across the lifetime of the SDK. The reason it's missing in this context (line 255) isn’t because it's unavailable - it’s because the call to RUMCoreContext.self
is returning nil
. That origins here in Monitor.swift
, where we explicitly reset the context when no session is active.
So, using applicationIDOverrideKey
masks the actual issue and applies a workaround rather than solving the root cause. A more scalable and clean solution might be to make sessionID
optional in RUMCoreContext
, allowing us to still propagate applicationID
even when no session exists. This would likely benefit other scenarios where only partial context is available.
--
I'm not sure how much effort it would take to address this in a more robust way, but it might be worth exploring. That said, if it's non-trivial or time-sensitive, the proposed patch is a reasonable workaround and does solve the immediate problem 👍.
Also cc-ing @maxep and @simaoseica-dd for their opinions.
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.
already reflects the new session’s ID, so we needed a mechanism to override it when reporting data for the previous session
Isn't it wrong to have a fallback then? ?? rum?.sessionID
My question here is, what is a TelemetryDebugEvent
without an applicationID
? It should exist at this point, and incrementing the channels (context
+ attributes
) to add that info will make it redundant without the need for it.
What and why?
This PR fixes the missing application ID in RUM Session Ended telemetry. This can happen when stopping a session manually with
RUMMonitor
.How?
For consistency, application ID follows the same override pattern as session ID, using
application_id_override
which gets transformed toapplication.id
by theTelemetryReceiver
.Review checklist
make api-surface
)