Skip to content

Commit 87c4109

Browse files
committed
review suggestions, comments, revert kitSpansIntegrations optimization, change root span enhancement time
1 parent d265348 commit 87c4109

File tree

4 files changed

+24
-48
lines changed

4 files changed

+24
-48
lines changed

packages/sveltekit/src/server-common/handle.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,9 @@ async function instrumentHandle(
155155
// https://github.com/getsentry/sentry-javascript/issues/14583
156156
normalizedRequest: winterCGRequestToRequestData(event.request),
157157
});
158-
159-
const res = await resolve(event, {
160-
transformPageChunk: addSentryCodeToPage({
161-
injectFetchProxyScript: options.injectFetchProxyScript ?? true,
162-
}),
163-
});
164-
165158
const kitRootSpan = event.tracing?.enabled ? event.tracing?.root : undefined;
166159

167-
if (sentrySpan) {
168-
setHttpStatus(sentrySpan, res.status);
169-
} else if (kitRootSpan) {
160+
if (kitRootSpan) {
170161
// Update the root span emitted from SvelteKit to resemble a `http.server` span
171162
// We're doing this here instead of an event processor to ensure we update the
172163
// span name as early as possible (for dynamic sampling, et al.)
@@ -188,6 +179,16 @@ async function instrumentHandle(
188179
});
189180
}
190181

182+
const res = await resolve(event, {
183+
transformPageChunk: addSentryCodeToPage({
184+
injectFetchProxyScript: options.injectFetchProxyScript ?? true,
185+
}),
186+
});
187+
188+
if (sentrySpan) {
189+
setHttpStatus(sentrySpan, res.status);
190+
}
191+
191192
return res;
192193
};
193194

packages/sveltekit/src/server-common/integrations/svelteKitSpans.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import { type SpanJSON, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_
88
*/
99
export function svelteKitSpansIntegration(): Integration {
1010
return {
11-
name: 'SvelteKitSpansEnhancment',
11+
name: 'SvelteKitSpansEnhancement',
1212
// Using preprocessEvent to ensure the processing happens before user-configured
1313
// event processors are executed
1414
preprocessEvent(event) {
1515
// only iterate over the spans if the root span was emitted by SvelteKit
16-
if (event.type === 'transaction' && event.contexts?.trace?.data?.['sveltekit.tracing.original_name']) {
16+
// TODO: Right now, we can't optimize this to only check traces with a kit-emitted root span
17+
// this is because in Cloudflare, the kit-emitted root span is missing but our cloudflare
18+
// SDK emits the http.server span.
19+
if (event.type === 'transaction') {
1720
event.spans?.forEach(_enhanceKitSpan);
1821
}
1922
},

packages/sveltekit/src/vite/sentryVitePlugins.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {}
3333

3434
if (mergedOptions.autoInstrument) {
3535
// TODO: Once tracing is promoted stable, we need to adjust this check!
36-
// We probably need to make a instrumentation.server.ts|js file lookup instead.
3736
const kitTracingEnabled = !!svelteConfig.kit?.experimental?.tracing?.server;
3837

3938
const pluginOptions: AutoInstrumentSelection = {
@@ -55,6 +54,12 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {}
5554
const sentryVitePluginsOptions = generateVitePluginOptions(mergedOptions);
5655

5756
if (mergedOptions.autoUploadSourceMaps) {
57+
// When source maps are enabled, we need to inject the output directory to get a correct
58+
// stack trace, by using this SDK's `rewriteFrames` integration.
59+
// This integration picks up the value.
60+
// TODO: I don't think this is technically correct. Either we always or never inject the output directory.
61+
// Stack traces shouldn't be different, depending on source maps config. With debugIds, we might not even
62+
// need to rewrite frames anymore.
5863
sentryPlugins.push(await makeGlobalValuesInjectionPlugin(svelteConfig, mergedOptions));
5964
}
6065

packages/sveltekit/test/server-common/integrations/svelteKitSpans.test.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ describe('svelteKitSpansIntegration', () => {
77
it('has a name and a preprocessEventHook', () => {
88
const integration = svelteKitSpansIntegration();
99

10-
expect(integration.name).toBe('SvelteKitSpansEnhancment');
10+
expect(integration.name).toBe('SvelteKitSpansEnhancement');
1111
expect(typeof integration.preprocessEvent).toBe('function');
1212
});
1313

14-
it('enhances spans from SvelteKit, if root span was emitted by SvelteKit', () => {
14+
it('enhances spans from SvelteKit', () => {
1515
const event: TransactionEvent = {
1616
type: 'transaction',
1717
contexts: {
@@ -46,39 +46,6 @@ describe('svelteKitSpansIntegration', () => {
4646
expect(event.spans?.[0]?.data[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toBe('auto.http.sveltekit');
4747
});
4848

49-
it('does not enhance spans from SvelteKit, if root span was not emitted by SvelteKit', () => {
50-
const event: TransactionEvent = {
51-
type: 'transaction',
52-
contexts: {
53-
trace: {
54-
span_id: '123',
55-
trace_id: 'abc',
56-
data: {},
57-
},
58-
},
59-
spans: [
60-
{
61-
description: 'sveltekit.resolve',
62-
data: {
63-
someAttribute: 'someValue',
64-
},
65-
span_id: '123',
66-
trace_id: 'abc',
67-
start_timestamp: 0,
68-
},
69-
],
70-
};
71-
72-
// @ts-expect-error -- passing in an empty option for client but it is unused in the integration
73-
svelteKitSpansIntegration().preprocessEvent?.(event, {}, {});
74-
75-
expect(event.spans).toHaveLength(1);
76-
expect(event.spans?.[0]?.op).toBeUndefined();
77-
expect(event.spans?.[0]?.origin).toBeUndefined();
78-
expect(event.spans?.[0]?.data[SEMANTIC_ATTRIBUTE_SENTRY_OP]).toBeUndefined();
79-
expect(event.spans?.[0]?.data[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]).toBeUndefined();
80-
});
81-
8249
describe('_enhanceKitSpan', () => {
8350
it.each([
8451
['sveltekit.resolve', 'function.sveltekit.resolve', 'auto.http.sveltekit'],

0 commit comments

Comments
 (0)