Skip to content

Commit fd8b435

Browse files
fix(trace): Query pinned attributes at the recorded time of moved spans
Pinned attribute values were queried over the trace space, which clock drift correction rewrites to the corrected bounds. Spans moved by the correction were recorded outside of it, so their values were missing. The tree now keeps the range its spans were recorded in, also for appended trees, and the query uses it. Co-Authored-By: Lukas Stracke <lukas.stracke@sentry.io>
1 parent b58109d commit fd8b435

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

‎static/app/views/performance/traceDetails/traceModels/clockDriftCorrection.spec.tsx‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,4 +786,44 @@ describe('clock drift correction', () => {
786786
expect(start + duration).toBeCloseTo(trace.space[0] + trace.space[1]);
787787
});
788788
});
789+
790+
describe('recorded space', () => {
791+
const drifted = (id: string) =>
792+
makeRequest({
793+
id,
794+
clientStart: 0,
795+
clientDuration: 480.8,
796+
serverStartGap: -121_056.4,
797+
serverDuration: 121.4,
798+
});
799+
800+
it('covers the recorded time of moved spans', () => {
801+
const tree = build(makePageload([drifted('1')]));
802+
803+
expect(tree.root.space[0]).toBeCloseTo((T - 10) * 1e3);
804+
expect(tree.recorded_space[0]).toBeCloseTo((T - 121.0564) * 1e3);
805+
expect(tree.recorded_space[0] + tree.recorded_space[1]).toBeCloseTo(
806+
tree.root.space[0] + tree.root.space[1]
807+
);
808+
});
809+
810+
it('matches the trace space without correction', () => {
811+
const tree = build(makePageload([drifted('1')]));
812+
813+
tree.setClockDriftCorrection(false, {organization, preferences});
814+
815+
expect(tree.recorded_space).toEqual(tree.root.space);
816+
expect(tree.recorded_space[0]).toBeCloseTo((T - 121.0564) * 1e3);
817+
});
818+
819+
it('covers the recorded time of moved spans in appended trees', () => {
820+
const tree = build(makePageload([]));
821+
tree.appendTree(build(makePageload([drifted('1')])));
822+
823+
expect(tree.recorded_space[0]).toBeCloseTo((T - 121.0564) * 1e3);
824+
expect(tree.recorded_space[0] + tree.recorded_space[1]).toBeCloseTo(
825+
(T + 300) * 1e3
826+
);
827+
});
828+
});
789829
});

‎static/app/views/performance/traceDetails/traceModels/traceTree.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {UptimeCheckNode} from './traceTreeNode/uptimeCheckNode';
4646
import {traceChronologicalSort} from './traceTreeNode/utils';
4747
import {
4848
applyClockDriftCorrection,
49+
getRecordedSubtreeSpace,
4950
removeClockDriftCorrection,
5051
} from './clockDriftCorrection';
5152
import {makeExampleTraceData} from './makeExampleTraceData';
@@ -351,6 +352,12 @@ export class TraceTree extends TraceTreeEventDispatcher {
351352
*/
352353
replay_bounds: [start: number, end: number] | null = null;
353354

355+
/**
356+
* The range the spans of the trace were recorded in. Clock drift correction can move spans out
357+
* of it, so the root space no longer covers them. Query data stored with the spans by this range.
358+
*/
359+
recorded_space: [start: number, duration: number] = [0, 0];
360+
354361
static MISSING_INSTRUMENTATION_THRESHOLD_MS = 100;
355362

356363
static Empty() {
@@ -590,6 +597,10 @@ export class TraceTree extends TraceTreeEventDispatcher {
590597
for (const traceNode of this.root.children) {
591598
traceNode.space = [start, end - start];
592599
}
600+
this.recorded_space =
601+
this.clock_drift_correction_count > 0
602+
? getRecordedSubtreeSpace(this.root)
603+
: [start, end - start];
593604

594605
if (changed) {
595606
this.dispatch('trace timeline change', this.root.space);
@@ -705,6 +716,13 @@ export class TraceTree extends TraceTreeEventDispatcher {
705716
this.dispatch('trace timeline change', this.root.space);
706717
}
707718

719+
const recordedStart = Math.min(this.recorded_space[0], tree.recorded_space[0]);
720+
const recordedEnd = Math.max(
721+
this.recorded_space[0] + this.recorded_space[1],
722+
tree.recorded_space[0] + tree.recorded_space[1]
723+
);
724+
this.recorded_space = [recordedStart, recordedEnd - recordedStart];
725+
708726
for (const child of tree.root.children) {
709727
this.list = this.list.concat(child.visibleChildren);
710728
}

‎static/app/views/performance/traceDetails/tracePinnedAttribute.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ export function useTracePinnedAttribute({
9595
// Query the full loaded trace independently of the selected span or error.
9696
// Round the time range outward to whole seconds so the events query includes
9797
// spans at both trace boundaries, including zero-duration spans.
98-
const start = Math.floor(tree.root.space[0] / 1000) * 1000;
99-
const end = (Math.floor((tree.root.space[0] + tree.root.space[1]) / 1000) + 1) * 1000;
98+
const [recordedStart, recordedDuration] = tree.recorded_space;
99+
const start = Math.floor(recordedStart / 1000) * 1000;
100+
const end = (Math.floor((recordedStart + recordedDuration) / 1000) + 1) * 1000;
100101
const query = useInfiniteQuery({
101102
...apiOptions.asInfinite<PinnedAttributeResponse>()(
102103
'/organizations/$organizationIdOrSlug/events/',

0 commit comments

Comments
 (0)