Skip to content

feat: Add accessor for current session id#1810

Merged
fuzzybinary merged 2 commits into
developfrom
jward/RUM-1962-session-id-acessor
Jan 9, 2024
Merged

feat: Add accessor for current session id#1810
fuzzybinary merged 2 commits into
developfrom
jward/RUM-1962-session-id-acessor

Conversation

@fuzzybinary

Copy link
Copy Markdown
Member

What does this PR do?

There are use cases (usually support use cases) where clients what to know the current session id without depending on the sessionStarted event. This provides that accessor.

refs: RUM-1962

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@fuzzybinary
fuzzybinary requested review from a team as code owners January 5, 2024 22:04
@codecov-commenter

codecov-commenter commented Jan 5, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.47%. Comparing base (a21c278) to head (6eeebd2).
Report is 1732 commits behind head on develop.

Files with missing lines Patch % Lines
.../android/rum/internal/monitor/DatadogRumMonitor.kt 77.78% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1810      +/-   ##
===========================================
+ Coverage    83.44%   83.47%   +0.04%     
===========================================
  Files          466      466              
  Lines        16375    16381       +6     
  Branches      2455     2456       +1     
===========================================
+ Hits         13663    13674      +11     
+ Misses        2047     2030      -17     
- Partials       665      677      +12     
Files with missing lines Coverage Δ
.../main/kotlin/com/datadog/android/rum/RumMonitor.kt 28.57% <ø> (ø)
.../android/rum/internal/monitor/DatadogRumMonitor.kt 85.66% <77.78%> (-0.26%) ⬇️

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +24 to +25
* The current active session id. May return null if a session has not been started yet.
* Will return a "null session id" (all zeros) if the current session is not tracked.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* The current active session id. May return null if a session has not been started yet.
* Will return a "null session id" (all zeros) if the current session is not tracked.
* The current active session ID. May return null if a session has not been started yet.
* Will return a "null session ID" (all zeros) if the current session is not tracked.

Comment on lines +24 to +25
* The current active session id. May return null if a session has not been started yet.
* Will return a "null session id" (all zeros) if the current session is not tracked.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To be precise, it won't be all zeros, but 00000000-0000-0000-0000-000000000000, so user cannot write something like if (currentSessionId.all {it == '0'}), so maybe for the sake of comparison with null session mentioned in the documentation, we need to expose such value?


// region RumMonitor

override val currentSessionId: String?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method is not thread-safe, because all the values inside RUM scopes hierarchy are set from the dedicated RUM thread, but currentSessionId can be called from any user thread. IMO it is not a big deal here, but if use-case from the user side requires consistency and precision, we may need to make this one thread-safe to avoid concurrency issues.

}

@Test
fun `M returns null id for current session W no session started`() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
fun `M returns null id for current session W no session started`() {
fun `M return null ID for current session W currentSessionId { no session started }`() {

}

@Test
fun `M currentSessionId returns correct sessionId W session started { sampled in }`(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
fun `M currentSessionId returns correct sessionId W session started { sampled in }`(
fun `M return correct sessionId W currentSessionId { session started, sampled in }`(

mockSessionListener
)

assertThat(testedMonitor.currentSessionId).isEqualTo(RumContext.NULL_UUID)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not aligned to what documentation of currentSessionId is saying:

May return null if a session has not been started yet.

}

@Test
fun `M currentSessionId returns null session W session started { sampled out }`(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
fun `M currentSessionId returns null session W session started { sampled out }`(
fun `M return null session W currentSessionId { session started, sampled out }`(

val sessionScope = applicationScope?.activeSession as? RumSessionScope
if (sessionScope != null && sessionScope.sessionState == RumSessionScope.State.NOT_TRACKED) {
// Aligns with iOS which assigns a NULL session id when the session is not tracked
return RumContext.NULL_UUID

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For "readability" purposes, in link with Nikita's comment above, maybe we should return null instead here. This would make it easier for customers to not use a "000…" value which doesn't make sense?

@fuzzybinary

Copy link
Copy Markdown
Member Author

@xgouchet / @0xnm Replaced the accessor with an async callback. Let me know what you think

@0xnm 0xnm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm! I've added a minor suggestion

// Then
completableFuture.thenAccept {
assertThat(it).isEqualTo(null)
}.orTimeout(100, TimeUnit.MILLISECONDS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
}.orTimeout(100, TimeUnit.MILLISECONDS)
}.orTimeout(PROCESSING_DELAY, TimeUnit.MILLISECONDS)

same to change for similar lines below

@fuzzybinary
fuzzybinary force-pushed the jward/RUM-1962-session-id-acessor branch from 28d15ef to 6eeebd2 Compare January 8, 2024 22:06
@fuzzybinary
fuzzybinary merged commit 5264083 into develop Jan 9, 2024
@fuzzybinary
fuzzybinary deleted the jward/RUM-1962-session-id-acessor branch January 9, 2024 15:44
@xgouchet xgouchet added this to the 2.5.0 milestone Feb 19, 2024
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.

5 participants