Skip to content

Commit 26d7f2a

Browse files
committed
feat(nextjs): Mark the late pageload link as a server_request link
Without a type, the link from a pageload to the server request whose trace context arrived too late shows up in Sentry with no meaning. The type is documented in getsentry/sentry-docs#20112.
1 parent 320309e commit 26d7f2a

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/nextjs/src/client/routing/traceMetaTags.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SENTRY_LINK_TYPE } from '@sentry/conventions/attributes';
12
import type { Span } from '@sentry/core';
23
import { extractTraceparentData } from '@sentry/core';
34
import { GLOBAL_OBJ } from '@sentry/core';
@@ -7,6 +8,8 @@ import { WINDOW } from '@sentry/react';
78
const TRACE_FLAG_SAMPLED = 0x1;
89
const TRACE_FLAG_NONE = 0x0;
910

11+
const SERVER_REQUEST_LINK_TYPE = 'server_request';
12+
1013
export interface TraceMetaTagValues {
1114
sentryTrace: string;
1215
baggage: string | undefined;
@@ -144,5 +147,6 @@ export function addTraceMetaTagLink(span: Span, { sentryTrace }: TraceMetaTagVal
144147
spanId: traceparent.parentSpanId,
145148
traceFlags: traceparent.parentSampled ? TRACE_FLAG_SAMPLED : TRACE_FLAG_NONE,
146149
},
150+
attributes: { [SENTRY_LINK_TYPE]: SERVER_REQUEST_LINK_TYPE },
147151
});
148152
}

‎packages/nextjs/test/client/traceMetaTags.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @vitest-environment jsdom
2+
import { SENTRY_LINK_TYPE } from '@sentry/conventions/attributes';
23
import type { Span } from '@sentry/core';
34
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
45
import {
@@ -191,7 +192,7 @@ describe('waitForTraceMetaTag', () => {
191192
});
192193

193194
describe('addTraceMetaTagLink', () => {
194-
it('links the span described by the sentry-trace value and carries the sampled flag', () => {
195+
it('links the server request described by the sentry-trace value and carries the sampled flag', () => {
195196
const span = { addLink: vi.fn() } as unknown as Span;
196197

197198
addTraceMetaTagLink(span, { sentryTrace: HEAD_TRACE, baggage: undefined });
@@ -202,9 +203,11 @@ describe('addTraceMetaTagLink', () => {
202203

203204
expect(span.addLink).toHaveBeenNthCalledWith(1, {
204205
context: { traceId: '11111111111111111111111111111111', spanId: '1111111111111111', traceFlags: 1 },
206+
attributes: { [SENTRY_LINK_TYPE]: 'server_request' },
205207
});
206208
expect(span.addLink).toHaveBeenNthCalledWith(2, {
207209
context: { traceId: '33333333333333333333333333333333', spanId: '3333333333333333', traceFlags: 0 },
210+
attributes: { [SENTRY_LINK_TYPE]: 'server_request' },
208211
});
209212
});
210213

0 commit comments

Comments
 (0)