Skip to content

Commit 0532f16

Browse files
committed
fix stuff...
1 parent e670133 commit 0532f16

File tree

9 files changed

+18
-25
lines changed

9 files changed

+18
-25
lines changed

dev-packages/e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"test:prepare": "ts-node prepare.ts",
1515
"test:validate": "run-s test:validate-configuration test:validate-test-app-setups",
1616
"clean": "rimraf tmp node_modules pnpm-lock.yaml && yarn clean:test-applications",
17-
"clean:test-applications": "rimraf test-applications/**/{node_modules,dist,build,.next,.sveltekit,pnpm-lock.yaml} .last-run.json"
17+
"clean:test-applications": "rimraf test-applications/**/{node_modules,dist,build,.next,.sveltekit,pnpm-lock.yaml} .last-run.json && pnpm store prune"
1818
},
1919
"devDependencies": {
2020
"@types/glob": "8.0.0",

dev-packages/e2e-tests/test-applications/create-next-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"build": "next build",
7-
"clean": "npx rimraf node_modules pnpm-lock.yaml",
7+
"clean": "npx rimraf node_modules pnpm-lock.yaml .next",
88
"test:prod": "TEST_ENV=prod playwright test",
99
"test:dev": "TEST_ENV=dev playwright test",
1010
"test:build": "pnpm install && npx playwright install && pnpm build",

dev-packages/e2e-tests/test-applications/create-next-app/sentry.client.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import * as Sentry from '@sentry/nextjs';
77
Sentry.init({
88
environment: 'qa', // dynamic sampling bias to keep transactions
99
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN,
10-
1110
tracesSampleRate: 1.0,
12-
1311
tunnel: 'http://localhost:3031',
1412
});

dev-packages/e2e-tests/test-applications/create-next-app/tests/server-errors.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,5 @@ test('Sends a server-side exception to Sentry', async ({ baseURL }) => {
2727
expect(errorEvent.contexts?.trace).toEqual({
2828
trace_id: expect.any(String),
2929
span_id: expect.any(String),
30-
// TODO: Why does this have a parent span ID?
31-
parent_span_id: expect.any(String),
3230
});
3331
});

dev-packages/e2e-tests/test-applications/create-next-app/tests/server-transactions.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ test('Sends server-side transactions to Sentry', async ({ baseURL }) => {
2626
trace: {
2727
span_id: expect.any(String),
2828
trace_id: expect.any(String),
29-
// TODO: Why does this have a parent span ID?
30-
parent_span_id: expect.any(String),
3129
op: 'http.server',
3230
origin: 'auto.http.nextjs',
3331
data: expect.objectContaining({

packages/nextjs/src/common/utils/tracingUtils.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Scope, getCurrentScope, withActiveSpan } from '@sentry/core';
1+
import { Scope, startNewTrace } from '@sentry/core';
22
import type { PropagationContext } from '@sentry/types';
3-
import { GLOBAL_OBJ, logger, uuid4 } from '@sentry/utils';
3+
import { GLOBAL_OBJ, logger } from '@sentry/utils';
44
import { DEBUG_BUILD } from '../debug-build';
55

66
const commonPropagationContextMap = new WeakMap<object, PropagationContext>();
@@ -85,11 +85,7 @@ export function escapeNextjsTracing<T>(cb: () => T): T {
8585
if (nextjsEscapedAsyncStorage.getStore()) {
8686
return cb();
8787
} else {
88-
return withActiveSpan(null, () => {
89-
getCurrentScope().setPropagationContext({
90-
traceId: uuid4(),
91-
spanId: uuid4().substring(16),
92-
});
88+
return startNewTrace(() => {
9389
return nextjsEscapedAsyncStorage.run(true, () => {
9490
return cb();
9591
});

packages/nextjs/src/common/wrapApiHandlerWithSentry.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
8181
// eslint-disable-next-line @typescript-eslint/unbound-method
8282
res.end = new Proxy(res.end, {
8383
apply(target, thisArg, argArray) {
84-
setHttpStatus(span, res.statusCode);
85-
span.end();
84+
if (span.isRecording()) {
85+
setHttpStatus(span, res.statusCode);
86+
span.end();
87+
}
8688
vercelWaitUntil(flushSafelyWithTimeout());
8789
target.apply(thisArg, argArray);
8890
},
@@ -128,8 +130,10 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
128130
res.statusCode = 500;
129131
res.statusMessage = 'Internal Server Error';
130132

131-
setHttpStatus(span, res.statusCode);
132-
span.end();
133+
if (span.isRecording()) {
134+
setHttpStatus(span, res.statusCode);
135+
span.end();
136+
}
133137

134138
vercelWaitUntil(flushSafelyWithTimeout());
135139

packages/opentelemetry/src/propagator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Baggage, Context, Span, SpanContext, TextMapGetter, TextMapSetter } from '@opentelemetry/api';
2+
import { INVALID_TRACEID } from '@opentelemetry/api';
23
import { context } from '@opentelemetry/api';
34
import { TraceFlags, propagation, trace } from '@opentelemetry/api';
45
import { TraceState, W3CBaggagePropagator, isTracingSuppressed } from '@opentelemetry/core';
@@ -127,7 +128,7 @@ export class SentryPropagator extends W3CBaggagePropagator {
127128
}
128129

129130
// We also want to avoid setting the default OTEL trace ID, if we get that for whatever reason
130-
if (traceId && traceId !== '00000000000000000000000000000000') {
131+
if (traceId && traceId !== INVALID_TRACEID) {
131132
setter.set(carrier, SENTRY_TRACE_HEADER, generateSentryTraceHeader(traceId, spanId, sampled));
132133
}
133134

packages/opentelemetry/src/trace.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { Context, Span, SpanContext, SpanOptions, Tracer } from '@opentelemetry/api';
2-
import { TraceFlags } from '@opentelemetry/api';
3-
import { context } from '@opentelemetry/api';
4-
import { SpanStatusCode, trace } from '@opentelemetry/api';
2+
import { INVALID_SPANID, SpanStatusCode, TraceFlags, context, trace } from '@opentelemetry/api';
53
import { suppressTracing } from '@opentelemetry/core';
64
import {
75
SDK_VERSION,
@@ -192,7 +190,7 @@ function getContext(scope: Scope | undefined, forceTransaction: boolean | undefi
192190

193191
const spanContext: SpanContext = {
194192
traceId: propagationContext.traceId,
195-
spanId: propagationContext.parentSpanId || propagationContext.spanId,
193+
spanId: propagationContext.parentSpanId || INVALID_SPANID,
196194
isRemote: true,
197195
traceFlags: propagationContext.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,
198196
traceState,
@@ -228,7 +226,7 @@ function getContext(scope: Scope | undefined, forceTransaction: boolean | undefi
228226

229227
const traceState = makeTraceState({
230228
dsc,
231-
parentSpanId: spanId,
229+
parentSpanId: spanId !== INVALID_SPANID ? spanId : undefined,
232230
sampled,
233231
});
234232

0 commit comments

Comments
 (0)