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

🐛 [RUM-2720] Send logs without session id when session inactive #2578

Merged

Conversation

amortemousque
Copy link
Contributor

@amortemousque amortemousque commented Jan 25, 2024

Motivation

Do not drop logs when session inactive

it's worth reviewing commit by commit

Changes

  • Keep untracked session in sessionContextHistory
  • Allow to find expired session
  • Send logs when a session is expired
  • Only set the session id if the session is active

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.32%. Comparing base (5825bd2) to head (ff8b196).
Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2578   +/-   ##
=======================================
  Coverage   93.31%   93.32%           
=======================================
  Files         241      242    +1     
  Lines        7062     7069    +7     
  Branches     1561     1567    +6     
=======================================
+ Hits         6590     6597    +7     
  Misses        472      472           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

packages/core/src/domain/session/sessionManager.ts Outdated Show resolved Hide resolved
packages/core/src/tools/valueHistory.ts Outdated Show resolved Hide resolved
packages/logs/src/domain/logsSessionManager.ts Outdated Show resolved Hide resolved
packages/core/src/transport/flushController.spec.ts Outdated Show resolved Hide resolved
packages/core/src/domain/session/sessionManager.ts Outdated Show resolved Hide resolved
packages/rum-core/src/domain/rumSessionManager.ts Outdated Show resolved Hide resolved
packages/core/src/domain/session/sessionStore.ts Outdated Show resolved Hide resolved
@amortemousque amortemousque force-pushed the aymeric/send-logs-without-session-id-when-session-inactive branch from 8c549b5 to 4a5df21 Compare January 26, 2024 20:36
@amortemousque
Copy link
Contributor Author

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented Jan 30, 2024

🚂 Branch Integration: starting soon, merge in < 8m

Commit 4a5df21851 will soon be integrated into staging-05.

This build is going to start soon! (estimated merge in less than 8m)

Use /to-staging -c to cancel this operation!

@dd-devflow
Copy link

dd-devflow bot commented Jan 30, 2024

🚨 Branch Integration: The build pipeline was cancelled for this merge request

Build pipeline was cancelled for cb25103

If you think this is a mistake, you can re-add your pull request to the queue!

Details

gitlab pipeline was cancelled link

If you need support, contact us on Slack #ci-interfaces with those details!

@amortemousque amortemousque force-pushed the aymeric/send-logs-without-session-id-when-session-inactive branch 2 times, most recently from 5ca67b4 to 6e13af9 Compare February 1, 2024 11:11
- Send logs when a session is expired
- Only set session id when the session is active
@amortemousque amortemousque force-pushed the aymeric/send-logs-without-session-id-when-session-inactive branch from 6e13af9 to 2e162b5 Compare February 1, 2024 11:16
@amortemousque amortemousque marked this pull request as ready for review February 1, 2024 11:20
@amortemousque amortemousque requested a review from a team as a code owner February 1, 2024 11:20
Copy link

cit-pr-commenter bot commented May 13, 2024

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 157.94 KiB 157.97 KiB 35 B +0.02%
Logs 56.42 KiB 56.72 KiB 303 B +0.52%
Rum Slim 104.43 KiB 104.46 KiB 35 B +0.03%
Worker 25.21 KiB 25.21 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base Average Cpu Time (ms) Local Average Cpu Time (ms) 𝚫
adderror 0.049 0.032 -0.017
addaction 0.021 0.015 -0.006
logmessage 0.006 0.005 -0.002
startview 1.565 0.806 -0.759
startstopsessionreplayrecording 1.020 0.705 -0.316
addtiming 0.001 0.001 -0.000
addglobalcontext 0.002 0.001 -0.001

@nulrich
Copy link
Contributor

nulrich commented May 16, 2024

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented May 16, 2024

🚂 Branch Integration: starting soon, merge in < 9m

Commit f1c07e04b4 will soon be integrated into staging-20.

This build is going to start soon! (estimated merge in less than 9m)

Use /to-staging -c to cancel this operation!

dd-mergequeue bot added a commit that referenced this pull request May 16, 2024
…hen-session-inactive into staging-20

Co-authored-by: Nicolas Ulrich <nicolas.ulrich@datadoghq.com>
@dd-devflow
Copy link

dd-devflow bot commented May 16, 2024

🚂 Branch Integration: This commit was successfully integrated

Commit f1c07e04b4 has been merged into staging-20 in merge commit 4e866dcbea.

Check out the triggered pipeline on Gitlab 🦊

@@ -19,6 +19,7 @@ export interface LogsInitConfiguration extends InitConfiguration {
forwardErrorsToLogs?: boolean | undefined
forwardConsoleLogs?: ConsoleApiName[] | 'all' | undefined
forwardReports?: RawReportType[] | 'all' | undefined
sendLogsAfterSessionExpiration?: boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

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

💬 suggestion: ‏Could be nice to add a comment: // TODO next major: remove this option and make it the default behaviour

@nulrich
Copy link
Contributor

nulrich commented May 16, 2024

/to-staging

@dd-devflow
Copy link

dd-devflow bot commented May 16, 2024

🚂 Branch Integration: starting soon, merge in < 9m

Commit 3782d12e3c will soon be integrated into staging-20.

This build is going to start soon! (estimated merge in less than 9m)

Use /to-staging -c to cancel this operation!

dd-mergequeue bot added a commit that referenced this pull request May 16, 2024
…hen-session-inactive into staging-20

Co-authored-by: Nicolas Ulrich <nicolas.ulrich@datadoghq.com>
@dd-devflow
Copy link

dd-devflow bot commented May 16, 2024

🚂 Branch Integration: This commit was successfully integrated

Commit 3782d12e3c has been merged into staging-20 in merge commit fda0dd1e82.

Check out the triggered pipeline on Gitlab 🦊

Copy link
Member

@BenoitZugmeyer BenoitZugmeyer left a comment

Choose a reason for hiding this comment

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

I can see there is three ways of getting inactive sessions:

  • in valueHistory, there is the AFTER_ENTRY_START predicate
  • in sessionManager, there is a different method findInactiveOrExpiredSession
  • in logsSessionManager, there is a { returnExpired } option argument.

I would expect to use the same for all three. I like the option object, but not so much the "expired" name, as we already use "active", I think we should use "inactive".

So my suggestion:

  • in valueHistory, have find(startTime, { returnInactive })
  • in sessionManager, introduce a findSession(startTime, { returnInactive }), that handles both cases (remove other find*Session methods)
  • in logsSessionManager, have findTrackedSession(startTime, { returnInactive })

(returnInactive should default to false in valueHistory, and you can just pass the options down without worrying about the default in other places)

handleLog({ status: StatusType.info, message: 'message 1' }, logger)

// expire session
setCookie(SESSION_STORE_KEY, 'isExpired=1', ONE_MINUTE)
Copy link
Member

Choose a reason for hiding this comment

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

🥜 nitpick: ‏this should be in a test helper, as we're doing it in many places

@@ -35,7 +37,7 @@ export function startLogsAssembly(
const log = combine(
{
service: configuration.service,
session_id: session.id,
session_id: session.isActiveAt(startTime) ? session.id : undefined,
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏I think isActiveAt complicates things quite a bit. It might be simpler to just call findTrackedSession multiple times:

const session = sessionManager.findTrackedSession(startTime)

if (
  !session &&
  (!configuration.sendLogsAfterSessionExpiration || !sessionManager.findTrackedSession(startTime, { returnInactive: true }))
) {
  return
}

// and then

session_id: session?.id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting! It removes the needs to add endTime to SessionContext. I like it 👍

@nulrich nulrich merged commit df31fae into main May 24, 2024
20 checks passed
@nulrich nulrich deleted the aymeric/send-logs-without-session-id-when-session-inactive branch May 24, 2024 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants