-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(replay): Add traces_by_timestamp to replay event
#18048
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
base: develop
Are you sure you want to change the base?
Changes from all commits
c72a99c
ffc6cd9
1c9f09f
424964d
56599e5
ee2cba9
1985467
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 |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| /* eslint-disable max-lines */ // TODO: We might want to split this file up | ||
| import type { ReplayRecordingMode, Span } from '@sentry/core'; | ||
| import { getActiveSpan, getClient, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, spanToJSON } from '@sentry/core'; | ||
| import { | ||
| getActiveSpan, | ||
| getClient, | ||
| getCurrentScope, | ||
| getRootSpan, | ||
| SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, | ||
| spanToJSON, | ||
| } from '@sentry/core'; | ||
| import { EventType, record } from '@sentry-internal/rrweb'; | ||
| import { | ||
| BUFFER_CHECKOUT_TIME, | ||
|
|
@@ -192,7 +199,7 @@ export class ReplayContainer implements ReplayContainerInterface { | |
| this._hasInitializedCoreListeners = false; | ||
| this._context = { | ||
| errorIds: new Set(), | ||
| traceIds: new Set(), | ||
| traceIds: [], | ||
| urls: [], | ||
| initialTimestamp: Date.now(), | ||
| initialUrl: '', | ||
|
|
@@ -1098,7 +1105,11 @@ export class ReplayContainer implements ReplayContainerInterface { | |
| private _clearContext(): void { | ||
| // XXX: `initialTimestamp` and `initialUrl` do not get cleared | ||
| this._context.errorIds.clear(); | ||
| this._context.traceIds.clear(); | ||
| // We want to preserve the most recent trace id for the next replay segment. | ||
| // This is so that we can associate replay events w/ the trace. | ||
| if (this._context.traceIds.length > 1) { | ||
| this._context.traceIds = this._context.traceIds.slice(-1); | ||
| } | ||
| this._context.urls = []; | ||
| } | ||
|
|
||
|
|
@@ -1126,11 +1137,17 @@ export class ReplayContainer implements ReplayContainerInterface { | |
| * Return and clear _context | ||
| */ | ||
| private _popEventContext(): PopEventContext { | ||
| if (this._context.traceIds.length === 0) { | ||
| const currentTraceId = getCurrentScope().getPropagationContext().traceId; | ||
| if (currentTraceId) { | ||
| this._context.traceIds.push([-1, currentTraceId]); | ||
| } | ||
| } | ||
| const _context = { | ||
| initialTimestamp: this._context.initialTimestamp, | ||
| initialUrl: this._context.initialUrl, | ||
| errorIds: Array.from(this._context.errorIds), | ||
| traceIds: Array.from(this._context.traceIds), | ||
| traceIds: this._context.traceIds, | ||
|
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. Bug: Shared array reference corrupts replay contextIn |
||
| urls: this._context.urls, | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,12 +37,16 @@ export async function sendReplayRequest({ | |
| return Promise.resolve({}); | ||
| } | ||
|
|
||
| const uniqueTraceIds = Array.from(new Set(traceIds.map(([_ts, traceId]) => traceId))); | ||
| const baseEvent: ReplayEvent = { | ||
| type: REPLAY_EVENT_NAME, | ||
| replay_start_timestamp: initialTimestamp / 1000, | ||
| timestamp: timestamp / 1000, | ||
| error_ids: errorIds, | ||
| trace_ids: traceIds, | ||
| trace_ids: uniqueTraceIds, | ||
| traces_by_timestamp: traceIds | ||
| .filter(([_ts, traceId]) => uniqueTraceIds.includes(traceId)) | ||
| .map(([ts, traceId]) => [ts, traceId]), | ||
|
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. Bug: Redundant Filter Causes Unnecessary Performance OverheadThe filter for |
||
| urls, | ||
| replay_id: replayId, | ||
| segment_id, | ||
|
|
||
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.
Bug: Timestamp Handling Ignores Valid Zero Value
The
event.start_timestampcheck inhandleTransactionEventuses a truthy evaluation, which causes trace IDs to not be recorded for transactions with astart_timestampof 0. Although rare, 0 is a valid Unix epoch timestamp.