-
Notifications
You must be signed in to change notification settings - Fork 175
✨ Compute session tracking type in developer extension for SDK v7 support #4202
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import type { ReactNode } from 'react' | |
| import React, { useState } from 'react' | ||
| import { evalInWindow } from '../../evalInWindow' | ||
| import { useSdkInfos } from '../../hooks/useSdkInfos' | ||
| import { computeLogsTrackingType, computeRumTrackingType } from '../../sampler' | ||
| import { Columns } from '../columns' | ||
| import type { JsonValueDescriptor } from '../json' | ||
| import { Json } from '../json' | ||
|
|
@@ -78,6 +79,12 @@ export function InfosTab() { | |
|
|
||
| const sessionId = infos.cookie?.id | ||
|
|
||
| const logsTrackingType = | ||
| infos.cookie?.logs ?? (sessionId && infos.logs?.config && computeLogsTrackingType(sessionId, infos.logs.config)) | ||
|
|
||
| const rumTrackingType = | ||
| infos.cookie?.rum ?? (sessionId && infos.rum?.config && computeRumTrackingType(sessionId, infos.rum.config)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This recomputation relies on Useful? React with 👍 / 👎.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not an issue — |
||
|
|
||
| return ( | ||
| <TabBase> | ||
| <Columns> | ||
|
|
@@ -87,14 +94,14 @@ export function InfosTab() { | |
| <Entry name="Id" value={infos.cookie.id} /> | ||
| <Entry | ||
| name="Logs" | ||
| value={infos.cookie.logs && formatSessionType(infos.cookie.logs, 'Not tracked', 'Tracked')} | ||
| value={logsTrackingType && formatSessionType(logsTrackingType, 'Not tracked', 'Tracked')} | ||
| /> | ||
| <Entry | ||
| name="RUM" | ||
| value={ | ||
| infos.cookie.rum && | ||
| rumTrackingType && | ||
| formatSessionType( | ||
| infos.cookie.rum, | ||
| rumTrackingType, | ||
| 'Not tracked', | ||
| 'Tracked with Session Replay', | ||
| 'Tracked without Session Replay' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { isSampled } from '@datadog/browser-rum-core' | ||
|
|
||
| export function computeRumTrackingType( | ||
| sessionId: string, | ||
| config: { sessionSampleRate?: number; sessionReplaySampleRate?: number } | ||
| ): string { | ||
| const sessionSampleRate = config.sessionSampleRate ?? 100 | ||
| const sessionReplaySampleRate = config.sessionReplaySampleRate ?? 0 | ||
|
|
||
| if (!isSampled(sessionId, sessionSampleRate)) { | ||
| return '0' // NOT_TRACKED | ||
| } | ||
|
|
||
| if (isSampled(sessionId, (sessionSampleRate * sessionReplaySampleRate) / 100)) { | ||
| return '1' // TRACKED_WITH_SESSION_REPLAY | ||
| } | ||
|
|
||
| return '2' // TRACKED_WITHOUT_SESSION_REPLAY | ||
| } | ||
|
|
||
| export function computeLogsTrackingType(sessionId: string, config: { sessionSampleRate?: number }): string { | ||
| const sessionSampleRate = config.sessionSampleRate ?? 100 | ||
|
|
||
| if (!isSampled(sessionId, sessionSampleRate)) { | ||
| return '0' // NOT_TRACKED | ||
| } | ||
|
|
||
| return '1' // TRACKED | ||
| } |
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.
The new fallback only computes
logsTrackingType/rumTrackingTypewhensessionIdis present. For sampled-out sessions, the SDK does not persist a session id (the session store only assignsidfor tracked sessions), so in v7 environments where cookielogs/rumfields are removed this leaves both valuesundefinedand the Infos tab displays empty values instead ofNot tracked. This will affect any deployment usingsessionSampleRate < 100.Useful? React with 👍 / 👎.
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.
Not an issue — SDK v7 still writes the session ID to the cookie for all sessions (tracked and untracked). When a session is sampled out, the ID is present in the cookie but the
logs/rumfields are absent. In that case,sessionIdwill be defined,computeLogsTrackingType/computeRumTrackingTypewill run, and they will correctly return'0'(not tracked).