Skip to content

Commit 60289ec

Browse files
committed
ref: refactor some start span options
1 parent e1063f4 commit 60289ec

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
@@ -76,8 +76,10 @@ describe('withProfiler', () => {
7676
name: `<${UNKNOWN_COMPONENT}>`,
7777
onlyIfParent: true,
7878
op: REACT_MOUNT_OP,
79-
origin: 'auto.ui.react.profiler',
80-
attributes: { 'ui.component_name': 'unknown' },
79+
attributes: {
80+
'sentry.origin': 'auto.ui.react.profiler',
81+
'ui.component_name': 'unknown',
82+
},
8183
});
8284
});
8385
});
@@ -95,9 +97,11 @@ describe('withProfiler', () => {
9597
name: `<${UNKNOWN_COMPONENT}>`,
9698
onlyIfParent: true,
9799
op: REACT_RENDER_OP,
98-
origin: 'auto.ui.react.profiler',
99-
startTimestamp: undefined,
100-
attributes: { 'ui.component_name': 'unknown' },
100+
startTime: undefined,
101+
attributes: {
102+
'sentry.origin': 'auto.ui.react.profiler',
103+
'ui.component_name': 'unknown',
104+
},
101105
});
102106
expect(mockFinish).toHaveBeenCalledTimes(2);
103107
});
@@ -125,24 +129,30 @@ describe('withProfiler', () => {
125129
rerender(<ProfiledComponent num={1} />);
126130
expect(mockStartInactiveSpan).toHaveBeenCalledTimes(2);
127131
expect(mockStartInactiveSpan).toHaveBeenLastCalledWith({
128-
attributes: { 'ui.react.changed_props': ['num'], 'ui.component_name': 'unknown' },
132+
attributes: {
133+
'sentry.origin': 'auto.ui.react.profiler',
134+
'ui.react.changed_props': ['num'],
135+
'ui.component_name': 'unknown',
136+
},
129137
name: `<${UNKNOWN_COMPONENT}>`,
130138
onlyIfParent: true,
131139
op: REACT_UPDATE_OP,
132-
origin: 'auto.ui.react.profiler',
133-
startTimestamp: expect.any(Number),
140+
startTime: expect.any(Number),
134141
});
135142
expect(mockFinish).toHaveBeenCalledTimes(2);
136143
// New props yet again
137144
rerender(<ProfiledComponent num={2} />);
138145
expect(mockStartInactiveSpan).toHaveBeenCalledTimes(3);
139146
expect(mockStartInactiveSpan).toHaveBeenLastCalledWith({
140-
attributes: { 'ui.react.changed_props': ['num'], 'ui.component_name': 'unknown' },
147+
attributes: {
148+
'sentry.origin': 'auto.ui.react.profiler',
149+
'ui.react.changed_props': ['num'],
150+
'ui.component_name': 'unknown',
151+
},
141152
name: `<${UNKNOWN_COMPONENT}>`,
142153
onlyIfParent: true,
143154
op: REACT_UPDATE_OP,
144-
origin: 'auto.ui.react.profiler',
145-
startTimestamp: expect.any(Number),
155+
startTime: expect.any(Number),
146156
});
147157
expect(mockFinish).toHaveBeenCalledTimes(3);
148158

@@ -181,8 +191,10 @@ describe('useProfiler()', () => {
181191
name: '<Example>',
182192
onlyIfParent: true,
183193
op: REACT_MOUNT_OP,
184-
origin: 'auto.ui.react.profiler',
185-
attributes: { 'ui.component_name': 'Example' },
194+
attributes: {
195+
'ui.component_name': 'Example',
196+
'sentry.origin': 'auto.ui.react.profiler',
197+
},
186198
});
187199
});
188200
});
@@ -206,8 +218,10 @@ describe('useProfiler()', () => {
206218
name: '<Example>',
207219
onlyIfParent: true,
208220
op: REACT_RENDER_OP,
209-
origin: 'auto.ui.react.profiler',
210-
attributes: { 'ui.component_name': 'Example' },
221+
attributes: {
222+
'sentry.origin': 'auto.ui.react.profiler',
223+
'ui.component_name': 'Example',
224+
},
211225
}),
212226
);
213227
});

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)