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-1455 Add Session Start Callback #590

Merged
merged 6 commits into from Sep 7, 2021

Conversation

maxep
Copy link
Member

@maxep maxep commented Sep 6, 2021

What and why?

Adds an optional onSessionStart callback to RUMApplicationScope to be called when a new session starts. The callback takes 2 arguments: the newly started Session ID and a boolean indicating whether or not the session is discarded by the sampling rate (when true it means no event in this session will be kept).

Fix #526

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

@maxep maxep requested a review from a team as a code owner September 6, 2021 18:08
@maxep
Copy link
Member Author

maxep commented Sep 6, 2021

This PR also surface API from recent PRs. Let me know if I should revert that!

@maxep maxep self-assigned this Sep 6, 2021
@maxep maxep added the needs-docs To mark PRs which need documentation update label Sep 6, 2021
@maxep maxep force-pushed the maxep/RUMM-1455/publish-session-id branch from c19a626 to 840ba8d Compare September 7, 2021 06:21
Tests/DatadogTests/Datadog/RUMMonitorTests.swift Outdated Show resolved Hide resolved
@@ -254,6 +254,11 @@ public class DDConfigurationBuilder: NSObject {
_ = sdkBuilder.set(rumSessionsSamplingRate: rumSessionsSamplingRate)
}

@objc
public func set(onSessionStart handler: @escaping (String, Bool) -> Void) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 👌, let's also add smoke test for this new API here.

@@ -87,6 +92,7 @@ internal class RUMApplicationScope: RUMScope, RUMContextProvider {
private func refresh(expiredSession: RUMSessionScope, on command: RUMCommand) {
let refreshedSession = RUMSessionScope(from: expiredSession, startTime: command.time)
sessionScope = refreshedSession
sessionScopeDidUpdate(refreshedSession)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have no test coverage for this case - test added in RUMMonitorTests only checks the callback for initial session. Both "initial" and "refreshed" sessions are already tested in RUMApplicationScopeTests and I think we could add tests for both callback situations there as well, WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree 👍

/// (when `true` it means no event in this session will be kept).
///
/// - Parameter handler: the callback handler to notify whenever a new Session starts.
public func onSessionStart(_ handler: @escaping (String, Bool) -> Void) -> Builder {
Copy link
Collaborator

@ncreated ncreated Sep 7, 2021

Choose a reason for hiding this comment

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

  • About the naming - as this is a RUM feature, I think it's worth expressing it from the name as we do for other RUM options. How about onRUMSessionStart?
  • About testing - it also requires updating tests in DatadogConfigurationBuilderTests (we cover all public options in there)

@maxep maxep requested a review from ncreated September 7, 2021 10:18
Copy link
Collaborator

@ncreated ncreated left a comment

Choose a reason for hiding this comment

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

🏅

@maxep maxep merged commit 88b9e66 into master Sep 7, 2021
@maxep maxep deleted the maxep/RUMM-1455/publish-session-id branch September 7, 2021 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-docs To mark PRs which need documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Get session ID
2 participants