Skip to content

🐛 fix session management and event attribution issues#79

Merged
bcaudan merged 9 commits into
mainfrom
bcaudan/fixes
Apr 2, 2026
Merged

🐛 fix session management and event attribution issues#79
bcaudan merged 9 commits into
mainfrom
bcaudan/fixes

Conversation

@bcaudan

@bcaudan bcaudan commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Several bugs were identified from an internal user report. This PR addresses session management, event attribution, and user activity detection issues.

Changes

  • Remove app name/version from the user agent string
  • Fix TimeStampValueHistory.find() to require startTime <= entry.endTime, preventing stale session/view attribution for events arriving after a session ended
  • Fix session restart to close the previous session history entry before creating a new one, avoiding to leave opened session in the history
  • Fix Assembly to use event.data.date (renderer event timestamp) for hook context resolution instead of the arrival time
  • Add UserActivityTracker — registers a handler that listens for renderer RUM events and emits END_USER_ACTIVITY when a click action is detected, keeping sessions alive from real user interactions

Test instructions

On the playground:

  • User activity tracking: clicking anywhere should update the session lastActivity timestamp
  • Session expiry filtering: stop the session, then trigger an error — the error is collected with the new session started with the click (previously it was attributed to the expired session)

Checklist

  • Tested locally (playground)
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated related documentation.

bcaudan added 3 commits April 2, 2026 11:22
It caused some issues if the app name is containing some non ascii characters.
As we don't really need to capture it here, let's drop it.
- discard events generated after session expiry (gap → DISCARDED)
- document the Infinity↔null disk format contract
- add e2e scenarios for session attribution and crash recovery
@bcaudan

bcaudan commented Apr 2, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a8f1ef1140

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/session/SessionManager.ts
Comment thread src/domain/UserActivityTracker.ts
@bcaudan bcaudan marked this pull request as ready for review April 2, 2026 10:22
@bcaudan bcaudan requested a review from a team as a code owner April 2, 2026 10:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 022a43103e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/domain/UserActivityTracker.ts
export function getUserAgent(): Promise<string> {
return getOSUserAgentPart().then((osPart) =>
[
`${app.getName()}/${app.getVersion()}`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we really remove it instead of sanitizing it ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This part in the user agent is not used and only visible when looking at the useragent attribute in the event JSON.
Since app name will be injected by backend from the created rum app and version needs to be configured at sdk init to be added properly into the events, I don't think it is really useful.

Comment thread src/assembly/Assembly.ts
const hookResult = this.hooks.triggerRum({
eventType: event.data.type,
startTime: event.startTime ?? timeStampNow(),
startTime: event.data.date as TimeStamp,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice catch!

Comment on lines +41 to +44
if (startTime <= entry.endTime) {
return entry.value;
}
break;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need this, are we expecting gaps between sessions ? I expected that if some even happens in-between 2 sessions it would be added to the older session. If we're expecting that some event could occur between a timeframe where a session ended and before another one started, this means the issue is actually that we are ending sessions incorrectly no ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

are we expecting gaps between sessions ?

yes, we could have a session expiring due to end user inactivity during 15 min and a new one starting only when the end user come back and interact again with the application.

I expected that if some even happens in-between 2 sessions it would be added to the older session.

We shouldn't collect the events happening outside of an active session.

For example, we could have events generated regularly, like requests from a regular poll to the backend.
The session should still expire if there is no end user activity and the requests happening when no session is active should not be collected.

this means the issue is actually that we are ending sessions incorrectly no ?

Let's chat to see if there are some missing case

@bcaudan bcaudan merged commit 8ea12bc into main Apr 2, 2026
14 checks passed
@bcaudan bcaudan deleted the bcaudan/fixes branch April 2, 2026 12:49
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