Skip to content

feat(v8): Remove deprecated trace and startActiveSpan methods #10593

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

Merged
merged 3 commits into from
Feb 12, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ export const config = {
};

export default async function handler() {
// Without `runWithAsyncContext` and a working async context strategy the two spans created by `Sentry.trace()` would be nested.
// Without `runWithAsyncContext` and a working async context strategy the two spans created by `Sentry.startSpan()` would be nested.

const outerSpanPromise = Sentry.runWithAsyncContext(() => {
return Sentry.trace({ name: 'outer-span' }, () => {
return Sentry.startSpan({ name: 'outer-span' }, () => {
return new Promise<void>(resolve => setTimeout(resolve, 300));
});
});

setTimeout(() => {
Sentry.runWithAsyncContext(() => {
return Sentry.trace({ name: 'inner-span' }, () => {
return Sentry.startSpan({ name: 'inner-span' }, () => {
return new Promise<void>(resolve => setTimeout(resolve, 100));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ const NODE_EXPORTS_IGNORE = [
'default',
// Probably generated by transpilation, no need to require it
'__esModule',
// this function was deprecated almost immediately after it was introduced
// due to a name change (startSpan). No need to re-export it IMHO.
'startActiveSpan',
// this was never meant for external use (and documented as such)
'trace',
// These Node exports were only made for type definition fixes (see #10339)
'Undici',
'Http',
Expand Down
4 changes: 0 additions & 4 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export {
setUser,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
withScope,
withIsolationScope,
autoDiscoverNodePerformanceMonitoringIntegrations,
Expand Down Expand Up @@ -78,8 +76,6 @@ export {
setMeasurement,
getActiveSpan,
startSpan,
// eslint-disable-next-line deprecation/deprecation
startActiveSpan,
startInactiveSpan,
startSpanManual,
continueTrace,
Expand Down
2 changes: 0 additions & 2 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export {
getActiveTransaction,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
makeMultiplexedTransport,
// eslint-disable-next-line deprecation/deprecation
ModuleMetadata,
Expand Down
2 changes: 0 additions & 2 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export {
setUser,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
withScope,
withIsolationScope,
captureCheckIn,
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ export {
} from './spanstatus';
export type { SpanStatusType } from './spanstatus';
export {
// eslint-disable-next-line deprecation/deprecation
trace,
getActiveSpan,
startSpan,
startInactiveSpan,
// eslint-disable-next-line deprecation/deprecation
startActiveSpan,
startSpanManual,
continueTrace,
} from './trace';
Expand Down
54 changes: 0 additions & 54 deletions packages/core/src/tracing/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,6 @@ import { handleCallbackErrors } from '../utils/handleCallbackErrors';
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
import { spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';

/**
* Wraps a function with a transaction/span and finishes the span after the function is done.
*
* Note that if you have not enabled tracing extensions via `addTracingExtensions`
* or you didn't set `tracesSampleRate`, this function will not generate spans
* and the `span` returned from the callback will be undefined.
*
* This function is meant to be used internally and may break at any time. Use at your own risk.
*
* @internal
* @private
*
* @deprecated Use `startSpan` instead.
*/
export function trace<T>(
context: TransactionContext,
callback: (span?: Span) => T,
// eslint-disable-next-line @typescript-eslint/no-empty-function
onError: (error: unknown, span?: Span) => void = () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
afterFinish: () => void = () => {},
): T {
// eslint-disable-next-line deprecation/deprecation
const hub = getCurrentHub();
const scope = getCurrentScope();
// eslint-disable-next-line deprecation/deprecation
const parentSpan = scope.getSpan();

const ctx = normalizeContext(context);
const activeSpan = createChildSpanOrTransaction(hub, parentSpan, ctx);

// eslint-disable-next-line deprecation/deprecation
scope.setSpan(activeSpan);

return handleCallbackErrors(
() => callback(activeSpan),
error => {
activeSpan && activeSpan.setStatus('internal_error');
onError(error, activeSpan);
},
() => {
activeSpan && activeSpan.end();
// eslint-disable-next-line deprecation/deprecation
scope.setSpan(parentSpan);
afterFinish();
},
);
}

/**
* Wraps a function with a transaction/span and finishes the span after the function is done.
* The created span is the active span and will be used as parent by other spans created inside the function
Expand Down Expand Up @@ -105,11 +56,6 @@ export function startSpan<T>(context: StartSpanOptions, callback: (span: Span |
});
}

/**
* @deprecated Use {@link startSpan} instead.
*/
export const startActiveSpan = startSpan;

/**
* Similar to `Sentry.startSpan`. Wraps a function with a transaction/span, but does not finish the span
* after the function is done automatically. You'll have to call `span.end()` manually.
Expand Down
2 changes: 0 additions & 2 deletions packages/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export {
setUser,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
withScope,
withIsolationScope,
captureCheckIn,
Expand Down
8 changes: 4 additions & 4 deletions packages/node-experimental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ You can manual instrument using the following APIs:
```js
const Sentry = require('@sentry/node-experimental');

Sentry.startActiveSpan({ description: 'outer' }, function (span) {
Sentry.startSpan({ description: 'outer' }, function (span) {
span.setData(customData);
doSomethingSlow();
Sentry.startActiveSpan({ description: 'inner' }, function() {
Sentry.startSpan({ description: 'inner' }, function() {
// inner span is a child of outer span
doSomethingVerySlow();
// inner span is auto-ended when this callback ends
Expand All @@ -72,13 +72,13 @@ Sentry.startActiveSpan({ description: 'outer' }, function (span) {
```

You can also create spans without marking them as the active span.
Note that for most scenarios, we recommend the `startActiveSpan` syntax.
Note that for most scenarios, we recommend the `startSpan` syntax.

```js
const Sentry = require('@sentry/node-experimental');

// This will _not_ be put on the scope/set as active, so no other spans will be attached to it
const span = Sentry.startSpan({ description: 'non-active span' });
const span = Sentry.startInactiveSpan({ description: 'non-active span' });

doSomethingSlow();

Expand Down
2 changes: 0 additions & 2 deletions packages/node-experimental/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export {
SDK_VERSION,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
captureCheckIn,
withMonitor,
hapiErrorPlugin,
Expand Down
4 changes: 0 additions & 4 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,13 @@ export {
setUser,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
withScope,
withIsolationScope,
captureCheckIn,
withMonitor,
setMeasurement,
getActiveSpan,
startSpan,
// eslint-disable-next-line deprecation/deprecation
startActiveSpan,
startInactiveSpan,
startSpanManual,
continueTrace,
Expand Down
2 changes: 0 additions & 2 deletions packages/remix/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export {
setUser,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
withScope,
withIsolationScope,
autoDiscoverNodePerformanceMonitoringIntegrations,
Expand Down
2 changes: 0 additions & 2 deletions packages/serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export {
setMeasurement,
getActiveSpan,
startSpan,
// eslint-disable-next-line deprecation/deprecation
startActiveSpan,
startInactiveSpan,
startSpanManual,
continueTrace,
Expand Down
4 changes: 0 additions & 4 deletions packages/sveltekit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export {
setUser,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
withScope,
withIsolationScope,
autoDiscoverNodePerformanceMonitoringIntegrations,
Expand Down Expand Up @@ -76,8 +74,6 @@ export {
setMeasurement,
getActiveSpan,
startSpan,
// eslint-disable-next-line deprecation/deprecation
startActiveSpan,
startInactiveSpan,
startSpanManual,
continueTrace,
Expand Down
2 changes: 0 additions & 2 deletions packages/vercel-edge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export {
setUser,
getSpanStatusFromHttpCode,
setHttpStatus,
// eslint-disable-next-line deprecation/deprecation
trace,
withScope,
withIsolationScope,
captureCheckIn,
Expand Down