Skip to content

Commit c502b64

Browse files
authored
ref: Refactor some deprecated startSpan options (#10825)
Mostly, changes `origin` to be set as an attribute, plus some further small adjustments. In the case of bun, I also changed it to keep the request on the isolation scope (vs. the span).
1 parent 887fc9f commit c502b64

File tree

7 files changed

+88
-58
lines changed

7 files changed

+88
-58
lines changed

packages/bun/src/integrations/bunserver.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
startSpan,
1212
withIsolationScope,
1313
} from '@sentry/core';
14-
import type { IntegrationFn } from '@sentry/types';
14+
import type { IntegrationFn, SpanAttributes } from '@sentry/types';
1515
import { getSanitizedUrlString, parseUrl } from '@sentry/utils';
1616

1717
const INTEGRATION_NAME = 'BunServer';
@@ -53,45 +53,42 @@ export function instrumentBunServe(): void {
5353
function instrumentBunServeOptions(serveOptions: Parameters<typeof Bun.serve>[0]): void {
5454
serveOptions.fetch = new Proxy(serveOptions.fetch, {
5555
apply(fetchTarget, fetchThisArg, fetchArgs: Parameters<typeof serveOptions.fetch>) {
56-
return withIsolationScope(() => {
56+
return withIsolationScope(isolationScope => {
5757
const request = fetchArgs[0];
5858
const upperCaseMethod = request.method.toUpperCase();
5959
if (upperCaseMethod === 'OPTIONS' || upperCaseMethod === 'HEAD') {
6060
return fetchTarget.apply(fetchThisArg, fetchArgs);
6161
}
6262

6363
const parsedUrl = parseUrl(request.url);
64-
const data: Record<string, unknown> = {
64+
const attributes: SpanAttributes = {
65+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.bun.serve',
6566
'http.request.method': request.method || 'GET',
6667
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
6768
};
6869
if (parsedUrl.search) {
69-
data['http.query'] = parsedUrl.search;
70+
attributes['http.query'] = parsedUrl.search;
7071
}
7172

7273
const url = getSanitizedUrlString(parsedUrl);
7374

75+
isolationScope.setSDKProcessingMetadata({
76+
request: {
77+
url,
78+
method: request.method,
79+
headers: request.headers.toJSON(),
80+
},
81+
});
82+
7483
return continueTrace(
7584
{ sentryTrace: request.headers.get('sentry-trace') || '', baggage: request.headers.get('baggage') },
7685
ctx => {
7786
return startSpan(
7887
{
79-
attributes: {
80-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.bun.serve',
81-
},
88+
attributes,
8289
op: 'http.server',
8390
name: `${request.method} ${parsedUrl.path || '/'}`,
8491
...ctx,
85-
data,
86-
metadata: {
87-
// eslint-disable-next-line deprecation/deprecation
88-
...ctx.metadata,
89-
request: {
90-
url,
91-
method: request.method,
92-
headers: request.headers.toJSON(),
93-
},
94-
},
9592
},
9693
async span => {
9794
try {

packages/react/src/profiler.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { startInactiveSpan } from '@sentry/browser';
2-
import { spanToJSON, withActiveSpan } from '@sentry/core';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON, withActiveSpan } from '@sentry/core';
33
import type { Span } from '@sentry/types';
44
import { timestampInSeconds } from '@sentry/utils';
55
import hoistNonReactStatics from 'hoist-non-react-statics';
@@ -59,8 +59,10 @@ class Profiler extends React.Component<ProfilerProps> {
5959
name: `<${name}>`,
6060
onlyIfParent: true,
6161
op: REACT_MOUNT_OP,
62-
origin: 'auto.ui.react.profiler',
63-
attributes: { 'ui.component_name': name },
62+
attributes: {
63+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',
64+
'ui.component_name': name,
65+
},
6466
});
6567
}
6668

@@ -86,9 +88,9 @@ class Profiler extends React.Component<ProfilerProps> {
8688
name: `<${this.props.name}>`,
8789
onlyIfParent: true,
8890
op: REACT_UPDATE_OP,
89-
origin: 'auto.ui.react.profiler',
90-
startTimestamp: now,
91+
startTime: now,
9192
attributes: {
93+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',
9294
'ui.component_name': this.props.name,
9395
'ui.react.changed_props': changedProps,
9496
},
@@ -114,15 +116,17 @@ class Profiler extends React.Component<ProfilerProps> {
114116
const { name, includeRender = true } = this.props;
115117

116118
if (this._mountSpan && includeRender) {
117-
const startTimestamp = spanToJSON(this._mountSpan).timestamp;
119+
const startTime = spanToJSON(this._mountSpan).timestamp;
118120
withActiveSpan(this._mountSpan, () => {
119121
const renderSpan = startInactiveSpan({
120122
onlyIfParent: true,
121123
name: `<${name}>`,
122124
op: REACT_RENDER_OP,
123-
origin: 'auto.ui.react.profiler',
124-
startTimestamp,
125-
attributes: { 'ui.component_name': name },
125+
startTime,
126+
attributes: {
127+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',
128+
'ui.component_name': name,
129+
},
126130
});
127131
if (renderSpan) {
128132
// Have to cast to Span because the type of _mountSpan is Span | undefined
@@ -192,8 +196,10 @@ function useProfiler(
192196
name: `<${name}>`,
193197
onlyIfParent: true,
194198
op: REACT_MOUNT_OP,
195-
origin: 'auto.ui.react.profiler',
196-
attributes: { 'ui.component_name': name },
199+
attributes: {
200+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',
201+
'ui.component_name': name,
202+
},
197203
});
198204
});
199205

@@ -204,16 +210,18 @@ function useProfiler(
204210

205211
return (): void => {
206212
if (mountSpan && options.hasRenderSpan) {
207-
const startTimestamp = spanToJSON(mountSpan).timestamp;
213+
const startTime = spanToJSON(mountSpan).timestamp;
208214
const endTimestamp = timestampInSeconds();
209215

210216
const renderSpan = startInactiveSpan({
211217
name: `<${name}>`,
212218
onlyIfParent: true,
213219
op: REACT_RENDER_OP,
214-
origin: 'auto.ui.react.profiler',
215-
startTimestamp,
216-
attributes: { 'ui.component_name': name },
220+
startTime,
221+
attributes: {
222+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',
223+
'ui.component_name': name,
224+
},
217225
});
218226
if (renderSpan) {
219227
// Have to cast to Span because the type of _mountSpan is Span | undefined

packages/react/test/profiler.test.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ describe('withProfiler', () => {
7474
name: `<${UNKNOWN_COMPONENT}>`,
7575
onlyIfParent: true,
7676
op: REACT_MOUNT_OP,
77-
origin: 'auto.ui.react.profiler',
78-
attributes: { 'ui.component_name': 'unknown' },
77+
attributes: {
78+
'sentry.origin': 'auto.ui.react.profiler',
79+
'ui.component_name': 'unknown',
80+
},
7981
});
8082
});
8183
});
@@ -93,9 +95,11 @@ describe('withProfiler', () => {
9395
name: `<${UNKNOWN_COMPONENT}>`,
9496
onlyIfParent: true,
9597
op: REACT_RENDER_OP,
96-
origin: 'auto.ui.react.profiler',
97-
startTimestamp: undefined,
98-
attributes: { 'ui.component_name': 'unknown' },
98+
startTime: undefined,
99+
attributes: {
100+
'sentry.origin': 'auto.ui.react.profiler',
101+
'ui.component_name': 'unknown',
102+
},
99103
});
100104
expect(mockFinish).toHaveBeenCalledTimes(2);
101105
});
@@ -123,24 +127,30 @@ describe('withProfiler', () => {
123127
rerender(<ProfiledComponent num={1} />);
124128
expect(mockStartInactiveSpan).toHaveBeenCalledTimes(2);
125129
expect(mockStartInactiveSpan).toHaveBeenLastCalledWith({
126-
attributes: { 'ui.react.changed_props': ['num'], 'ui.component_name': 'unknown' },
130+
attributes: {
131+
'sentry.origin': 'auto.ui.react.profiler',
132+
'ui.react.changed_props': ['num'],
133+
'ui.component_name': 'unknown',
134+
},
127135
name: `<${UNKNOWN_COMPONENT}>`,
128136
onlyIfParent: true,
129137
op: REACT_UPDATE_OP,
130-
origin: 'auto.ui.react.profiler',
131-
startTimestamp: expect.any(Number),
138+
startTime: expect.any(Number),
132139
});
133140
expect(mockFinish).toHaveBeenCalledTimes(2);
134141
// New props yet again
135142
rerender(<ProfiledComponent num={2} />);
136143
expect(mockStartInactiveSpan).toHaveBeenCalledTimes(3);
137144
expect(mockStartInactiveSpan).toHaveBeenLastCalledWith({
138-
attributes: { 'ui.react.changed_props': ['num'], 'ui.component_name': 'unknown' },
145+
attributes: {
146+
'sentry.origin': 'auto.ui.react.profiler',
147+
'ui.react.changed_props': ['num'],
148+
'ui.component_name': 'unknown',
149+
},
139150
name: `<${UNKNOWN_COMPONENT}>`,
140151
onlyIfParent: true,
141152
op: REACT_UPDATE_OP,
142-
origin: 'auto.ui.react.profiler',
143-
startTimestamp: expect.any(Number),
153+
startTime: expect.any(Number),
144154
});
145155
expect(mockFinish).toHaveBeenCalledTimes(3);
146156

@@ -179,8 +189,10 @@ describe('useProfiler()', () => {
179189
name: '<Example>',
180190
onlyIfParent: true,
181191
op: REACT_MOUNT_OP,
182-
origin: 'auto.ui.react.profiler',
183-
attributes: { 'ui.component_name': 'Example' },
192+
attributes: {
193+
'ui.component_name': 'Example',
194+
'sentry.origin': 'auto.ui.react.profiler',
195+
},
184196
});
185197
});
186198
});
@@ -204,8 +216,10 @@ describe('useProfiler()', () => {
204216
name: '<Example>',
205217
onlyIfParent: true,
206218
op: REACT_RENDER_OP,
207-
origin: 'auto.ui.react.profiler',
208-
attributes: { 'ui.component_name': 'Example' },
219+
attributes: {
220+
'sentry.origin': 'auto.ui.react.profiler',
221+
'ui.component_name': 'Example',
222+
},
209223
}),
210224
);
211225
});

packages/remix/src/client/performance.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getActiveSpan, getRootSpan } from '@sentry/core';
1+
import {
2+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
3+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
4+
getActiveSpan,
5+
getRootSpan,
6+
} from '@sentry/core';
27
import type { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/react';
38
import type { BrowserClient, ErrorBoundaryProps } from '@sentry/react';
49
import {
@@ -72,8 +77,8 @@ export function startPageloadSpan(): void {
7277
const spanContext: StartSpanOptions = {
7378
name: initPathName,
7479
op: 'pageload',
75-
origin: 'auto.pageload.remix',
7680
attributes: {
81+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.remix',
7782
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
7883
},
7984
};
@@ -96,8 +101,8 @@ function startNavigationSpan(matches: RouteMatch<string>[]): void {
96101
const spanContext: StartSpanOptions = {
97102
name: matches[matches.length - 1].id,
98103
op: 'navigation',
99-
origin: 'auto.navigation.remix',
100104
attributes: {
105+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.remix',
101106
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
102107
},
103108
};

packages/tracing-internal/src/browser/browserTracingIntegration.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { IdleTransaction } from '@sentry/core';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
23
import { getActiveSpan } from '@sentry/core';
34
import { getCurrentHub } from '@sentry/core';
45
import {
@@ -232,7 +233,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
232233
};
233234
}
234235

235-
const finalContext = beforeStartSpan ? beforeStartSpan(expandedContext) : expandedContext;
236+
const finalContext: TransactionContext = beforeStartSpan ? beforeStartSpan(expandedContext) : expandedContext;
236237

237238
// If `beforeStartSpan` set a custom name, record that fact
238239
finalContext.attributes =
@@ -323,10 +324,10 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
323324
const context: StartSpanOptions = {
324325
name: WINDOW.location.pathname,
325326
// pageload should always start at timeOrigin (and needs to be in s, not ms)
326-
startTimestamp: browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined,
327-
origin: 'auto.pageload.browser',
327+
startTime: browserPerformanceTimeOrigin ? browserPerformanceTimeOrigin / 1000 : undefined,
328328
attributes: {
329329
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
330+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.browser',
330331
},
331332
};
332333
startBrowserTracingPageLoadSpan(client, context);
@@ -352,9 +353,9 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
352353
startingUrl = undefined;
353354
const context: StartSpanOptions = {
354355
name: WINDOW.location.pathname,
355-
origin: 'auto.navigation.browser',
356356
attributes: {
357357
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
358+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.browser',
358359
},
359360
};
360361

packages/tracing-internal/src/node/integrations/prisma.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ export class Prisma implements Integration {
101101
op: 'db.prisma',
102102
attributes: {
103103
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.prisma',
104+
...clientData,
105+
'db.operation': action,
104106
},
105-
data: { ...clientData, 'db.operation': action },
106107
},
107108
() => next(params),
108109
);

packages/vue/src/tracing.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getActiveSpan, startInactiveSpan } from '@sentry/browser';
1+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getActiveSpan, startInactiveSpan } from '@sentry/browser';
22
import type { Span } from '@sentry/types';
33
import { logger, timestampInSeconds } from '@sentry/utils';
44

@@ -75,7 +75,9 @@ export const createTracingMixins = (options: TracingOptions): Mixins => {
7575
startInactiveSpan({
7676
name: 'Application Render',
7777
op: `${VUE_OP}.render`,
78-
origin: 'auto.ui.vue',
78+
attributes: {
79+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.vue',
80+
},
7981
});
8082
}
8183
}
@@ -109,7 +111,9 @@ export const createTracingMixins = (options: TracingOptions): Mixins => {
109111
this.$_sentrySpans[operation] = startInactiveSpan({
110112
name: `Vue <${name}>`,
111113
op: `${VUE_OP}.${operation}`,
112-
origin: 'auto.ui.vue',
114+
attributes: {
115+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.vue',
116+
},
113117
});
114118
}
115119
} else {

0 commit comments

Comments
 (0)