Skip to content

Commit bb03a7e

Browse files
committed
feat(core): Deprecate span name and description
Instead, users should use `spanGetName(span)`.
1 parent 5462b04 commit bb03a7e

File tree

29 files changed

+235
-187
lines changed

29 files changed

+235
-187
lines changed

dev-packages/browser-integration-tests/suites/public-api/startSpan/basic/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ sentryTest('should report finished spans as children of the root transaction', a
2929
expect(transaction.spans).toHaveLength(1);
3030

3131
const span_1 = transaction.spans?.[0];
32+
// eslint-disable-next-line deprecation/deprecation
3233
expect(span_1?.description).toBe('child_span');
3334
expect(span_1?.parentSpanId).toEqual(rootSpanId);
3435
});

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-fid/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ sentryTest('should capture a FID vital.', async ({ browserName, getLocalTestPath
2121
expect(eventData.measurements).toBeDefined();
2222
expect(eventData.measurements?.fid?.value).toBeDefined();
2323

24+
// eslint-disable-next-line deprecation/deprecation
2425
const fidSpan = eventData.spans?.filter(({ description }) => description === 'first input delay')[0];
2526

2627
expect(fidSpan).toBeDefined();

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-fp-fcp/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ sentryTest('should capture FP vital.', async ({ browserName, getLocalTestPath, p
1616
expect(eventData.measurements).toBeDefined();
1717
expect(eventData.measurements?.fp?.value).toBeDefined();
1818

19+
// eslint-disable-next-line deprecation/deprecation
1920
const fpSpan = eventData.spans?.filter(({ description }) => description === 'first-paint')[0];
2021

2122
expect(fpSpan).toBeDefined();
@@ -34,6 +35,7 @@ sentryTest('should capture FCP vital.', async ({ getLocalTestPath, page }) => {
3435
expect(eventData.measurements).toBeDefined();
3536
expect(eventData.measurements?.fcp?.value).toBeDefined();
3637

38+
// eslint-disable-next-line deprecation/deprecation
3739
const fcpSpan = eventData.spans?.filter(({ description }) => description === 'first-contentful-paint')[0];
3840

3941
expect(fcpSpan).toBeDefined();

packages/browser/src/profiling/hubextensions.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable complexity */
2+
import { spanGetName } from '@sentry/core';
23
import type { Transaction } from '@sentry/types';
34
import { logger, timestampInSeconds, uuid4 } from '@sentry/utils';
45

@@ -56,7 +57,7 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
5657
}
5758

5859
if (DEBUG_BUILD) {
59-
logger.log(`[Profiling] started profiling transaction: ${transaction.name || transaction.description}`);
60+
logger.log(`[Profiling] started profiling transaction: ${spanGetName(transaction)}`);
6061
}
6162

6263
// We create "unique" transaction names to avoid concurrent transactions with same names
@@ -87,11 +88,7 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
8788
}
8889
if (processedProfile) {
8990
if (DEBUG_BUILD) {
90-
logger.log(
91-
'[Profiling] profile for:',
92-
transaction.name || transaction.description,
93-
'already exists, returning early',
94-
);
91+
logger.log('[Profiling] profile for:', spanGetName(transaction), 'already exists, returning early');
9592
}
9693
return null;
9794
}
@@ -105,14 +102,14 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
105102
}
106103

107104
if (DEBUG_BUILD) {
108-
logger.log(`[Profiling] stopped profiling of transaction: ${transaction.name || transaction.description}`);
105+
logger.log(`[Profiling] stopped profiling of transaction: ${spanGetName(transaction)}`);
109106
}
110107

111108
// In case of an overlapping transaction, stopProfiling may return null and silently ignore the overlapping profile.
112109
if (!profile) {
113110
if (DEBUG_BUILD) {
114111
logger.log(
115-
`[Profiling] profiler returned null profile for: ${transaction.name || transaction.description}`,
112+
`[Profiling] profiler returned null profile for: ${spanGetName(transaction)}`,
116113
'this may indicate an overlapping transaction or a call to stopProfiling with a profile title that was never started',
117114
);
118115
}
@@ -133,10 +130,7 @@ export function startProfileForTransaction(transaction: Transaction): Transactio
133130
// Enqueue a timeout to prevent profiles from running over max duration.
134131
let maxDurationTimeoutID: number | undefined = WINDOW.setTimeout(() => {
135132
if (DEBUG_BUILD) {
136-
logger.log(
137-
'[Profiling] max profile duration elapsed, stopping profiling for:',
138-
transaction.name || transaction.description,
139-
);
133+
logger.log('[Profiling] max profile duration elapsed, stopping profiling for:', spanGetName(transaction));
140134
}
141135
// If the timeout exceeds, we want to stop profiling, but not finish the transaction
142136
// eslint-disable-next-line @typescript-eslint/no-floating-promises

packages/bun/test/integrations/bunserver.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeAll, beforeEach, describe, expect, test } from 'bun:test';
2-
import { Hub, makeMain } from '@sentry/core';
2+
import { Hub, makeMain, spanGetName } from '@sentry/core';
33

44
import { BunClient } from '../../src/client';
55
import { instrumentBunServe } from '../../src/integrations/bunserver';
@@ -30,7 +30,7 @@ describe('Bun Serve Integration', () => {
3030
'http.status_code': '200',
3131
});
3232
expect(transaction.op).toEqual('http.server');
33-
expect(transaction.name).toEqual('GET /');
33+
expect(spanGetName(transaction)).toEqual('GET /');
3434
});
3535

3636
const server = Bun.serve({
@@ -52,7 +52,7 @@ describe('Bun Serve Integration', () => {
5252
'http.status_code': '200',
5353
});
5454
expect(transaction.op).toEqual('http.server');
55-
expect(transaction.name).toEqual('POST /');
55+
expect(spanGetName(transaction)).toEqual('POST /');
5656
});
5757

5858
const server = Bun.serve({

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export { createCheckInEnvelope } from './checkin';
7171
export { hasTracingEnabled } from './utils/hasTracingEnabled';
7272
export { isSentryRequestUrl } from './utils/isSentryRequestUrl';
7373
export { handleCallbackErrors } from './utils/handleCallbackErrors';
74-
export { spanToTraceHeader } from './utils/spanUtils';
74+
export { spanToTraceHeader, spanGetName } from './utils/spanUtils';
7575
export { DEFAULT_ENVIRONMENT } from './constants';
7676
export { ModuleMetadata } from './integrations/metadata';
7777
export { RequestData } from './integrations/requestdata';

packages/core/src/integrations/requestdata.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Client, IntegrationFn, Transaction } from '@sentry/types';
22
import type { AddRequestDataToEventOptions, TransactionNamingScheme } from '@sentry/utils';
33
import { addRequestDataToEvent, extractPathForTransaction } from '@sentry/utils';
44
import { convertIntegrationFnToClass } from '../integration';
5+
import { spanGetName } from '../utils/spanUtils';
56

67
export type RequestDataIntegrationOptions = {
78
/**
@@ -105,18 +106,20 @@ const requestDataIntegration: IntegrationFn = (options: RequestDataIntegrationOp
105106
const reqWithTransaction = req as { _sentryTransaction?: Transaction };
106107
const transaction = reqWithTransaction._sentryTransaction;
107108
if (transaction) {
109+
const name = spanGetName(transaction);
110+
108111
// TODO (v8): Remove the nextjs check and just base it on `transactionNamingScheme` for all SDKs. (We have to
109112
// keep it the way it is for the moment, because changing the names of transactions in Sentry has the potential
110113
// to break things like alert rules.)
111114
const shouldIncludeMethodInTransactionName =
112115
getSDKName(client) === 'sentry.javascript.nextjs'
113-
? transaction.name.startsWith('/api')
116+
? name.startsWith('/api')
114117
: transactionNamingScheme !== 'path';
115118

116119
const [transactionValue] = extractPathForTransaction(req, {
117120
path: true,
118121
method: shouldIncludeMethodInTransactionName,
119-
customRoute: transaction.name,
122+
customRoute: name,
120123
});
121124

122125
processedEvent.transaction = transactionValue;

packages/core/src/metrics/exports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { logger } from '@sentry/utils';
33
import type { BaseClient } from '../baseclient';
44
import { DEBUG_BUILD } from '../debug-build';
55
import { getClient, getCurrentScope } from '../exports';
6+
import { spanGetName } from '../utils/spanUtils';
67
import { COUNTER_METRIC_TYPE, DISTRIBUTION_METRIC_TYPE, GAUGE_METRIC_TYPE, SET_METRIC_TYPE } from './constants';
78
import { MetricsAggregator } from './integration';
89
import type { MetricType } from './types';
@@ -38,7 +39,7 @@ function addToMetricsAggregator(
3839
metricTags.environment = environment;
3940
}
4041
if (transaction) {
41-
metricTags.transaction = transaction.name;
42+
metricTags.transaction = spanGetName(transaction);
4243
}
4344

4445
DEBUG_BUILD && logger.log(`Adding value of ${value} to ${metricType} metric ${name}`);

packages/core/src/tracing/sampling.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isNaN, logger } from '@sentry/utils';
33

44
import { DEBUG_BUILD } from '../debug-build';
55
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
6+
import { spanGetName } from '../utils/spanUtils';
67
import type { Transaction } from './transaction';
78

89
/**
@@ -93,7 +94,7 @@ export function sampleTransaction<T extends Transaction>(
9394
return transaction;
9495
}
9596

96-
DEBUG_BUILD && logger.log(`[Tracing] starting ${transaction.op} transaction - ${transaction.name}`);
97+
DEBUG_BUILD && logger.log(`[Tracing] starting ${transaction.op} transaction - ${spanGetName(transaction)}`);
9798
return transaction;
9899
}
99100

packages/core/src/tracing/span.ts

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
import { dropUndefinedKeys, logger, timestampInSeconds, uuid4 } from '@sentry/utils';
1414

1515
import { DEBUG_BUILD } from '../debug-build';
16-
import { spanToTraceContext, spanToTraceHeader } from '../utils/spanUtils';
16+
import { spanGetName, spanToTraceContext, spanToTraceHeader } from '../utils/spanUtils';
1717
import { ensureTimestampInSeconds } from './utils';
1818

1919
/**
@@ -91,11 +91,6 @@ export class Span implements SpanInterface {
9191
*/
9292
public op?: string;
9393

94-
/**
95-
* @inheritDoc
96-
*/
97-
public description?: string;
98-
9994
/**
10095
* @inheritDoc
10196
*/
@@ -132,6 +127,8 @@ export class Span implements SpanInterface {
132127
*/
133128
public origin?: SpanOrigin;
134129

130+
protected _name?: string;
131+
135132
/**
136133
* You should never call the constructor manually, always use `Sentry.startTransaction()`
137134
* or call `startChild()` on an existing span.
@@ -148,6 +145,8 @@ export class Span implements SpanInterface {
148145
this.attributes = spanContext.attributes || {};
149146
this.instrumenter = spanContext.instrumenter || 'sentry';
150147
this.origin = spanContext.origin || 'manual';
148+
// eslint-disable-next-line deprecation/deprecation
149+
this._name = spanContext.name || spanContext.description;
151150

152151
if (spanContext.parentSpanId) {
153152
this.parentSpanId = spanContext.parentSpanId;
@@ -159,12 +158,6 @@ export class Span implements SpanInterface {
159158
if (spanContext.op) {
160159
this.op = spanContext.op;
161160
}
162-
if (spanContext.description) {
163-
this.description = spanContext.description;
164-
}
165-
if (spanContext.name) {
166-
this.description = spanContext.name;
167-
}
168161
if (spanContext.status) {
169162
this.status = spanContext.status;
170163
}
@@ -173,8 +166,15 @@ export class Span implements SpanInterface {
173166
}
174167
}
175168

176-
/** An alias for `description` of the Span. */
169+
// This rule conflicts with another rule :()
170+
/* eslint-disable @typescript-eslint/member-ordering */
171+
172+
/**
173+
* An alias for `description` of the Span.
174+
* @deprecated Use `spanGetName(span)` instead.
175+
*/
177176
public get name(): string {
177+
// eslint-disable-next-line deprecation/deprecation
178178
return this.description || '';
179179
}
180180
/**
@@ -184,6 +184,24 @@ export class Span implements SpanInterface {
184184
this.updateName(name);
185185
}
186186

187+
/**
188+
* Get the description of the Span.
189+
* @deprecated Use `spanGetName(span)` instead.
190+
*/
191+
public get description(): string | undefined {
192+
return this._name;
193+
}
194+
195+
/**
196+
* Get the description of the Span.
197+
* @deprecated Use `spanGetName(span)` instead.
198+
*/
199+
public set description(description: string | undefined) {
200+
this._name = description;
201+
}
202+
203+
/* eslint-enable @typescript-eslint/member-ordering */
204+
187205
/**
188206
* @inheritDoc
189207
*/
@@ -206,7 +224,7 @@ export class Span implements SpanInterface {
206224

207225
if (DEBUG_BUILD && childSpan.transaction) {
208226
const opStr = (spanContext && spanContext.op) || '< unknown op >';
209-
const nameStr = childSpan.transaction.name || '< unknown name >';
227+
const nameStr = spanGetName(childSpan) || '< unknown name >';
210228
const idStr = childSpan.transaction.spanId;
211229

212230
const logMessage = `[Tracing] Starting '${opStr}' span on transaction '${nameStr}' (${idStr}).`;
@@ -279,7 +297,7 @@ export class Span implements SpanInterface {
279297
* @inheritDoc
280298
*/
281299
public updateName(name: string): this {
282-
this.description = name;
300+
this._name = name;
283301
return this;
284302
}
285303

@@ -330,7 +348,7 @@ export class Span implements SpanInterface {
330348
public toContext(): SpanContext {
331349
return dropUndefinedKeys({
332350
data: this._getData(),
333-
description: this.description,
351+
description: this._name,
334352
endTimestamp: this.endTimestamp,
335353
op: this.op,
336354
parentSpanId: this.parentSpanId,
@@ -348,7 +366,8 @@ export class Span implements SpanInterface {
348366
*/
349367
public updateWithContext(spanContext: SpanContext): this {
350368
this.data = spanContext.data || {};
351-
this.description = spanContext.description;
369+
// eslint-disable-next-line deprecation/deprecation
370+
this._name = spanContext.name || spanContext.description;
352371
this.endTimestamp = spanContext.endTimestamp;
353372
this.op = spanContext.op;
354373
this.parentSpanId = spanContext.parentSpanId;
@@ -388,7 +407,7 @@ export class Span implements SpanInterface {
388407
} {
389408
return dropUndefinedKeys({
390409
data: this._getData(),
391-
description: this.description,
410+
description: this._name,
392411
op: this.op,
393412
parent_span_id: this.parentSpanId,
394413
span_id: this.spanId,

0 commit comments

Comments
 (0)