Skip to content

Commit 548d455

Browse files
authored
feat(core): Deprecate span.startChild() (#10091)
We still have quite a lot of these ourselves, but we can refactor them over time during the v8 preparation. But with this, I think we have the most important deprecations mostly done!
1 parent 5aac890 commit 548d455

File tree

39 files changed

+147
-67
lines changed

39 files changed

+147
-67
lines changed

MIGRATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ npx @sentry/migr8@latest
88

99
This will let you select which updates to run, and automatically update your code. Make sure to still review all code changes!
1010

11-
## Deprecate `startTransaction()`
11+
## Deprecate `startTransaction()` & `span.startChild()`
1212

13-
In v8, the old performance API `startTransaction()` (as well as `hub.startTransaction()`) will be removed.
13+
In v8, the old performance API `startTransaction()` (and `hub.startTransaction()`), as well as `span.startChild()`, will be removed.
1414
Instead, use the new performance APIs:
1515

1616
* `startSpan()`

dev-packages/e2e-tests/test-applications/create-next-app/pages/api/success.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
77
const transaction = Sentry.startTransaction({ name: 'test-transaction', op: 'e2e-test' });
88
Sentry.getCurrentHub().getScope().setSpan(transaction);
99

10+
// eslint-disable-next-line deprecation/deprecation
1011
const span = transaction.startChild();
1112

1213
span.end();

dev-packages/e2e-tests/test-applications/node-express-app/src/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ app.get('/test-transaction', async function (req, res) {
3838
const transaction = Sentry.startTransaction({ name: 'test-transaction', op: 'e2e-test' });
3939
Sentry.getCurrentScope().setSpan(transaction);
4040

41+
// eslint-disable-next-line deprecation/deprecation
4142
const span = transaction.startChild();
4243

4344
span.end();

dev-packages/node-integration-tests/suites/public-api/startTransaction/with-nested-spans/scenario.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Sentry.init({
1010

1111
// eslint-disable-next-line deprecation/deprecation
1212
const transaction = Sentry.startTransaction({ name: 'test_transaction_1' });
13+
// eslint-disable-next-line deprecation/deprecation
1314
const span_1 = transaction.startChild({
1415
op: 'span_1',
1516
data: {
@@ -23,16 +24,20 @@ for (let i = 0; i < 2000; i++);
2324
span_1.end();
2425

2526
// span_2 doesn't finish
27+
// eslint-disable-next-line deprecation/deprecation
2628
transaction.startChild({ op: 'span_2' });
2729
for (let i = 0; i < 4000; i++);
2830

31+
// eslint-disable-next-line deprecation/deprecation
2932
const span_3 = transaction.startChild({ op: 'span_3' });
3033
for (let i = 0; i < 4000; i++);
3134

3235
// span_4 is the child of span_3 but doesn't finish.
36+
// eslint-disable-next-line deprecation/deprecation
3337
span_3.startChild({ op: 'span_4', data: { qux: 'quux' } });
3438

3539
// span_5 is another child of span_3 but finishes.
40+
// eslint-disable-next-line deprecation/deprecation
3641
span_3.startChild({ op: 'span_5' }).end();
3742

3843
// span_3 also finishes

packages/angular/src/tracing.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class TraceService implements OnDestroy {
8484
if (this._routingSpan) {
8585
this._routingSpan.end();
8686
}
87+
// eslint-disable-next-line deprecation/deprecation
8788
this._routingSpan = activeTransaction.startChild({
8889
description: `${navigationEvent.url}`,
8990
op: ANGULAR_ROUTING_OP,
@@ -183,6 +184,7 @@ export class TraceDirective implements OnInit, AfterViewInit {
183184

184185
const activeTransaction = getActiveTransaction();
185186
if (activeTransaction) {
187+
// eslint-disable-next-line deprecation/deprecation
186188
this._tracingSpan = activeTransaction.startChild({
187189
description: `<${this.componentName}>`,
188190
op: ANGULAR_INIT_OP,
@@ -225,6 +227,7 @@ export function TraceClassDecorator(): ClassDecorator {
225227
target.prototype.ngOnInit = function (...args: any[]): ReturnType<typeof originalOnInit> {
226228
const activeTransaction = getActiveTransaction();
227229
if (activeTransaction) {
230+
// eslint-disable-next-line deprecation/deprecation
228231
tracingSpan = activeTransaction.startChild({
229232
description: `<${target.name}>`,
230233
op: ANGULAR_INIT_OP,
@@ -262,6 +265,7 @@ export function TraceMethodDecorator(): MethodDecorator {
262265
const now = timestampInSeconds();
263266
const activeTransaction = getActiveTransaction();
264267
if (activeTransaction) {
268+
// eslint-disable-next-line deprecation/deprecation
265269
activeTransaction.startChild({
266270
description: `<${target.constructor.name}>`,
267271
endTimestamp: now,

packages/core/src/tracing/span.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ export class Span implements SpanInterface {
187187
}
188188

189189
/**
190-
* @inheritDoc
190+
* Creates a new `Span` while setting the current `Span.id` as `parentSpanId`.
191+
* Also the `sampled` decision will be inherited.
192+
*
193+
* @deprecated Use `startSpan()`, `startSpanManual()` or `startInactiveSpan()` instead.
191194
*/
192195
public startChild(
193196
spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'sampled' | 'traceId' | 'parentSpanId'>>,

packages/core/src/tracing/trace.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined {
158158
const hub = getCurrentHub();
159159
const parentSpan = getActiveSpan();
160160
return parentSpan
161-
? parentSpan.startChild(ctx)
161+
? // eslint-disable-next-line deprecation/deprecation
162+
parentSpan.startChild(ctx)
162163
: // eslint-disable-next-line deprecation/deprecation
163164
hub.startTransaction(ctx);
164165
}
@@ -240,7 +241,8 @@ function createChildSpanOrTransaction(
240241
return undefined;
241242
}
242243
return parentSpan
243-
? parentSpan.startChild(ctx)
244+
? // eslint-disable-next-line deprecation/deprecation
245+
parentSpan.startChild(ctx)
244246
: // eslint-disable-next-line deprecation/deprecation
245247
hub.startTransaction(ctx);
246248
}

packages/ember/addon/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const instrumentRoutePerformance = <T extends RouteConstructor>(BaseRoute
8888
return result;
8989
}
9090
currentTransaction
91+
// eslint-disable-next-line deprecation/deprecation
9192
.startChild({
9293
op,
9394
description,

packages/ember/addon/instance-initializers/sentry-performance.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export function _instrumentEmberRouter(
149149
'routing.instrumentation': '@sentry/ember',
150150
},
151151
});
152+
// eslint-disable-next-line deprecation/deprecation
152153
transitionSpan = activeTransaction?.startChild({
153154
op: 'ui.ember.transition',
154155
description: `route:${fromRoute} -> route:${toRoute}`,
@@ -212,6 +213,7 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void {
212213

213214
if ((now - currentQueueStart) * 1000 >= minQueueDuration) {
214215
activeTransaction
216+
// eslint-disable-next-line deprecation/deprecation
215217
?.startChild({
216218
op: `ui.ember.runloop.${queue}`,
217219
origin: 'auto.ui.ember',
@@ -287,7 +289,7 @@ function processComponentRenderAfter(
287289

288290
if (componentRenderDuration * 1000 >= minComponentDuration) {
289291
const activeTransaction = getActiveTransaction();
290-
292+
// eslint-disable-next-line deprecation/deprecation
291293
activeTransaction?.startChild({
292294
op,
293295
description: payload.containerKey || payload.object,
@@ -373,6 +375,7 @@ function _instrumentInitialLoad(config: EmberSentryConfig): void {
373375
const endTimestamp = startTimestamp + measure.duration / 1000;
374376

375377
const transaction = getActiveTransaction();
378+
// eslint-disable-next-line deprecation/deprecation
376379
const span = transaction?.startChild({
377380
op: 'ui.ember.init',
378381
origin: 'auto.ui.ember',

packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export function pagesRouterInstrumentation(
186186
// We don't want to finish the navigation transaction on `routeChangeComplete`, since users might want to attach
187187
// spans to that transaction even after `routeChangeComplete` is fired (eg. HTTP requests in some useEffect
188188
// hooks). Instead, we'll simply let the navigation transaction finish itself (it's an `IdleTransaction`).
189+
// eslint-disable-next-line deprecation/deprecation
189190
const nextRouteChangeSpan = navigationTransaction.startChild({
190191
op: 'ui.nextjs.route-change',
191192
origin: 'auto.ui.nextjs.pages_router_instrumentation',

packages/nextjs/src/common/utils/wrapperUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export function withTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
131131
spanToContinue = previousSpan;
132132
}
133133

134+
// eslint-disable-next-line deprecation/deprecation
134135
dataFetcherSpan = spanToContinue.startChild({
135136
op: 'function.nextjs',
136137
description: `${options.dataFetchingMethodName} (${options.dataFetcherRouteName})`,
@@ -209,6 +210,7 @@ export async function callDataFetcherTraced<F extends (...args: any[]) => Promis
209210

210211
// Capture the route, since pre-loading, revalidation, etc might mean that this span may happen during another
211212
// route's transaction
213+
// eslint-disable-next-line deprecation/deprecation
212214
const span = transaction.startChild({
213215
op: 'function.nextjs',
214216
origin: 'auto.function.nextjs',

packages/node/src/integrations/http.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ function _createWrappedRequestMethodFactory(
251251
const data = getRequestSpanData(requestUrl, requestOptions);
252252

253253
const requestSpan = shouldCreateSpan(rawRequestUrl)
254-
? parentSpan?.startChild({
254+
? // eslint-disable-next-line deprecation/deprecation
255+
parentSpan?.startChild({
255256
op: 'http.client',
256257
origin: 'auto.http.node.http',
257258
description: `${data['http.method']} ${data.url}`,

packages/node/src/integrations/undici/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ function createRequestSpan(
310310
if (url.hash) {
311311
data['http.fragment'] = url.hash;
312312
}
313+
// eslint-disable-next-line deprecation/deprecation
313314
return activeSpan?.startChild({
314315
op: 'http.client',
315316
origin: 'auto.http.node.undici',

packages/node/test/handlers.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ describe('tracingHandler', () => {
424424
it('waits to finish transaction until all spans are finished, even though `transaction.end()` is registered on `res.finish` event first', done => {
425425
const transaction = new Transaction({ name: 'mockTransaction', sampled: true });
426426
transaction.initSpanRecorder();
427+
// eslint-disable-next-line deprecation/deprecation
427428
const span = transaction.startChild({
428429
description: 'reallyCoolHandler',
429430
op: 'middleware',

packages/opentelemetry-node/src/spanprocessor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
5656
const sentryParentSpan = otelParentSpanId && getSentrySpan(otelParentSpanId);
5757

5858
if (sentryParentSpan) {
59+
// eslint-disable-next-line deprecation/deprecation
5960
const sentryChildSpan = sentryParentSpan.startChild({
6061
description: otelSpan.name,
6162
instrumenter: 'otel',

packages/opentelemetry-node/test/propagator.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('SentryPropagator', () => {
6565
if (type === PerfType.Span) {
6666
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6767
const { spanId, ...ctx } = transactionContext;
68+
// eslint-disable-next-line deprecation/deprecation
6869
const span = transaction.startChild({ ...ctx, description: transaction.name });
6970
setSentrySpan(span.spanId, span);
7071
}

packages/opentelemetry/src/spanExporter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ function createAndFinishSpanForOtelSpan(node: SpanNode, sentryParentSpan: Sentry
204204
const { op, description, tags, data, origin } = getSpanData(span);
205205
const allData = { ...removeSentryAttributes(attributes), ...data };
206206

207+
// eslint-disable-next-line deprecation/deprecation
207208
const sentrySpan = sentryParentSpan.startChild({
208209
description,
209210
op,

packages/react/src/profiler.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Profiler extends React.Component<ProfilerProps> {
5959

6060
const activeTransaction = getActiveTransaction();
6161
if (activeTransaction) {
62+
// eslint-disable-next-line deprecation/deprecation
6263
this._mountSpan = activeTransaction.startChild({
6364
description: `<${name}>`,
6465
op: REACT_MOUNT_OP,
@@ -85,6 +86,7 @@ class Profiler extends React.Component<ProfilerProps> {
8586
const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
8687
if (changedProps.length > 0) {
8788
const now = timestampInSeconds();
89+
// eslint-disable-next-line deprecation/deprecation
8890
this._updateSpan = this._mountSpan.startChild({
8991
data: {
9092
changedProps,
@@ -116,6 +118,7 @@ class Profiler extends React.Component<ProfilerProps> {
116118
if (this._mountSpan && includeRender) {
117119
// If we were able to obtain the spanId of the mount activity, we should set the
118120
// next activity as a child to the component mount activity.
121+
// eslint-disable-next-line deprecation/deprecation
119122
this._mountSpan.startChild({
120123
description: `<${name}>`,
121124
endTimestamp: timestampInSeconds(),
@@ -183,6 +186,7 @@ function useProfiler(
183186

184187
const activeTransaction = getActiveTransaction();
185188
if (activeTransaction) {
189+
// eslint-disable-next-line deprecation/deprecation
186190
return activeTransaction.startChild({
187191
description: `<${name}>`,
188192
op: REACT_MOUNT_OP,
@@ -201,6 +205,7 @@ function useProfiler(
201205

202206
return (): void => {
203207
if (mountSpan && options.hasRenderSpan) {
208+
// eslint-disable-next-line deprecation/deprecation
204209
mountSpan.startChild({
205210
description: `<${name}>`,
206211
endTimestamp: timestampInSeconds(),

packages/remix/src/utils/instrumentServer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ function makeWrappedDocumentRequestFunction(remixVersion?: number) {
184184
const activeTransaction = getActiveTransaction();
185185

186186
try {
187+
// eslint-disable-next-line deprecation/deprecation
187188
const span = activeTransaction?.startChild({
188189
op: 'function.remix.document_request',
189190
origin: 'auto.function.remix',
@@ -239,6 +240,7 @@ function makeWrappedDataFunction(
239240
const currentScope = getCurrentScope();
240241

241242
try {
243+
// eslint-disable-next-line deprecation/deprecation
242244
const span = activeTransaction?.startChild({
243245
op: `function.remix.${name}`,
244246
origin: 'auto.ui.remix',

packages/serverless/src/awsservices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function wrapMakeRequest<TService extends AWSService, TResult>(
6262
const req = orig.call(this, operation, params);
6363
req.on('afterBuild', () => {
6464
if (transaction) {
65+
// eslint-disable-next-line deprecation/deprecation
6566
span = transaction.startChild({
6667
description: describe(this, operation, params),
6768
op: 'http.client',

packages/serverless/src/google-cloud-grpc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function fillGrpcFunction(stub: Stub, serviceIdentifier: string, methodName: str
111111
const scope = getCurrentScope();
112112
const transaction = scope.getTransaction();
113113
if (transaction) {
114+
// eslint-disable-next-line deprecation/deprecation
114115
span = transaction.startChild({
115116
description: `${callType} ${methodName}`,
116117
op: `grpc.${serviceIdentifier}`,

packages/serverless/src/google-cloud-http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function wrapRequestFunction(orig: RequestFunction): RequestFunction {
5656
const transaction = scope.getTransaction();
5757
if (transaction) {
5858
const httpMethod = reqOpts.method || 'GET';
59+
// eslint-disable-next-line deprecation/deprecation
5960
span = transaction.startChild({
6061
description: `${httpMethod} ${reqOpts.uri}`,
6162
op: `http.client.${identifyService(this.apiEndpoint)}`,

packages/svelte/src/performance.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function trackComponent(options?: TrackComponentOptions): void {
4747
}
4848

4949
function recordInitSpan(transaction: Transaction, componentName: string): Span {
50+
// eslint-disable-next-line deprecation/deprecation
5051
const initSpan = transaction.startChild({
5152
op: UI_SVELTE_INIT,
5253
description: componentName,
@@ -75,6 +76,7 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
7576
const parentSpan =
7677
initSpan && !initSpan.endTimestamp && initSpan.transaction === transaction ? initSpan : transaction;
7778

79+
// eslint-disable-next-line deprecation/deprecation
7880
updateSpan = parentSpan.startChild({
7981
op: UI_SVELTE_UPDATE,
8082
description: componentName,

packages/sveltekit/src/client/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ function instrumentNavigations(startTransactionFn: (context: TransactionContext)
117117
// If a routing span is still open from a previous navigation, we finish it.
118118
routingSpan.end();
119119
}
120+
// eslint-disable-next-line deprecation/deprecation
120121
routingSpan = activeTransaction.startChild({
121122
op: 'ui.sveltekit.routing',
122123
description: 'SvelteKit Route Change',

packages/sveltekit/test/client/router.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ describe('sveltekitRoutingInstrumentation', () => {
117117
},
118118
});
119119

120+
// eslint-disable-next-line deprecation/deprecation
120121
expect(returnedTransaction?.startChild).toHaveBeenCalledWith({
121122
op: 'ui.sveltekit.routing',
122123
origin: 'auto.ui.sveltekit',
@@ -168,6 +169,7 @@ describe('sveltekitRoutingInstrumentation', () => {
168169
},
169170
});
170171

172+
// eslint-disable-next-line deprecation/deprecation
171173
expect(returnedTransaction?.startChild).toHaveBeenCalledWith({
172174
op: 'ui.sveltekit.routing',
173175
origin: 'auto.ui.sveltekit',

packages/tracing-internal/src/browser/metrics/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function startTrackingLongTasks(): void {
7676
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
7777
const duration = msToSec(entry.duration);
7878

79+
// eslint-disable-next-line deprecation/deprecation
7980
transaction.startChild({
8081
description: 'Main UI thread blocked',
8182
op: 'ui.long-task',
@@ -115,6 +116,7 @@ export function startTrackingInteractions(): void {
115116
span.data = { 'ui.component_name': componentName };
116117
}
117118

119+
// eslint-disable-next-line deprecation/deprecation
118120
transaction.startChild(span);
119121
}
120122
}

packages/tracing-internal/src/browser/metrics/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function _startChild(transaction: Transaction, { startTimestamp, ...ctx }
1818
transaction.startTimestamp = startTimestamp;
1919
}
2020

21+
// eslint-disable-next-line deprecation/deprecation
2122
return transaction.startChild({
2223
startTimestamp,
2324
...ctx,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ export function xhrCallback(
275275

276276
const span =
277277
shouldCreateSpanResult && parentSpan
278-
? parentSpan.startChild({
278+
? // eslint-disable-next-line deprecation/deprecation
279+
parentSpan.startChild({
279280
data: {
280281
type: 'xhr',
281282
'http.method': sentryXhrData.method,

packages/tracing-internal/src/common/fetch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export function instrumentFetchRequest(
7979

8080
const span =
8181
shouldCreateSpanResult && parentSpan
82-
? parentSpan.startChild({
82+
? // eslint-disable-next-line deprecation/deprecation
83+
parentSpan.startChild({
8384
data: {
8485
url,
8586
type: 'fetch',

0 commit comments

Comments
 (0)