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

Only start a new session span if it's appropriate #986

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

bidetofevil
Copy link
Collaborator

@bidetofevil bidetofevil commented Jun 24, 2024

Goal

Pass down whether or not ending a session in the CurrentSessionSpan should start a new session, and make the check appropriately based on end type as well as whether background sessions are enabled.

Testing

Added new tests for the condition

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @bidetofevil and the rest of your teammates on Graphite Graphite

Copy link

codecov bot commented Jun 24, 2024

Codecov Report

Attention: Patch coverage is 84.44444% with 7 lines in your changes missing coverage. Please review.

Project coverage is 79.02%. Comparing base (8e95028) to head (09865d4).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #986      +/-   ##
==========================================
+ Coverage   78.97%   79.02%   +0.04%     
==========================================
  Files         416      416              
  Lines       11045    11065      +20     
  Branches     1764     1766       +2     
==========================================
+ Hits         8723     8744      +21     
  Misses       1539     1539              
+ Partials      783      782       -1     
Files Coverage Δ
.../capture/envelope/session/SessionEnvelopeSource.kt 100.00% <100.00%> (ø)
...ture/envelope/session/SessionEnvelopeSourceImpl.kt 100.00% <100.00%> (ø)
...k/capture/envelope/session/SessionPayloadSource.kt 100.00% <100.00%> (ø)
...pture/envelope/session/SessionPayloadSourceImpl.kt 100.00% <100.00%> (ø)
...id/embracesdk/internal/spans/CurrentSessionSpan.kt 100.00% <100.00%> (ø)
.../embracesdk/session/message/FinalEnvelopeParams.kt 77.77% <100.00%> (+2.77%) ⬆️
...esdk/session/message/PayloadMessageCollatorImpl.kt 100.00% <100.00%> (ø)
...acesdk/session/orchestrator/SessionSnapshotType.kt 71.42% <80.00%> (+4.76%) ⬆️
...mbracesdk/internal/spans/CurrentSessionSpanImpl.kt 90.32% <66.66%> (+6.11%) ⬆️
...d/embracesdk/session/message/PayloadFactoryImpl.kt 93.10% <82.35%> (+0.69%) ⬆️

... and 2 files with indirect coverage changes

@bidetofevil bidetofevil marked this pull request as ready for review June 24, 2024 17:14
@bidetofevil bidetofevil requested a review from a team as a code owner June 24, 2024 17:14
@@ -98,7 +98,9 @@ internal class CurrentSessionSpanImpl(
if (appTerminationCause == null) {
endingSessionSpan.stop()
spanRepository.clearCompletedSpans()
sessionSpan.set(startSessionSpan(openTelemetryClock.now().nanosToMillis()))
if (startNewSession) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This introduces undesirable behavior where calling sessionSpan.get() afterwards means folks could attempt to write to the span after the session has ended. Setting the reference to null if no new session is created should be enough to fix it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. Will fix tomorrow!

Copy link
Collaborator Author

@bidetofevil bidetofevil Jun 26, 2024

Choose a reason for hiding this comment

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

This brings up an interesting point about what happens if we do stuff when there is no session span. Looking at the code, we can't start a new span without a session span, and likely everything else that gets written to the session span will fail.

Before OTel, that data is just lost, right?

I'll put up the fix for this but lets figure this out before I merge this - we should have tests to verify this case and ensure we don't crash

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added tests to verify no-session-span state. This should be good to go.

Copy link

github-actions bot commented Jun 26, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

Copy link
Collaborator Author

Differentiated between initialization and whether a session span exists, as there doesn't necessarily have to be one now, if we are in the background and background activity isn't on.

Copy link
Contributor

@fractalwrench fractalwrench left a comment

Choose a reason for hiding this comment

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

LGTM

@bidetofevil bidetofevil merged commit 8aa7f9a into master Jun 27, 2024
5 checks passed
@bidetofevil bidetofevil deleted the hho/session-starting-sync branch June 27, 2024 15:10
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.

2 participants