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

Use of SessionIdTimeoutHandler class #860

Open
ddas09 opened this issue Feb 28, 2025 · 10 comments
Open

Use of SessionIdTimeoutHandler class #860

ddas09 opened this issue Feb 28, 2025 · 10 comments

Comments

@ddas09
Copy link

ddas09 commented Feb 28, 2025

Hi Team, I am trying to understand the use of the SessionIdTimeoutHandler class. As per my understanding there are two classes -

  • SessionManagerImpl - this allows a session to be active for a maximum of 4 hours (if not overridden using the OtelRumConfig here
  • SessionIdTimeoutHandler - this class handles expiring session if the app remains if background for more than 15 minutes (if not overridden using the OtelRumConfig here without any activity (span, logs).

The only scenario when I think the SessionIdTimeoutHandler class hasTimedOut check to be useful is if the timeout is not overridden from the OtelRumConfig API. In this case the handler class would timeout the session If the app is in the background and no activity (spans) happens for >15 minutes

But if the timeout is set in the config API it would override the value in both the SessionIdTimeoutHandler and SessionManagerImpl class. In this case If the app is in the background and no activity (spans) happens for >15 minutes, the next time the app comes foreground and any span is created, the check in the SessionManagerImpl class only would fail. Since the sessionLifetimeNanos is 15 minutes now.

Please help me to understand if I am missing something!

@breedx-splk
Copy link
Contributor

I think you got it.

Sessions are intended to timeout after some period of inactivity, default is 15 minutes as you noted. Inactivity is defined as no user behavior, which means no telemetry being created. A foregrounded app is not considered inactive.

Hopefully that helps.

@breedx-splk breedx-splk added the needs author feedback Waiting for additional feedback from the author label Mar 6, 2025
@breedx-splk
Copy link
Contributor

Also keep in mind that the SessionIdTimeoutHandler class is in the internal package and is not intended for direct use by users.

@ddas09
Copy link
Author

ddas09 commented Mar 7, 2025

But if the timeout is set in the config API it would override the value in both the SessionIdTimeoutHandler and SessionManagerImpl class. In this case If the app is in the background and no activity (spans) happens for >15 minutes, the next time the app comes foreground and any span is created, the check in the SessionManagerImpl class only would fail. Since the sessionLifetimeNanos is 15 minutes now.

Thank you @breedx-splk for the explanation. Can you also confirm this?

@github-actions github-actions bot removed the needs author feedback Waiting for additional feedback from the author label Mar 7, 2025
@breedx-splk
Copy link
Contributor

I think that's right. Even if the app is backgrounded, if the max time for a session to live expires, a new session should id should be created. Is this a problem or not matching your expectations?

Can you try it? I added

config.sessionTimeout = Duration.ofSeconds(10)
into the startup of the demo app, you I could watch the session id change every 10 seconds or so (you have to click the icon or generate some telemetry, and the way to observe that is thru the docker logs of the collector).

I backgrounded the app and saw no changes while backgrounded, but certainly once foregrounded again the session changed soon after.

@ddas09
Copy link
Author

ddas09 commented Mar 13, 2025

@breedx-splk, I was just wondering why we have these two classes, when the check inside the session manager class itself is enough to expire a session and create a new session.

@breedx-splk
Copy link
Contributor

@breedx-splk, I was just wondering why we have these two classes, when the check inside the session manager class itself is enough to expire a session and create a new session.

Ok, I think I understand what you're asking now. Maybe I can clarify:

  • The SessionManagerImpl is the implementation of the SessionManager interface, which combiners SessionProvider and SessionPublisher interfaces, so you get two external methods -- getSessionId() and addObserver(). Through the interface, this implementation is how users can get the session id and subscribe observers for changes.
  • The SessionTimeoutHandler is itself an ApplicationStateListener that watches for application foreground/background state changes in order to determine (though encapsulation) if the timeout should be considered expired.

These two classes are collaborators -- the SessionManagerImpl leverages the SessionIdTimeoutHandler.

I think what you were trying to suggest is that one of the timeout checks might be redundant because they are ORed together. I think what you might be overlooking (or that the code doesn't yet make clear enough) is that there are intended to be two separate timeouts --

  1. The overall maximum lifetime that a session can exist. Regardless of app state, a new session is supposed to be generated after this time passes. Original default is intended to be 4 hours.
  2. The session idle timeout -- time after which an inactive app should create a new session. Original default is intended to be 15 minutes.

I think we've broken something about this along the way through refactoring, though.

@ddas09
Copy link
Author

ddas09 commented Mar 14, 2025

I think what you might be overlooking (or that the code doesn't yet make clear enough) is that there are intended to be two separate timeouts

@breedx-splk, Thanks for the detailed explanation! I got it that both the classes are used for different timeouts. But when the user overrides the default timeouts the checks become redundant as you shared. Maybe this is how it’s supposed to work?

@breedx-splk
Copy link
Contributor

I think that's not how it's supposed to work, so I submitted #887 to address this. Thanks for talking this out.

@ddas09
Copy link
Author

ddas09 commented Mar 14, 2025

Thanks @breedx-splk! I saw the changes. The new config makes the timeout usages very clear.

@breedx-splk
Copy link
Contributor

Thanks @ddas09. Please feel welcome to submit a PR review. This kind of feedback is very helpful, and a gray checkmark of approval with/without comments is still very much needed in the otel community. 🙏🏻

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

No branches or pull requests

2 participants