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',

0 commit comments

Comments
 (0)