-
Notifications
You must be signed in to change notification settings - Fork 40
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
Refactor session handling #564
Merged
breedx-splk
merged 20 commits into
open-telemetry:main
from
breedx-splk:session_refactor
Aug 30, 2024
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f098fe2
first pass at new session api
breedx-splk 56f0b19
session work in progress
breedx-splk 81d2f42
Rename .java to .kt
breedx-splk a428718
fix up some tests
breedx-splk ef9c20e
make sampler use interface
breedx-splk 8d13d28
move SessionIdTest.java to SessionManagerTest.kt and fix up
breedx-splk 2d9f56c
remove unused SessionId.java
breedx-splk 276b155
remove unused SessionChangeObserver
breedx-splk b20a910
spotless
breedx-splk 30c5a50
make constants
breedx-splk 7234663
don't send events for the NONE session
breedx-splk 869840b
default to NONE session and cause session start after adding observer
breedx-splk fe4d8e6
Rename .java to .kt
breedx-splk 8436771
migrate observer to kotlin
breedx-splk 7aa16ba
spotless
breedx-splk fe5d9e4
pass config session timeout and don't force SessionManager to be a bu…
breedx-splk ae68dd1
fix typo
breedx-splk 8d54ec7
fix test
breedx-splk 9ef46b0
fix tests
breedx-splk 17b0792
remove SessionIdEventSender (to make the PR more purely refactoring)
breedx-splk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 0 additions & 92 deletions
92
core/src/main/java/io/opentelemetry/android/SessionId.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
core/src/main/java/io/opentelemetry/android/SessionIdChangeListener.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
core/src/main/java/io/opentelemetry/android/SessionIdChangeTracer.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
core/src/main/java/io/opentelemetry/android/SessionIdEventSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android | ||
|
||
import io.opentelemetry.android.common.RumConstants.Events.EVENT_SESSION_END | ||
import io.opentelemetry.android.common.RumConstants.Events.EVENT_SESSION_START | ||
import io.opentelemetry.android.session.Session | ||
import io.opentelemetry.android.session.SessionObserver | ||
import io.opentelemetry.api.incubator.events.EventLogger | ||
import io.opentelemetry.semconv.incubating.SessionIncubatingAttributes.SESSION_ID | ||
import io.opentelemetry.semconv.incubating.SessionIncubatingAttributes.SESSION_PREVIOUS_ID | ||
|
||
internal class SessionIdEventSender(private val eventLogger: EventLogger) : SessionObserver { | ||
override fun onSessionStarted( | ||
newSession: Session, | ||
previousSession: Session, | ||
) { | ||
val eventBuilder = | ||
eventLogger | ||
.builder(EVENT_SESSION_START) | ||
.put(SESSION_ID, newSession.getId()) | ||
val previousSessionId = previousSession.getId() | ||
if (previousSessionId.isNotEmpty()) { | ||
eventBuilder.put(SESSION_PREVIOUS_ID, previousSessionId) | ||
} | ||
eventBuilder.emit() | ||
breedx-splk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
override fun onSessionEnded(session: Session) { | ||
if (session.getId().isEmpty()) { | ||
return | ||
} | ||
eventLogger.builder(EVENT_SESSION_END) | ||
.put(SESSION_ID, session.getId()) | ||
.emit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this is fine for the purpose of replacing the existing behavior's implementation with the new API. However, since this is the
core
part of the lib, I think it should receive the lowest level part of the API, which isSessionProvider
. Passing aSessionIdTimeoutHandler
incore
implies that the only way all apps can get their session handled is by time, even if that doesn't match their specific requirements. Probably a good place to passSessionIdTimeoutHandler
would be in the higher-level typeAndroidAgentBuilder
that it's proposed here. That way the "time-based" approach that we recommend would be the easiest to set up via the agent, though it would still be possible to override it when needed.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.
In fact, probably only
SessionProvider
should live incore
and we should move all of its subtypes/helpers over toandroid-agent
.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.
We can talk more about this, because I think that we should be opinionated about sessions having a default max time to live...but the user should ultimately be able to configure and/or override this. As you pointed out, it's also consistent with the existing/current behavior.
Can we work on this aspect in a follow-up PR effort?
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.
Sounds good. We can follow up on it later 👍