Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Deprecate span.startChild() #10091

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ npx @sentry/migr8@latest

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

## Deprecate `startTransaction()`
## Deprecate `startTransaction()` & `span.startChild()`

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

* `startSpan()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
const transaction = Sentry.startTransaction({ name: 'test-transaction', op: 'e2e-test' });
Sentry.getCurrentHub().getScope().setSpan(transaction);

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

span.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ app.get('/test-transaction', async function (req, res) {
const transaction = Sentry.startTransaction({ name: 'test-transaction', op: 'e2e-test' });
Sentry.getCurrentScope().setSpan(transaction);

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

span.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Sentry.init({

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

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

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

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

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

// span_3 also finishes
Expand Down
4 changes: 4 additions & 0 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class TraceService implements OnDestroy {
if (this._routingSpan) {
this._routingSpan.end();
}
// eslint-disable-next-line deprecation/deprecation
this._routingSpan = activeTransaction.startChild({
description: `${navigationEvent.url}`,
op: ANGULAR_ROUTING_OP,
Expand Down Expand Up @@ -183,6 +184,7 @@ export class TraceDirective implements OnInit, AfterViewInit {

const activeTransaction = getActiveTransaction();
if (activeTransaction) {
// eslint-disable-next-line deprecation/deprecation
this._tracingSpan = activeTransaction.startChild({
description: `<${this.componentName}>`,
op: ANGULAR_INIT_OP,
Expand Down Expand Up @@ -225,6 +227,7 @@ export function TraceClassDecorator(): ClassDecorator {
target.prototype.ngOnInit = function (...args: any[]): ReturnType<typeof originalOnInit> {
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
// eslint-disable-next-line deprecation/deprecation
tracingSpan = activeTransaction.startChild({
description: `<${target.name}>`,
op: ANGULAR_INIT_OP,
Expand Down Expand Up @@ -262,6 +265,7 @@ export function TraceMethodDecorator(): MethodDecorator {
const now = timestampInSeconds();
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
// eslint-disable-next-line deprecation/deprecation
activeTransaction.startChild({
description: `<${target.constructor.name}>`,
endTimestamp: now,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/tracing/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ export class Span implements SpanInterface {
}

/**
* @inheritDoc
* Creates a new `Span` while setting the current `Span.id` as `parentSpanId`.
* Also the `sampled` decision will be inherited.
*
* @deprecated Use `startSpan()`, `startSpanManual()` or `startInactiveSpan()` instead.
*/
public startChild(
spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'sampled' | 'traceId' | 'parentSpanId'>>,
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/tracing/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined {
const hub = getCurrentHub();
const parentSpan = getActiveSpan();
return parentSpan
? parentSpan.startChild(ctx)
? // eslint-disable-next-line deprecation/deprecation
parentSpan.startChild(ctx)
: // eslint-disable-next-line deprecation/deprecation
hub.startTransaction(ctx);
}
Expand Down Expand Up @@ -240,7 +241,8 @@ function createChildSpanOrTransaction(
return undefined;
}
return parentSpan
? parentSpan.startChild(ctx)
? // eslint-disable-next-line deprecation/deprecation
parentSpan.startChild(ctx)
: // eslint-disable-next-line deprecation/deprecation
hub.startTransaction(ctx);
}
Expand Down
1 change: 1 addition & 0 deletions packages/ember/addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const instrumentRoutePerformance = <T extends RouteConstructor>(BaseRoute
return result;
}
currentTransaction
// eslint-disable-next-line deprecation/deprecation
.startChild({
op,
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export function _instrumentEmberRouter(
'routing.instrumentation': '@sentry/ember',
},
});
// eslint-disable-next-line deprecation/deprecation
transitionSpan = activeTransaction?.startChild({
op: 'ui.ember.transition',
description: `route:${fromRoute} -> route:${toRoute}`,
Expand Down Expand Up @@ -212,6 +213,7 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void {

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

if (componentRenderDuration * 1000 >= minComponentDuration) {
const activeTransaction = getActiveTransaction();

// eslint-disable-next-line deprecation/deprecation
activeTransaction?.startChild({
op,
description: payload.containerKey || payload.object,
Expand Down Expand Up @@ -373,6 +375,7 @@ function _instrumentInitialLoad(config: EmberSentryConfig): void {
const endTimestamp = startTimestamp + measure.duration / 1000;

const transaction = getActiveTransaction();
// eslint-disable-next-line deprecation/deprecation
const span = transaction?.startChild({
op: 'ui.ember.init',
origin: 'auto.ui.ember',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export function pagesRouterInstrumentation(
// We don't want to finish the navigation transaction on `routeChangeComplete`, since users might want to attach
// spans to that transaction even after `routeChangeComplete` is fired (eg. HTTP requests in some useEffect
// hooks). Instead, we'll simply let the navigation transaction finish itself (it's an `IdleTransaction`).
// eslint-disable-next-line deprecation/deprecation
const nextRouteChangeSpan = navigationTransaction.startChild({
op: 'ui.nextjs.route-change',
origin: 'auto.ui.nextjs.pages_router_instrumentation',
Expand Down
2 changes: 2 additions & 0 deletions packages/nextjs/src/common/utils/wrapperUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export function withTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
spanToContinue = previousSpan;
}

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

// Capture the route, since pre-loading, revalidation, etc might mean that this span may happen during another
// route's transaction
// eslint-disable-next-line deprecation/deprecation
const span = transaction.startChild({
op: 'function.nextjs',
origin: 'auto.function.nextjs',
Expand Down
3 changes: 2 additions & 1 deletion packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ function _createWrappedRequestMethodFactory(
const data = getRequestSpanData(requestUrl, requestOptions);

const requestSpan = shouldCreateSpan(rawRequestUrl)
? parentSpan?.startChild({
? // eslint-disable-next-line deprecation/deprecation
parentSpan?.startChild({
op: 'http.client',
origin: 'auto.http.node.http',
description: `${data['http.method']} ${data.url}`,
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/integrations/undici/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ function createRequestSpan(
if (url.hash) {
data['http.fragment'] = url.hash;
}
// eslint-disable-next-line deprecation/deprecation
return activeSpan?.startChild({
op: 'http.client',
origin: 'auto.http.node.undici',
Expand Down
1 change: 1 addition & 0 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ describe('tracingHandler', () => {
it('waits to finish transaction until all spans are finished, even though `transaction.end()` is registered on `res.finish` event first', done => {
const transaction = new Transaction({ name: 'mockTransaction', sampled: true });
transaction.initSpanRecorder();
// eslint-disable-next-line deprecation/deprecation
const span = transaction.startChild({
description: 'reallyCoolHandler',
op: 'middleware',
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-node/src/spanprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class SentrySpanProcessor implements OtelSpanProcessor {
const sentryParentSpan = otelParentSpanId && getSentrySpan(otelParentSpanId);

if (sentryParentSpan) {
// eslint-disable-next-line deprecation/deprecation
const sentryChildSpan = sentryParentSpan.startChild({
description: otelSpan.name,
instrumenter: 'otel',
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-node/test/propagator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('SentryPropagator', () => {
if (type === PerfType.Span) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { spanId, ...ctx } = transactionContext;
// eslint-disable-next-line deprecation/deprecation
const span = transaction.startChild({ ...ctx, description: transaction.name });
setSentrySpan(span.spanId, span);
}
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry/src/spanExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ function createAndFinishSpanForOtelSpan(node: SpanNode, sentryParentSpan: Sentry
const { op, description, tags, data, origin } = getSpanData(span);
const allData = { ...removeSentryAttributes(attributes), ...data };

// eslint-disable-next-line deprecation/deprecation
const sentrySpan = sentryParentSpan.startChild({
description,
op,
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/profiler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Profiler extends React.Component<ProfilerProps> {

const activeTransaction = getActiveTransaction();
if (activeTransaction) {
// eslint-disable-next-line deprecation/deprecation
this._mountSpan = activeTransaction.startChild({
description: `<${name}>`,
op: REACT_MOUNT_OP,
Expand All @@ -85,6 +86,7 @@ class Profiler extends React.Component<ProfilerProps> {
const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
if (changedProps.length > 0) {
const now = timestampInSeconds();
// eslint-disable-next-line deprecation/deprecation
this._updateSpan = this._mountSpan.startChild({
data: {
changedProps,
Expand Down Expand Up @@ -116,6 +118,7 @@ class Profiler extends React.Component<ProfilerProps> {
if (this._mountSpan && includeRender) {
// If we were able to obtain the spanId of the mount activity, we should set the
// next activity as a child to the component mount activity.
// eslint-disable-next-line deprecation/deprecation
this._mountSpan.startChild({
description: `<${name}>`,
endTimestamp: timestampInSeconds(),
Expand Down Expand Up @@ -183,6 +186,7 @@ function useProfiler(

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

return (): void => {
if (mountSpan && options.hasRenderSpan) {
// eslint-disable-next-line deprecation/deprecation
mountSpan.startChild({
description: `<${name}>`,
endTimestamp: timestampInSeconds(),
Expand Down
2 changes: 2 additions & 0 deletions packages/remix/src/utils/instrumentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function makeWrappedDocumentRequestFunction(remixVersion?: number) {
const activeTransaction = getActiveTransaction();

try {
// eslint-disable-next-line deprecation/deprecation
const span = activeTransaction?.startChild({
op: 'function.remix.document_request',
origin: 'auto.function.remix',
Expand Down Expand Up @@ -239,6 +240,7 @@ function makeWrappedDataFunction(
const currentScope = getCurrentScope();

try {
// eslint-disable-next-line deprecation/deprecation
const span = activeTransaction?.startChild({
op: `function.remix.${name}`,
origin: 'auto.ui.remix',
Expand Down
1 change: 1 addition & 0 deletions packages/serverless/src/awsservices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function wrapMakeRequest<TService extends AWSService, TResult>(
const req = orig.call(this, operation, params);
req.on('afterBuild', () => {
if (transaction) {
// eslint-disable-next-line deprecation/deprecation
span = transaction.startChild({
description: describe(this, operation, params),
op: 'http.client',
Expand Down
1 change: 1 addition & 0 deletions packages/serverless/src/google-cloud-grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function fillGrpcFunction(stub: Stub, serviceIdentifier: string, methodName: str
const scope = getCurrentScope();
const transaction = scope.getTransaction();
if (transaction) {
// eslint-disable-next-line deprecation/deprecation
span = transaction.startChild({
description: `${callType} ${methodName}`,
op: `grpc.${serviceIdentifier}`,
Expand Down
1 change: 1 addition & 0 deletions packages/serverless/src/google-cloud-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function wrapRequestFunction(orig: RequestFunction): RequestFunction {
const transaction = scope.getTransaction();
if (transaction) {
const httpMethod = reqOpts.method || 'GET';
// eslint-disable-next-line deprecation/deprecation
span = transaction.startChild({
description: `${httpMethod} ${reqOpts.uri}`,
op: `http.client.${identifyService(this.apiEndpoint)}`,
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/src/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function trackComponent(options?: TrackComponentOptions): void {
}

function recordInitSpan(transaction: Transaction, componentName: string): Span {
// eslint-disable-next-line deprecation/deprecation
const initSpan = transaction.startChild({
op: UI_SVELTE_INIT,
description: componentName,
Expand Down Expand Up @@ -75,6 +76,7 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void {
const parentSpan =
initSpan && !initSpan.endTimestamp && initSpan.transaction === transaction ? initSpan : transaction;

// eslint-disable-next-line deprecation/deprecation
updateSpan = parentSpan.startChild({
op: UI_SVELTE_UPDATE,
description: componentName,
Expand Down
1 change: 1 addition & 0 deletions packages/sveltekit/src/client/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ function instrumentNavigations(startTransactionFn: (context: TransactionContext)
// If a routing span is still open from a previous navigation, we finish it.
routingSpan.end();
}
// eslint-disable-next-line deprecation/deprecation
routingSpan = activeTransaction.startChild({
op: 'ui.sveltekit.routing',
description: 'SvelteKit Route Change',
Expand Down
2 changes: 2 additions & 0 deletions packages/sveltekit/test/client/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('sveltekitRoutingInstrumentation', () => {
},
});

// eslint-disable-next-line deprecation/deprecation
expect(returnedTransaction?.startChild).toHaveBeenCalledWith({
op: 'ui.sveltekit.routing',
origin: 'auto.ui.sveltekit',
Expand Down Expand Up @@ -168,6 +169,7 @@ describe('sveltekitRoutingInstrumentation', () => {
},
});

// eslint-disable-next-line deprecation/deprecation
expect(returnedTransaction?.startChild).toHaveBeenCalledWith({
op: 'ui.sveltekit.routing',
origin: 'auto.ui.sveltekit',
Expand Down
2 changes: 2 additions & 0 deletions packages/tracing-internal/src/browser/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function startTrackingLongTasks(): void {
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
const duration = msToSec(entry.duration);

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

// eslint-disable-next-line deprecation/deprecation
transaction.startChild(span);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/tracing-internal/src/browser/metrics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function _startChild(transaction: Transaction, { startTimestamp, ...ctx }
transaction.startTimestamp = startTimestamp;
}

// eslint-disable-next-line deprecation/deprecation
return transaction.startChild({
startTimestamp,
...ctx,
Expand Down
3 changes: 2 additions & 1 deletion packages/tracing-internal/src/browser/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ export function xhrCallback(

const span =
shouldCreateSpanResult && parentSpan
? parentSpan.startChild({
? // eslint-disable-next-line deprecation/deprecation
parentSpan.startChild({
data: {
type: 'xhr',
'http.method': sentryXhrData.method,
Expand Down
3 changes: 2 additions & 1 deletion packages/tracing-internal/src/common/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export function instrumentFetchRequest(

const span =
shouldCreateSpanResult && parentSpan
? parentSpan.startChild({
? // eslint-disable-next-line deprecation/deprecation
parentSpan.startChild({
data: {
url,
type: 'fetch',
Expand Down