Skip to content

Commit 64437ed

Browse files
committed
s/_sentry_span_name_set_by_user/SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME
1 parent 99dc49a commit 64437ed

File tree

9 files changed

+50
-35
lines changed

9 files changed

+50
-35
lines changed

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/pageload-update-txn-name/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@playwright/test';
2-
import type { Event } from '@sentry/core';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, type Event } from '@sentry/core';
33

44
import {
55
SEMANTIC_ATTRIBUTE_SENTRY_OP,
@@ -34,7 +34,7 @@ sentryTest(
3434
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
3535
});
3636

37-
expect(traceContextData!._sentry_span_name_set_by_user).toBeUndefined();
37+
expect(traceContextData![SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]).toBeUndefined();
3838

3939
expect(eventData.contexts?.trace?.op).toBe('pageload');
4040
expect(eventData.spans?.length).toBeGreaterThan(0);

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/pageload-updateSpanName/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@playwright/test';
2-
import type { Event } from '@sentry/core';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, type Event } from '@sentry/core';
33

44
import {
55
SEMANTIC_ATTRIBUTE_SENTRY_OP,
@@ -32,7 +32,7 @@ sentryTest(
3232
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
3333
});
3434

35-
expect(traceContextData!._sentry_span_name_set_by_user).toBeUndefined();
35+
expect(traceContextData![SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]).toBeUndefined();
3636

3737
expect(eventData.transaction).toBe('new name');
3838

dev-packages/node-integration-tests/suites/express/tracing/updateName/test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/node';
22
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
3+
import { SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME } from '@sentry/core';
34

45
describe('express tracing', () => {
56
afterAll(() => {
@@ -58,7 +59,7 @@ describe('express tracing', () => {
5859
},
5960
});
6061
// ensure we delete the internal attribute once we're done with it
61-
expect(txnEvent.contexts?.trace?.data?.['_sentry_span_name_set_by_user']).toBeUndefined();
62+
expect(txnEvent.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]).toBeUndefined();
6263
},
6364
})
6465
.start(done)
@@ -84,7 +85,7 @@ describe('express tracing', () => {
8485
},
8586
});
8687
// ensure we delete the internal attribute once we're done with it
87-
expect(txnEvent.contexts?.trace?.data?.['_sentry_span_name_set_by_user']).toBeUndefined();
88+
expect(txnEvent.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]).toBeUndefined();
8889
},
8990
})
9091
.start(done)

dev-packages/rollup-utils/plugins/bundlePlugins.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ export function makeTerserPlugin() {
140140
'_isShim',
141141
// This is used in metadata integration
142142
'_sentryModuleMetadata',
143-
// _sentry_span_name_set_by_user is set by the user and is used to store the original span name
144-
'_sentry_span_name_set_by_user',
145143
],
146144
},
147145
},

packages/core/src/envelope.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME } from './semanticAttributes';
12
import { getDynamicSamplingContextFromSpan } from './tracing/dynamicSamplingContext';
23
import type { SentrySpan } from './tracing/sentrySpan';
34
import type {
@@ -97,9 +98,11 @@ export function createEventEnvelope(
9798
delete event.sdkProcessingMetadata;
9899
try {
99100
// @ts-expect-error - for bundle size we try/catch the access to this property
100-
delete event.contexts.trace.data._sentry_span_name_set_by_user;
101+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
102+
delete event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
101103
// @ts-expect-error - for bundle size we try/catch the access to this property
102-
event.spans.forEach(span => delete span.data._sentry_span_name_set_by_user);
104+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
105+
event.spans.forEach(span => delete span.data[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]);
103106
} catch {
104107
// Do nothing
105108
}

packages/core/src/semanticAttributes.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ export const SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT = 'sentry.measurement_un
2929
/** The value of a measurement, which may be stored as a TimedEvent. */
3030
export const SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE = 'sentry.measurement_value';
3131

32+
/**
33+
* A custom span name set by users guaranteed to be taken over any automatically
34+
* inferred name. This attribute is removed before the span is sent.
35+
*
36+
* @internal only meant for internal SDK usage
37+
* @hidden
38+
*/
39+
export const SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME = 'sentry.custom_span_name';
40+
3241
/**
3342
* The id of the profile that this span occurred in.
3443
*/

packages/core/src/utils/spanUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getCurrentScope } from '../currentScopes';
44
import { getMetricSummaryJsonForSpan, updateMetricSummaryOnSpan } from '../metrics/metric-summary';
55
import type { MetricType } from '../metrics/types';
66
import {
7+
SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,
78
SEMANTIC_ATTRIBUTE_SENTRY_OP,
89
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
910
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
@@ -335,6 +336,6 @@ export function updateSpanName(span: Span, name: string): void {
335336
span.updateName(name);
336337
span.setAttributes({
337338
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
338-
['_sentry_span_name_set_by_user']: name,
339+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: name,
339340
});
340341
}

packages/opentelemetry/src/utils/parseSpanDescription.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '@opentelemetry/semantic-conventions';
1616
import type { SpanAttributes, TransactionSource } from '@sentry/core';
1717
import {
18+
SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,
1819
SEMANTIC_ATTRIBUTE_SENTRY_OP,
1920
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
2021
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
@@ -115,10 +116,11 @@ export function parseSpanDescription(span: AbstractSpan): SpanDescription {
115116

116117
function descriptionForDbSystem({ attributes, name }: { attributes: Attributes; name: string }): SpanDescription {
117118
// if we already have a custom name, we don't overwrite it but only set the op
118-
if (typeof attributes['_sentry_span_name_set_by_user'] === 'string') {
119+
const userDefinedName = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
120+
if (typeof userDefinedName === 'string') {
119121
return {
120122
op: 'db',
121-
description: attributes['_sentry_span_name_set_by_user'],
123+
description: userDefinedName,
122124
source: (attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionSource) || 'custom',
123125
};
124126
}
@@ -202,11 +204,10 @@ export function descriptionForHttpMethod(
202204

203205
// If users (or in very rare occasions we) set the source to custom, we don't overwrite the name
204206
const alreadyHasCustomSource = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === 'custom';
207+
const customSpanName = attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
205208

206209
const useInferredDescription =
207-
!alreadyHasCustomSource &&
208-
attributes['_sentry_span_name_set_by_user'] == null &&
209-
(isClientOrServerKind || !isManualSpan);
210+
!alreadyHasCustomSource && customSpanName == null && (isClientOrServerKind || !isManualSpan);
210211

211212
const { description, source } = useInferredDescription
212213
? { description: inferredDescription, source: inferredSource }
@@ -302,12 +303,14 @@ export function getUserUpdatedNameAndSource(
302303
source: TransactionSource;
303304
} {
304305
const source = (attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionSource) || fallbackSource;
306+
const description = attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
305307

306-
if (attributes['_sentry_span_name_set_by_user'] && typeof attributes['_sentry_span_name_set_by_user'] === 'string')
308+
if (description && typeof description === 'string') {
307309
return {
308-
description: attributes['_sentry_span_name_set_by_user'],
310+
description,
309311
source,
310312
};
313+
}
311314

312315
return { description: originalName, source };
313316
}

packages/opentelemetry/test/utils/parseSpanDescription.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
SEMATTRS_RPC_SERVICE,
1616
} from '@opentelemetry/semantic-conventions';
1717

18-
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
18+
import { SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
1919
import {
2020
descriptionForHttpMethod,
2121
getSanitizedUrl,
@@ -108,7 +108,7 @@ describe('parseSpanDescription', () => {
108108
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
109109
[SEMATTRS_DB_SYSTEM]: 'mysql',
110110
[SEMATTRS_DB_STATEMENT]: 'SELECT * from users',
111-
['_sentry_span_name_set_by_user']: 'custom name',
111+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
112112
},
113113
'test name',
114114
SpanKind.CLIENT,
@@ -124,7 +124,7 @@ describe('parseSpanDescription', () => {
124124
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
125125
[SEMATTRS_DB_SYSTEM]: 'mysql',
126126
[SEMATTRS_DB_STATEMENT]: 'SELECT * from users',
127-
['_sentry_span_name_set_by_user']: 'custom name',
127+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
128128
},
129129
'test name',
130130
SpanKind.CLIENT,
@@ -179,7 +179,7 @@ describe('parseSpanDescription', () => {
179179
{
180180
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
181181
[SEMATTRS_RPC_SERVICE]: 'rpc-test-service',
182-
['_sentry_span_name_set_by_user']: 'custom name',
182+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
183183
},
184184
'test name',
185185
undefined,
@@ -194,7 +194,7 @@ describe('parseSpanDescription', () => {
194194
{
195195
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
196196
[SEMATTRS_RPC_SERVICE]: 'rpc-test-service',
197-
['_sentry_span_name_set_by_user']: 'custom name',
197+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
198198
},
199199
'test name',
200200
undefined,
@@ -236,7 +236,7 @@ describe('parseSpanDescription', () => {
236236
{
237237
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
238238
[SEMATTRS_MESSAGING_SYSTEM]: 'test-messaging-system',
239-
['_sentry_span_name_set_by_user']: 'custom name',
239+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
240240
},
241241
'test name',
242242
undefined,
@@ -251,7 +251,7 @@ describe('parseSpanDescription', () => {
251251
{
252252
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
253253
[SEMATTRS_MESSAGING_SYSTEM]: 'test-messaging-system',
254-
['_sentry_span_name_set_by_user']: 'custom name',
254+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
255255
},
256256
'test name',
257257
undefined,
@@ -293,7 +293,7 @@ describe('parseSpanDescription', () => {
293293
{
294294
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
295295
[SEMATTRS_FAAS_TRIGGER]: 'test-faas-trigger',
296-
['_sentry_span_name_set_by_user']: 'custom name',
296+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
297297
},
298298
'test name',
299299
undefined,
@@ -308,7 +308,7 @@ describe('parseSpanDescription', () => {
308308
{
309309
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
310310
[SEMATTRS_FAAS_TRIGGER]: 'test-faas-trigger',
311-
['_sentry_span_name_set_by_user']: 'custom name',
311+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
312312
},
313313
'test name',
314314
undefined,
@@ -465,7 +465,7 @@ describe('descriptionForHttpMethod', () => {
465465
[SEMATTRS_HTTP_TARGET]: '/my-path/123',
466466
[ATTR_HTTP_ROUTE]: '/my-path/:id',
467467
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom',
468-
['_sentry_span_name_set_by_user']: 'custom name',
468+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
469469
},
470470
'test name',
471471
SpanKind.CLIENT,
@@ -487,7 +487,7 @@ describe('descriptionForHttpMethod', () => {
487487
[SEMATTRS_HTTP_TARGET]: '/my-path/123',
488488
[ATTR_HTTP_ROUTE]: '/my-path/:id',
489489
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
490-
['_sentry_span_name_set_by_user']: 'custom name',
490+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
491491
},
492492
'test name',
493493
SpanKind.CLIENT,
@@ -655,30 +655,30 @@ describe('getSanitizedUrl', () => {
655655
});
656656

657657
describe('getUserUpdatedNameAndSource', () => {
658-
it('returns param name if `_sentry_span_name_set_by_user` attribute is not set', () => {
658+
it('returns param name if `SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME` attribute is not set', () => {
659659
expect(getUserUpdatedNameAndSource('base name', {})).toEqual({ description: 'base name', source: 'custom' });
660660
});
661661

662-
it('returns param name with custom fallback source if `_sentry_span_name_set_by_user` attribute is not set', () => {
662+
it('returns param name with custom fallback source if `SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME` attribute is not set', () => {
663663
expect(getUserUpdatedNameAndSource('base name', {}, 'route')).toEqual({
664664
description: 'base name',
665665
source: 'route',
666666
});
667667
});
668668

669-
it('returns param name if `_sentry_span_name_set_by_user` attribute is not a string', () => {
670-
expect(getUserUpdatedNameAndSource('base name', { ['_sentry_span_name_set_by_user']: 123 })).toEqual({
669+
it('returns param name if `SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME` attribute is not a string', () => {
670+
expect(getUserUpdatedNameAndSource('base name', { [SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 123 })).toEqual({
671671
description: 'base name',
672672
source: 'custom',
673673
});
674674
});
675675

676676
it.each(['custom', 'task', 'url', 'route'])(
677-
'returns `_sentry_span_name_set_by_user` attribute if is a string and source is %s',
677+
'returns `SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME` attribute if is a string and source is %s',
678678
source => {
679679
expect(
680680
getUserUpdatedNameAndSource('base name', {
681-
['_sentry_span_name_set_by_user']: 'custom name',
681+
[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'custom name',
682682
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
683683
}),
684684
).toEqual({

0 commit comments

Comments
 (0)