Skip to content

Commit 6a9d230

Browse files
authored
Merge branch 'develop' into cg-split-nextjs-app-dir-test
2 parents 47420c0 + 68d7ee4 commit 6a9d230

File tree

30 files changed

+505
-84
lines changed

30 files changed

+505
-84
lines changed

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ module.exports = [
233233
import: createImport('init'),
234234
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
235235
gzip: true,
236-
limit: '144 KB',
236+
limit: '146 KB',
237237
},
238238
{
239239
name: '@sentry/node - without tracing',

dev-packages/e2e-tests/test-applications/nextjs-15/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ next-env.d.ts
4444

4545
test-results
4646
event-dumps
47+
48+
.tmp_dev_server_logs
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <p>Next 15 test app</p>;
3+
}

dev-packages/e2e-tests/test-applications/nextjs-15/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 > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)",
7-
"clean": "npx rimraf node_modules pnpm-lock.yaml",
7+
"clean": "npx rimraf node_modules pnpm-lock.yaml .tmp_dev_server_logs",
88
"test:prod": "TEST_ENV=production playwright test",
99
"test:dev": "TEST_ENV=development playwright test",
1010
"test:dev-turbo": "TEST_ENV=dev-turbopack playwright test",

dev-packages/e2e-tests/test-applications/nextjs-15/playwright.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ if (!testEnv) {
77

88
const getStartCommand = () => {
99
if (testEnv === 'dev-turbopack') {
10-
return 'pnpm next dev -p 3030 --turbopack';
10+
return 'pnpm next dev -p 3030 --turbopack 2>&1 | tee .tmp_dev_server_logs';
1111
}
1212

1313
if (testEnv === 'development') {
14-
return 'pnpm next dev -p 3030';
14+
return 'pnpm next dev -p 3030 2>&1 | tee .tmp_dev_server_logs';
1515
}
1616

1717
if (testEnv === 'production') {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect, test } from '@playwright/test';
2+
import fs from 'fs';
3+
4+
test('should not print warning for async params', async ({ page }) => {
5+
test.skip(
6+
process.env.TEST_ENV !== 'development' && process.env.TEST_ENV !== 'dev-turbopack',
7+
'should be skipped for non-dev mode',
8+
);
9+
await page.goto('/');
10+
11+
// If the server exits with code 1, the test will fail (see instrumentation.ts)
12+
const devStdout = fs.readFileSync('.tmp_dev_server_logs', 'utf-8');
13+
expect(devStdout).not.toContain('`params` should be awaited before using its properties.');
14+
15+
await expect(page.getByText('Next 15 test app')).toBeVisible();
16+
});

packages/core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export { instrumentOpenAiClient } from './utils/openai';
122122
export { OPENAI_INTEGRATION_NAME } from './utils/openai/constants';
123123
export type { OpenAiClient, OpenAiOptions, InstrumentedMethod } from './utils/openai/types';
124124
export type { FeatureFlag } from './utils/featureFlags';
125+
125126
export {
126127
_INTERNAL_copyFlagsFromScopeToEvent,
127128
_INTERNAL_insertFlagToScope,
@@ -219,6 +220,7 @@ export {
219220
extractTraceparentData,
220221
generateSentryTraceHeader,
221222
propagationContextFromHeaders,
223+
shouldContinueTrace,
222224
} from './utils/tracing';
223225
export { getSDKSource, isBrowserBundle } from './utils/env';
224226
export type { SdkSource } from './utils/env';

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import type { DynamicSamplingContext } from '../types-hoist/envelope';
1111
import type { Span } from '../types-hoist/span';
1212
import { baggageHeaderToDynamicSamplingContext, dynamicSamplingContextToSentryBaggageHeader } from '../utils/baggage';
13-
import { extractOrgIdFromDsnHost } from '../utils/dsn';
13+
import { extractOrgIdFromClient } from '../utils/dsn';
1414
import { hasSpansEnabled } from '../utils/hasSpansEnabled';
1515
import { addNonEnumerableProperty } from '../utils/object';
1616
import { getRootSpan, spanIsSampled, spanToJSON } from '../utils/spanUtils';
@@ -42,14 +42,7 @@ export function freezeDscOnSpan(span: Span, dsc: Partial<DynamicSamplingContext>
4242
export function getDynamicSamplingContextFromClient(trace_id: string, client: Client): DynamicSamplingContext {
4343
const options = client.getOptions();
4444

45-
const { publicKey: public_key, host } = client.getDsn() || {};
46-
47-
let org_id: string | undefined;
48-
if (options.orgId) {
49-
org_id = String(options.orgId);
50-
} else if (host) {
51-
org_id = extractOrgIdFromDsnHost(host);
52-
}
45+
const { publicKey: public_key } = client.getDsn() || {};
5346

5447
// Instead of conditionally adding non-undefined values, we add them and then remove them if needed
5548
// otherwise, the order of baggage entries changes, which "breaks" a bunch of tests etc.
@@ -58,7 +51,7 @@ export function getDynamicSamplingContextFromClient(trace_id: string, client: Cl
5851
release: options.release,
5952
public_key,
6053
trace_id,
61-
org_id,
54+
org_id: extractOrgIdFromClient(client),
6255
};
6356

6457
client.emit('createDsc', dsc);

packages/core/src/tracing/trace.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import type { DynamicSamplingContext } from '../types-hoist/envelope';
1111
import type { ClientOptions } from '../types-hoist/options';
1212
import type { SentrySpanArguments, Span, SpanTimeInput } from '../types-hoist/span';
1313
import type { StartSpanOptions } from '../types-hoist/startSpanOptions';
14+
import { baggageHeaderToDynamicSamplingContext } from '../utils/baggage';
1415
import { debug } from '../utils/debug-logger';
1516
import { handleCallbackErrors } from '../utils/handleCallbackErrors';
1617
import { hasSpansEnabled } from '../utils/hasSpansEnabled';
1718
import { parseSampleRate } from '../utils/parseSampleRate';
1819
import { generateTraceId } from '../utils/propagationContext';
1920
import { _getSpanForScope, _setSpanForScope } from '../utils/spanOnScope';
2021
import { addChildSpanToSpan, getRootSpan, spanIsSampled, spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';
21-
import { propagationContextFromHeaders } from '../utils/tracing';
22+
import { propagationContextFromHeaders, shouldContinueTrace } from '../utils/tracing';
2223
import { freezeDscOnSpan, getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
2324
import { logSpanStart } from './logSpans';
2425
import { sampleSpan } from './sampling';
@@ -216,6 +217,12 @@ export const continueTrace = <V>(
216217

217218
const { sentryTrace, baggage } = options;
218219

220+
const client = getClient();
221+
const incomingDsc = baggageHeaderToDynamicSamplingContext(baggage);
222+
if (client && !shouldContinueTrace(client, incomingDsc?.org_id)) {
223+
return startNewTrace(callback);
224+
}
225+
219226
return withScope(scope => {
220227
const propagationContext = propagationContextFromHeaders(sentryTrace, baggage);
221228
scope.setPropagationContext(propagationContext);

packages/core/src/types-hoist/options.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,23 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
302302
tracePropagationTargets?: TracePropagationTargets;
303303

304304
/**
305-
* The organization ID of the current SDK. The organization ID is a string containing only numbers. This ID is used to
306-
* propagate traces to other Sentry services.
305+
* If set to `true`, the SDK will only continue a trace if the `organization ID` of the incoming trace found in the
306+
* `baggage` header matches the `organization ID` of the current Sentry client.
307307
*
308-
* The SDK tries to automatically extract the organization ID from the DSN. With this option, you can override it.
308+
* The client's organization ID is extracted from the DSN or can be set with the `orgId` option.
309+
*
310+
* If the organization IDs do not match, the SDK will start a new trace instead of continuing the incoming one.
311+
* This is useful to prevent traces of unknown third-party services from being continued in your application.
312+
*
313+
* @default false
314+
*/
315+
strictTraceContinuation?: boolean;
316+
317+
/**
318+
* The organization ID for your Sentry project.
319+
*
320+
* The SDK will try to extract the organization ID from the DSN. If it cannot be found, or if you need to override it,
321+
* you can provide the ID with this option. The organization ID is used for trace propagation and for features like `strictTraceContinuation`.
309322
*/
310323
orgId?: `${number}` | number;
311324

0 commit comments

Comments
 (0)