Skip to content

Commit b0e1db0

Browse files
authored
feat(sveltekit): Switch to Otel-based @sentry/node package (#11075)
This PR switches the underlying Node SDK from `@sentry/node-experimental` (aka the "legacy" v7 Node SDK) to the new OpenTelemetry-based `@sentry/node` package.
1 parent d2005ba commit b0e1db0

File tree

14 files changed

+111
-103
lines changed

14 files changed

+111
-103
lines changed

dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const DEPENDENTS: Dependent[] = [
9898
},
9999
{
100100
package: '@sentry/sveltekit',
101-
compareWith: nodeExperimentalExports,
101+
compareWith: nodeExports,
102102
exports: Object.keys(SentrySvelteKit),
103103
},
104104
];

packages/sveltekit/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"dependencies": {
4040
"@sentry-internal/tracing": "8.0.0-alpha.2",
4141
"@sentry/core": "8.0.0-alpha.2",
42-
"@sentry/node-experimental": "8.0.0-alpha.2",
42+
"@sentry/node": "8.0.0-alpha.2",
43+
"@sentry/opentelemetry": "8.0.0-alpha.2",
4344
"@sentry/svelte": "8.0.0-alpha.2",
4445
"@sentry/types": "8.0.0-alpha.2",
4546
"@sentry/utils": "8.0.0-alpha.2",
@@ -68,7 +69,7 @@
6869
"fix": "eslint . --format stylish --fix",
6970
"lint": "eslint . --format stylish",
7071
"test": "yarn test:unit",
71-
"test:unit": "vitest run",
72+
"test:unit": "vitest run --outputDiffMaxLines=2000",
7273
"test:watch": "vitest --watch",
7374
"yalc:publish": "ts-node ../../scripts/prepack.ts && yalc publish build --push --sig"
7475
},

packages/sveltekit/src/index.types.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ export declare function handleErrorWithSentry<T extends HandleClientError | Hand
3636
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3737
export declare function wrapLoadWithSentry<T extends (...args: any) => any>(origLoad: T): T;
3838

39-
// We export a merged Integrations object so that users can (at least typing-wise) use all integrations everywhere.
40-
// eslint-disable-next-line deprecation/deprecation
41-
export declare const Integrations: typeof clientSdk.Integrations & typeof serverSdk.Integrations;
42-
4339
export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
4440
export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration;
4541

4642
export declare const getDefaultIntegrations: (options: Options) => Integration[];
4743
export declare const defaultStackParser: StackParser;
4844

45+
export declare const getClient: typeof clientSdk.getClient;
46+
// eslint-disable-next-line deprecation/deprecation
47+
export declare const getCurrentHub: typeof clientSdk.getCurrentHub;
48+
// eslint-disable-next-line deprecation/deprecation
49+
export declare const makeMain: typeof clientSdk.makeMain;
4950
export declare function close(timeout?: number | undefined): PromiseLike<boolean>;
5051
export declare function flush(timeout?: number | undefined): PromiseLike<boolean>;
5152

53+
export declare const continueTrace: typeof clientSdk.continueTrace;
54+
5255
export declare const metrics: typeof clientSdk.metrics & typeof serverSdk.metrics;

packages/sveltekit/src/server/handle.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import {
22
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
33
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
4-
continueTrace,
54
getActiveSpan,
6-
getDynamicSamplingContextFromSpan,
75
getRootSpan,
86
setHttpStatus,
97
spanToTraceHeader,
108
withIsolationScope,
119
} from '@sentry/core';
1210
import { startSpan } from '@sentry/core';
13-
import { captureException } from '@sentry/node-experimental';
11+
import { captureException, continueTrace } from '@sentry/node';
1412
import type { Span } from '@sentry/types';
1513
import { dynamicSamplingContextToSentryBaggageHeader, objectify } from '@sentry/utils';
1614
import type { Handle, ResolveOptions } from '@sveltejs/kit';
1715

16+
import { getDynamicSamplingContextFromSpan } from '@sentry/opentelemetry';
17+
1818
import { isHttpError, isRedirect } from '../common/utils';
1919
import { flushIfServerless, getTracePropagationData } from './utils';
2020

@@ -149,9 +149,10 @@ export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
149149
};
150150

151151
const sentryRequestHandler: Handle = input => {
152-
// if there is an active transaction, we know that this handle call is nested and hence
153-
// we don't create a new domain for it. If we created one, nested server calls would
154-
// create new transactions instead of adding a child span to the currently active span.
152+
// if there is an active span, we know that this handle call is nested and hence
153+
// we don't create a new execution context for it.
154+
// If we created one, nested server calls would create new root span instead
155+
// of adding a child span to the currently active span.
155156
if (getActiveSpan()) {
156157
return instrumentHandle(input, options);
157158
}
@@ -181,6 +182,7 @@ async function instrumentHandle(
181182
attributes: {
182183
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.sveltekit',
183184
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: event.route?.id ? 'route' : 'url',
185+
'http.method': event.request.method,
184186
},
185187
name: `${event.request.method} ${event.route?.id || event.url.pathname}`,
186188
},

packages/sveltekit/src/server/handleError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureException } from '@sentry/node-experimental';
1+
import { captureException } from '@sentry/node';
22
import type { HandleServerError } from '@sveltejs/kit';
33

44
import { flushIfServerless } from './utils';

packages/sveltekit/src/server/index.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Node SDK exports
2-
// Unfortunately, we cannot `export * from '@sentry/node-experimental'` because in prod builds,
2+
// Unfortunately, we cannot `export * from '@sentry/node'` because in prod builds,
33
// Vite puts these exports into a `default` property (Sentry.default) rather than
44
// on the top - level namespace.
55
// Hence, we export everything from the Node SDK explicitly:
66
export {
7-
// eslint-disable-next-line deprecation/deprecation
8-
addGlobalEventProcessor,
97
addEventProcessor,
108
addBreadcrumb,
119
addIntegration,
@@ -15,10 +13,6 @@ export {
1513
captureCheckIn,
1614
withMonitor,
1715
createTransport,
18-
// eslint-disable-next-line deprecation/deprecation
19-
getActiveTransaction,
20-
// eslint-disable-next-line deprecation/deprecation
21-
getCurrentHub,
2216
getClient,
2317
isInitialized,
2418
getCurrentScope,
@@ -41,7 +35,6 @@ export {
4135
setHttpStatus,
4236
withScope,
4337
withIsolationScope,
44-
autoDiscoverNodePerformanceMonitoringIntegrations,
4538
makeNodeTransport,
4639
getDefaultIntegrations,
4740
defaultStackParser,
@@ -51,7 +44,6 @@ export {
5144
addRequestDataToEvent,
5245
DEFAULT_USER_INCLUDES,
5346
extractRequestData,
54-
Integrations,
5547
consoleIntegration,
5648
onUncaughtExceptionIntegration,
5749
onUnhandledRejectionIntegration,
@@ -63,7 +55,6 @@ export {
6355
functionToStringIntegration,
6456
inboundFiltersIntegration,
6557
linkedErrorsIntegration,
66-
Handlers,
6758
setMeasurement,
6859
getActiveSpan,
6960
getRootSpan,
@@ -75,16 +66,15 @@ export {
7566
cron,
7667
parameterize,
7768
createGetModuleFromFilename,
78-
hapiErrorPlugin,
7969
metrics,
8070
SEMANTIC_ATTRIBUTE_SENTRY_OP,
8171
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
8272
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
8373
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
84-
} from '@sentry/node-experimental';
74+
} from '@sentry/node';
8575

8676
// We can still leave this for the carrier init and type exports
87-
export * from '@sentry/node-experimental';
77+
export * from '@sentry/node';
8878

8979
// -------------------------
9080
// SvelteKit SDK exports:

packages/sveltekit/src/server/load.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
33
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
4+
captureException,
45
continueTrace,
56
startSpan,
6-
} from '@sentry/core';
7-
import { captureException } from '@sentry/node-experimental';
7+
} from '@sentry/node';
88
import { addNonEnumerableProperty, objectify } from '@sentry/utils';
99
import type { LoadEvent, ServerLoadEvent } from '@sveltejs/kit';
1010

packages/sveltekit/src/server/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { applySdkMetadata, setTag } from '@sentry/core';
2-
import type { NodeOptions } from '@sentry/node-experimental';
3-
import { getDefaultIntegrations as getDefaultNodeIntegrations } from '@sentry/node-experimental';
4-
import { init as initNodeSdk } from '@sentry/node-experimental';
2+
import type { NodeOptions } from '@sentry/node';
3+
import { getDefaultIntegrations as getDefaultNodeIntegrations } from '@sentry/node';
4+
import { init as initNodeSdk } from '@sentry/node';
55

66
import { rewriteFramesIntegration } from './rewriteFramesIntegration';
77

packages/sveltekit/src/server/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { flush } from '@sentry/node-experimental';
1+
import { flush } from '@sentry/node';
22
import { logger } from '@sentry/utils';
33
import type { RequestEvent } from '@sveltejs/kit';
44

packages/sveltekit/src/vite/sourceMaps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as child_process from 'child_process';
22
import * as fs from 'fs';
33
import * as path from 'path';
4-
import { getSentryRelease } from '@sentry/node-experimental';
4+
import { getSentryRelease } from '@sentry/node';
55
import { escapeStringForRegex, uuid4 } from '@sentry/utils';
66
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
77
import { sentryVitePlugin } from '@sentry/vite-plugin';

0 commit comments

Comments
 (0)