Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3b7c09b
feat(trace): Correct clock drift between client and server spans
Lms24 Nov 20, 2026
c1d4fbe
feat(trace): Gate clock drift correction behind a feature flag
Lms24 Nov 20, 2026
0f96221
fix(trace): Shift issues on autogroups in clock drift corrected subtrees
Lms24 Nov 20, 2026
f7d0cee
ref(trace): Flag clock drift correction roots with a boolean
Lms24 Nov 23, 2026
0c606a9
fix(trace): Swap server rendered pageloads before correcting clock drift
Lms24 Nov 24, 2026
81991c0
fix(trace): Shift occurrence patterns with clock drift corrected spans
Lms24 Nov 24, 2026
9ec6c3f
fix(trace): Keep the clock drift preference for organizations without it
Lms24 Nov 24, 2026
6c684a9
ref(trace): Remove clock drift comment from missing instrumentation
Lms24 Nov 24, 2026
f64ecfc
test(trace): Cover clock drift correction of nested client spans
Lms24 Nov 24, 2026
26aac35
ref(trace): Let the trace tree toggle clock drift correction
Lms24 Nov 27, 2026
0123a07
ref(trace): Keep the clock drift icon sizes next to the model
Lms24 Nov 27, 2026
5fdbadc
ref(trace): Use Text and plain translations for clock drift copy
Lms24 Nov 27, 2026
16937e2
ref(trace): Remove the unused clock drift correction collector
Lms24 Nov 27, 2026
0c62f8c
fix(trace): Query profiles and issues at the recorded time of moved s…
Lms24 Nov 27, 2026
498a9c0
ref(trace): Clarify why clock drift requests are grouped by segment
Lms24 Nov 27, 2026
4fec74c
fix(trace): Explain the clock drift shift on autogroup labels
Lms24 Nov 27, 2026
dae9221
ref(trace): Trim clock drift comments
Lms24 Nov 27, 2026
ed54c80
fix(trace): Redraw span issue icons with the view
sentry-junior[bot] Nov 27, 2026
ccad5b9
fix(trace): Include drifted spans in the trace issues link range
sentry-junior[bot] Nov 27, 2026
b58109d
fix(trace): Keep the clock drift tooltip on one line
sentry-junior[bot] Nov 27, 2026
fd8b435
fix(trace): Query pinned attributes at the recorded time of moved spans
sentry-junior[bot] Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const DEFAULT_ISSUE_DETAILS_TRACE_VIEW_PREFERENCES: TracePreferencesState = {
missing_instrumentation: true,
autogroup: {parent: true, sibling: true},
compressed_timeline: false,
clock_drift_correction: false,
layout: 'drawer bottom',
list: {width: 0.5},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const DEFAULT_ISSUE_DETAILS_TRACE_VIEW_PREFERENCES: TracePreferencesState = {
missing_instrumentation: true,
autogroup: {parent: true, sibling: true},
compressed_timeline: false,
clock_drift_correction: false,
layout: 'drawer bottom',
list: {width: 0.5},
};
Expand Down
3 changes: 3 additions & 0 deletions static/app/utils/analytics/tracingEventMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type TracingEventParameters = {
trace_duration_seconds: number;
};
'trace.preferences.autogrouping_change': {enabled: boolean};
'trace.preferences.clock_drift_correction_change': {enabled: boolean};
'trace.preferences.compressed_timeline_change': {enabled: boolean};
'trace.preferences.missing_instrumentation_change': {enabled: boolean};
'trace.quality.missing_spans.doc_link_clicked': Record<string, unknown>;
Expand Down Expand Up @@ -210,6 +211,8 @@ export const tracingEventMap: Record<TracingEventKey, string | null> = {
'trace_explorer.toggle_trace_details': 'Trace Explorer: Toggle Trace Details in Table',
'trace_explorer.toggle_span_details': 'Trace Explorer: Toggle Span Details in Table',
'trace.preferences.autogrouping_change': 'Changed Autogrouping Preference',
'trace.preferences.clock_drift_correction_change':
'Changed Clock Drift Correction Preference',
'trace.preferences.compressed_timeline_change':
'Changed Compressed Timeline Preference',
'trace.preferences.missing_instrumentation_change':
Expand Down
1 change: 1 addition & 0 deletions static/app/views/explore/replays/detail/trace/trace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const DEFAULT_REPLAY_TRACE_VIEW_PREFERENCES: TracePreferencesState = {
missing_instrumentation: true,
autogroup: {parent: true, sibling: true},
compressed_timeline: false,
clock_drift_correction: false,
layout: 'drawer bottom',
list: {width: 0.5},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import {ClockDriftTag} from './clockDriftIndicators';

describe('ClockDriftTag', () => {
it('renders nothing for a span that was not shifted', () => {
const {container} = render(<ClockDriftTag offsetMs={0} />);
expect(container).toBeEmptyDOMElement();
});

it('explains a shift to a later time', async () => {
render(<ClockDriftTag offsetMs={2000} />);

await userEvent.hover(screen.getByText('Shifted +2.00s'));

expect(
await screen.findByText(
"Shown 2.00s later in the waterfall to correct for clock drift: the clocks of the services in this trace were out of sync. The span's duration and the timestamps below are unchanged."
)
).toBeInTheDocument();
});

it('explains a shift to an earlier time', async () => {
render(<ClockDriftTag offsetMs={-340} />);

await userEvent.hover(screen.getByText('Shifted −340.00ms'));

expect(
await screen.findByText(/^Shown 340.00ms earlier in the waterfall/)
).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {IconClock} from '@sentry/icons/clock';

import {Tag} from '@sentry/scraps/badge';
import {Tooltip} from '@sentry/scraps/tooltip';

import {t} from 'sentry/locale';
import {formatTraceDuration} from 'sentry/utils/duration/formatTraceDuration';

import {formatClockDriftOffset} from './traceModels/clockDriftCorrection';

// These components take the correction values as props rather than the node: nodes are mutated in
// place when the correction is toggled, so the React Compiler would not see a change in the node.

/**
* Explains the shift of a span in the waterfall. Wraps the duration label of the span. Renders the
* element as is if the span was not shifted.
*
* The element must be a DOM element, so the tooltip can attach to it without a wrapper that would
* break its positioning.
*/
export function ClockDriftTooltip({
children,
offsetMs,
}: {
children: React.ReactElement;
offsetMs: number;
}) {
if (offsetMs === 0) {
return children;
}

return (
<Tooltip
title={t(
'Shifted by %s to correct for clock drift',
formatClockDriftOffset(offsetMs)
)}
// Wrapping the short sentence leaves wide empty sides in the default 225px tooltip
maxWidth="none"
skipWrapper
>
{children}
</Tooltip>
);
}

/**
* Marks the duration label of the root of a subtree moved to correct for clock drift.
*/
export function ClockDriftLabelIcon({visible}: {visible: boolean}) {
if (!visible) {
return null;
}

return (
<span className="TraceClockDriftIcon" data-test-id="trace-clock-drift-icon">
<IconClock size="xs" />
</span>
);
}

/**
* Shown next to the duration in the drawer of a shifted span, as the drawer shows the recorded
* timestamps while the waterfall shows the shifted ones.
*/
export function ClockDriftTag({offsetMs}: {offsetMs: number}) {
if (offsetMs === 0) {
return null;
}

const distance = formatTraceDuration(Math.abs(offsetMs));
const title =
offsetMs > 0
? t(
"Shown %s later in the waterfall to correct for clock drift: the clocks of the services in this trace were out of sync. The span's duration and the timestamps below are unchanged.",
distance
)
: t(
"Shown %s earlier in the waterfall to correct for clock drift: the clocks of the services in this trace were out of sync. The span's duration and the timestamps below are unchanged.",
distance
);

return (
<Tooltip title={title} skipWrapper>
<Tag variant="muted" icon={<IconClock />}>
{t('Shifted %s', formatClockDriftOffset(offsetMs))}
</Tag>
</Tooltip>
);
}
172 changes: 172 additions & 0 deletions static/app/views/performance/traceDetails/trace.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,178 @@ describe('trace view', () => {
});
});

describe('clock drift correction', () => {
const organization = OrganizationFixture({
features: ['trace-waterfall-clock-drift-correction'],
});

beforeEach(() => {
// Trace preferences persist in local storage, don't let a toggled preference leak
localStorage.clear();
});

// The correction is off by default, store it as turned on
function storeClockDriftCorrectionPreference() {
localStorage.setItem(
'trace-waterfall-preferences',
JSON.stringify({
drawer_layout: 'drawer right',
missing_instrumentation: false,
autogroup: {parent: true, sibling: true},
compressed_timeline: true,
clock_drift_correction: true,
})
);
}

function mockClockDriftTrace() {
mockPerformanceSubscriptionDetailsResponse();
mockProjectDetailsResponse();
mockTraceResponse({
body: makeEAPTrace([
makeEAPSpan({
event_id: 'browser-request',
op: 'http.client',
description: 'GET /api/0/projects/',
project_id: 1,
sdk_name: 'sentry.javascript.react',
start_timestamp: 10,
end_timestamp: 10.5,
children: [
makeEAPSpan({
event_id: 'server-request',
op: 'http.server',
description: 'server request',
is_transaction: true,
project_id: 2,
sdk_name: 'sentry.python.django',
parent_span_id: 'browser-request',
// Recorded 2s before the browser sent the request
start_timestamp: 8,
end_timestamp: 8.2,
children: [
makeEAPSpan({
event_id: 'server-query',
op: 'db',
description: 'SELECT * FROM projects',
project_id: 2,
sdk_name: 'sentry.python.django',
parent_span_id: 'server-request',
start_timestamp: 8.05,
end_timestamp: 8.1,
}),
],
}),
],
}),
]),
});
mockTraceMetaResponse({
body: {
errorsCount: 0,
logsCount: 0,
metricsCount: 0,
performanceIssuesCount: 0,
spansCount: 3,
spansCountMap: {},
},
});
mockTraceRootFacets();
mockEventsResponse();
MockApiClient.addMockResponse({
url: '/projects/org-slug/project_slug/trace-items/browser-request/',
body: {
itemId: 'browser-request',
links: null,
meta: {},
timestamp: new Date(10e3).toISOString(),
attributes: [],
},
});
MockApiClient.addMockResponse({
url: '/projects/org-slug/project_slug/trace-items/server-request/',
body: {
itemId: 'server-request',
links: null,
meta: {},
timestamp: new Date(8e3).toISOString(),
attributes: [],
},
});
MockApiClient.addMockResponse({
url: '/projects/org-slug/project_slug/trace-items/server-query/',
body: {
itemId: 'server-query',
links: null,
meta: {},
timestamp: new Date(8.1e3).toISOString(),
attributes: [],
},
});
MockApiClient.addMockResponse({
url: '/organizations/org-slug/logs/',
body: {data: []},
});
MockApiClient.addMockResponse({
url: '/organizations/org-slug/dashboards/',
body: [],
});
}

it('is off by default and can be toggled', async () => {
mockClockDriftTrace();

render(<TraceView />, {initialRouterConfig, organization});

expect(await screen.findByText('server request')).toBeInTheDocument();
expect(screen.queryByTestId('trace-clock-drift-icon')).not.toBeInTheDocument();

await userEvent.click(screen.getByRole('button', {name: 'Trace Preferences'}));
await userEvent.click(screen.getByRole('option', {name: /Clock Drift Correction/}));

expect(await screen.findByTestId('trace-clock-drift-icon')).toBeInTheDocument();

await userEvent.click(screen.getByRole('option', {name: /Clock Drift Correction/}));

await waitFor(() => {
expect(screen.queryByTestId('trace-clock-drift-icon')).not.toBeInTheDocument();
});
});

it('is not available without the feature', async () => {
mockClockDriftTrace();
storeClockDriftCorrectionPreference();

render(<TraceView />, {
initialRouterConfig,
organization: OrganizationFixture({features: []}),
});

expect(await screen.findByText('server request')).toBeInTheDocument();
expect(screen.queryByTestId('trace-clock-drift-icon')).not.toBeInTheDocument();

await userEvent.click(screen.getByRole('button', {name: 'Trace Preferences'}));

expect(
screen.queryByRole('option', {name: /Clock Drift Correction/})
).not.toBeInTheDocument();
});

it('explains the shift when hovering the duration label of a span that moved along with its parent', async () => {
mockClockDriftTrace();
storeClockDriftCorrectionPreference();

render(<TraceView />, {initialRouterConfig, organization});

// The child has no icon, its label still explains the shift
await userEvent.hover(await screen.findByText('50.00ms'));

expect(
await screen.findByText('Shifted by +2.00s to correct for clock drift')
).toBeInTheDocument();
});
});

describe('pageload', () => {
it('expands and collapses loaded EAP children with keyboard navigation', async () => {
mockPerformanceSubscriptionDetailsResponse();
Expand Down
6 changes: 6 additions & 0 deletions static/app/views/performance/traceDetails/trace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
STATUS_TEXT,
} from 'sentry/views/insights/browser/webVitals/utils/scoreToStatus';

import {CLOCK_DRIFT_ICON_GAP_PX} from './traceModels/clockDriftCorrection';
import {TraceTree} from './traceModels/traceTree';
import type {BaseNode} from './traceModels/traceTreeNode/baseNode';
import type {TraceEvents, TraceScheduler} from './traceRenderers/traceScheduler';
Expand Down Expand Up @@ -1641,6 +1642,7 @@ const TraceStylingWrapper = styled('div')`
bottom: 0;
display: flex;
align-items: center;
gap: ${CLOCK_DRIFT_ICON_GAP_PX}px;
transform-origin: left center;
font-size: ${p => p.theme.font.size.xs};
line-height: 1;
Expand All @@ -1658,6 +1660,10 @@ const TraceStylingWrapper = styled('div')`
text-box: trim-both cap alphabetic;
}

.TraceClockDriftIcon {
display: flex;
}

.TraceChildrenCount {
height: 16px;
white-space: nowrap;
Expand Down
10 changes: 10 additions & 0 deletions static/app/views/performance/traceDetails/traceAnalytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ const trackCompressedTimelinePreferenceChange = (
) =>
trackAnalytics('trace.preferences.compressed_timeline_change', {organization, enabled});

const trackClockDriftCorrectionPreferenceChange = (
organization: Organization,
enabled: boolean
) =>
trackAnalytics('trace.preferences.clock_drift_correction_change', {
organization,
enabled,
});

const traceAnalytics = {
// Trace Onboarding
trackTracingOnboarding,
Expand Down Expand Up @@ -274,6 +283,7 @@ const traceAnalytics = {
trackAutogroupingPreferenceChange,
trackMissingInstrumentationPreferenceChange,
trackCompressedTimelinePreferenceChange,
trackClockDriftCorrectionPreferenceChange,
// Trace Drawer Details
trackEAPSpanHasDetails,
trackGenAISpanDetailsViewed,
Expand Down
Loading
Loading