Skip to content
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
4 changes: 4 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ 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 `scope.getTransaction()` and `getActiveTransaction()`

Instead, you should not rely on the active transaction, but just use `startSpan()` APIs, which handle this for you.

## Deprecate arguments for `startSpan()` APIs

In v8, the API to start a new span will be reduced from the currently available options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ app.use(Sentry.Handlers.tracingHandler());
app.use(cors());

app.get('/test/express', (_req, res) => {
// eslint-disable-next-line deprecation/deprecation
const transaction = Sentry.getCurrentHub().getScope().getTransaction();
if (transaction) {
// eslint-disable-next-line deprecation/deprecation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ app.use(Sentry.Handlers.tracingHandler());
app.use(cors());

app.get('/test/express', (_req, res) => {
// eslint-disable-next-line deprecation/deprecation
const transaction = Sentry.getCurrentHub().getScope().getTransaction();
if (transaction) {
// eslint-disable-next-line deprecation/deprecation
Expand Down
31 changes: 10 additions & 21 deletions packages/angular-ivy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,33 +215,22 @@ export class FooterComponent implements OnInit {
}
```

You can also add your own custom spans by attaching them to the current active transaction using `getActiveTransaction`
helper. For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows:
You can also add your own custom spans via `startSpan()`. For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows:

```javascript
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { init, getActiveTransaction } from '@sentry/angular-ivy';
import { init, startSpan } from '@sentry/angular';

import { AppModule } from './app/app.module';

// ...

const activeTransaction = getActiveTransaction();
const boostrapSpan =
activeTransaction &&
activeTransaction.startChild({
description: 'platform-browser-dynamic',
op: 'ui.angular.bootstrap',
});

platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(() => console.log(`Bootstrap success`))
.catch(err => console.error(err));
.finally(() => {
if (bootstrapSpan) {
boostrapSpan.finish();
}
})
startSpan({
name: 'platform-browser-dynamic',
op: 'ui.angular.bootstrap'
},
async () => {
await platformBrowserDynamic().bootstrapModule(AppModule);
}
);
```
31 changes: 10 additions & 21 deletions packages/angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,33 +215,22 @@ export class FooterComponent implements OnInit {
}
```

You can also add your own custom spans by attaching them to the current active transaction using `getActiveTransaction`
helper. For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows:
You can also add your own custom spans via `startSpan()`. For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows:

```javascript
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { init, getActiveTransaction } from '@sentry/angular';
import { init, startSpan } from '@sentry/angular';

import { AppModule } from './app/app.module';

// ...

const activeTransaction = getActiveTransaction();
const boostrapSpan =
activeTransaction &&
activeTransaction.startChild({
description: 'platform-browser-dynamic',
op: 'ui.angular.bootstrap',
});

platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(() => console.log(`Bootstrap success`))
.catch(err => console.error(err));
.finally(() => {
if (bootstrapSpan) {
boostrapSpan.finish();
}
})
startSpan({
name: 'platform-browser-dynamic',
op: 'ui.angular.bootstrap'
},
async () => {
await platformBrowserDynamic().bootstrapModule(AppModule);
}
);
```
1 change: 1 addition & 0 deletions packages/angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from '@sentry/browser';
export { init } from './sdk';
export { createErrorHandler, SentryErrorHandler } from './errorhandler';
export {
// eslint-disable-next-line deprecation/deprecation
getActiveTransaction,
// TODO `instrumentAngularRouting` is just an alias for `routingInstrumentation`; deprecate the latter at some point
instrumentAngularRouting, // new name
Expand Down
10 changes: 9 additions & 1 deletion packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ export function routingInstrumentation(
export const instrumentAngularRouting = routingInstrumentation;

/**
* Grabs active transaction off scope
* Grabs active transaction off scope.
*
* @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead.
*/
export function getActiveTransaction(): Transaction | undefined {
// eslint-disable-next-line deprecation/deprecation
return getCurrentScope().getTransaction();
}

Expand All @@ -69,6 +72,7 @@ export class TraceService implements OnDestroy {
}

const strippedUrl = stripUrlQueryAndFragment(navigationEvent.url);
// eslint-disable-next-line deprecation/deprecation
let activeTransaction = getActiveTransaction();

if (!activeTransaction && stashedStartTransactionOnLocationChange) {
Expand Down Expand Up @@ -116,6 +120,7 @@ export class TraceService implements OnDestroy {
(event.state as unknown as RouterState & { root: ActivatedRouteSnapshot }).root,
);

// eslint-disable-next-line deprecation/deprecation
const transaction = getActiveTransaction();
// TODO (v8 / #5416): revisit the source condition. Do we want to make the parameterized route the default?
if (transaction && transaction.metadata.source === 'url') {
Expand Down Expand Up @@ -182,6 +187,7 @@ export class TraceDirective implements OnInit, AfterViewInit {
this.componentName = UNKNOWN_COMPONENT;
}

// eslint-disable-next-line deprecation/deprecation
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
// eslint-disable-next-line deprecation/deprecation
Expand Down Expand Up @@ -225,6 +231,7 @@ export function TraceClassDecorator(): ClassDecorator {
const originalOnInit = target.prototype.ngOnInit;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
target.prototype.ngOnInit = function (...args: any[]): ReturnType<typeof originalOnInit> {
// eslint-disable-next-line deprecation/deprecation
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
// eslint-disable-next-line deprecation/deprecation
Expand Down Expand Up @@ -263,6 +270,7 @@ export function TraceMethodDecorator(): MethodDecorator {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
descriptor.value = function (...args: any[]): ReturnType<typeof originalMethod> {
const now = timestampInSeconds();
// eslint-disable-next-line deprecation/deprecation
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
// eslint-disable-next-line deprecation/deprecation
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
createTransport,
// eslint-disable-next-line deprecation/deprecation
extractTraceparentData,
// eslint-disable-next-line deprecation/deprecation
getActiveTransaction,
getHubFromCarrier,
getCurrentHub,
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export {
setMeasurement,
// eslint-disable-next-line deprecation/deprecation
extractTraceparentData,
// eslint-disable-next-line deprecation/deprecation
getActiveTransaction,
spanStatusfromHttpCode,
// eslint-disable-next-line deprecation/deprecation
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/profiling/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const browserProfilingIntegration: IntegrationFn = () => {
setup(client) {
const scope = getCurrentScope();

// eslint-disable-next-line deprecation/deprecation
const transaction = scope.getTransaction();

if (transaction && isAutomatedPageLoadTransaction(transaction)) {
Expand Down
1 change: 1 addition & 0 deletions packages/browser/test/unit/profiling/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('BrowserProfilingIntegration', () => {

const client = Sentry.getClient<BrowserClient>();

// eslint-disable-next-line deprecation/deprecation
const currentTransaction = Sentry.getCurrentHub().getScope().getTransaction();
expect(currentTransaction?.op).toBe('pageload');
currentTransaction?.end();
Expand Down
1 change: 1 addition & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export {
// eslint-disable-next-line deprecation/deprecation
extractTraceparentData,
flush,
// eslint-disable-next-line deprecation/deprecation
getActiveTransaction,
getHubFromCarrier,
getCurrentHub,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/metrics/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function addToMetricsAggregator(
}
const { unit, tags, timestamp } = data;
const { release, environment } = client.getOptions();
// eslint-disable-next-line deprecation/deprecation
const transaction = scope.getTransaction();
const metricTags: Record<string, string> = {};
if (release) {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ export class Scope implements ScopeInterface {
}

/**
* @inheritDoc
* Returns the `Transaction` attached to the scope (if there is one).
* @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead.
*/
public getTransaction(): Transaction | undefined {
// Often, this span (if it exists at all) will be a transaction, but it's not guaranteed to be. Regardless, it will
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tracing/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function registerErrorInstrumentation(): void {
* If an error or unhandled promise occurs, we mark the active transaction as failed
*/
function errorCallback(): void {
// eslint-disable-next-line deprecation/deprecation
const activeTransaction = getActiveTransaction();
if (activeTransaction) {
const status: SpanStatusType = 'internal_error';
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tracing/idletransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export class IdleTransaction extends Transaction {
// if `this._onScope` is `true`, the transaction put itself on the scope when it started
if (this._onScope) {
const scope = this._idleHub.getScope();
// eslint-disable-next-line deprecation/deprecation
if (scope.getTransaction() === this) {
scope.setSpan(undefined);
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/tracing/measurement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getActiveTransaction } from './utils';
* Adds a measurement to the current active transaction.
*/
export function setMeasurement(name: string, value: number, unit: MeasurementUnit): void {
// eslint-disable-next-line deprecation/deprecation
const transaction = getActiveTransaction();
if (transaction) {
transaction.setMeasurement(name, value, unit);
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/tracing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { extractTraceparentData as _extractTraceparentData } from '@sentry/utils
import type { Hub } from '../hub';
import { getCurrentHub } from '../hub';

/** Grabs active transaction off scope, if any */
/**
* Grabs active transaction off scope.
*
* @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead.
*/
export function getActiveTransaction<T extends Transaction>(maybeHub?: Hub): T | undefined {
const hub = maybeHub || getCurrentHub();
const scope = hub.getScope();
// eslint-disable-next-line deprecation/deprecation
return scope.getTransaction() as T | undefined;
}

Expand Down
1 change: 1 addition & 0 deletions packages/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export {
extractTraceparentData,
continueTrace,
flush,
// eslint-disable-next-line deprecation/deprecation
getActiveTransaction,
getHubFromCarrier,
getCurrentHub,
Expand Down
32 changes: 16 additions & 16 deletions packages/ember/addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { assert, warn } from '@ember/debug';
import type Route from '@ember/routing/route';
import { next } from '@ember/runloop';
import { getOwnConfig, isDevelopingApp, macroCondition } from '@embroider/macros';
import { startSpan } from '@sentry/browser';
import type { BrowserOptions } from '@sentry/browser';
import * as Sentry from '@sentry/browser';
import { SDK_VERSION } from '@sentry/browser';
import type { Transaction } from '@sentry/types';
import { GLOBAL_OBJ, timestampInSeconds } from '@sentry/utils';
import { GLOBAL_OBJ } from '@sentry/utils';
import Ember from 'ember';

import type { EmberSentryConfig, GlobalConfig, OwnConfig } from './types';
Expand Down Expand Up @@ -66,7 +67,13 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions): void {
}
}

/**
* Grabs active transaction off scope.
*
* @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead.
*/
export const getActiveTransaction = (): Transaction | undefined => {
// eslint-disable-next-line deprecation/deprecation
return Sentry.getCurrentHub().getScope().getTransaction();
};

Expand All @@ -80,23 +87,16 @@ export const instrumentRoutePerformance = <T extends RouteConstructor>(BaseRoute
fn: X,
args: Parameters<X>,
): Promise<ReturnType<X>> => {
const startTimestamp = timestampInSeconds();
const result = await fn(...args);

const currentTransaction = getActiveTransaction();
if (!currentTransaction) {
return result;
}
currentTransaction
// eslint-disable-next-line deprecation/deprecation
.startChild({
return startSpan(
{
op,
description,
name: description,
origin: 'auto.ui.ember',
startTimestamp,
})
.end();
return result;
},
() => {
return fn(...args);
},
);
};

const routeName = BaseRoute.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void {
if (previousInstance) {
return;
}
// eslint-disable-next-line deprecation/deprecation
const activeTransaction = getActiveTransaction();
if (!activeTransaction) {
return;
Expand Down Expand Up @@ -227,6 +228,7 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void {

// Setup for next queue

// eslint-disable-next-line deprecation/deprecation
const stillActiveTransaction = getActiveTransaction();
if (!stillActiveTransaction) {
return;
Expand Down Expand Up @@ -288,6 +290,7 @@ function processComponentRenderAfter(
const componentRenderDuration = now - begin.now;

if (componentRenderDuration * 1000 >= minComponentDuration) {
// eslint-disable-next-line deprecation/deprecation
const activeTransaction = getActiveTransaction();
// eslint-disable-next-line deprecation/deprecation
activeTransaction?.startChild({
Expand Down Expand Up @@ -374,6 +377,7 @@ function _instrumentInitialLoad(config: EmberSentryConfig): void {
const startTimestamp = (measure.startTime + browserPerformanceTimeOrigin) / 1000;
const endTimestamp = startTimestamp + measure.duration / 1000;

// eslint-disable-next-line deprecation/deprecation
const transaction = getActiveTransaction();
// eslint-disable-next-line deprecation/deprecation
const span = transaction?.startChild({
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/src/common/utils/wrapperUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export async function callDataFetcherTraced<F extends (...args: any[]) => Promis
): Promise<ReturnType<F>> {
const { parameterizedRoute, dataFetchingMethodName } = options;

// eslint-disable-next-line deprecation/deprecation
const transaction = getActiveTransaction();

if (!transaction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetI
};
} = await tracedGetInitialProps.apply(thisArg, args);

// eslint-disable-next-line deprecation/deprecation
const requestTransaction = getTransactionFromRequest(req) ?? getCurrentScope().getTransaction();

// Per definition, `pageProps` is not optional, however an increased amount of users doesn't seem to call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function wrapErrorGetInitialPropsWithSentry(
_sentryBaggage?: string;
} = await tracedGetInitialProps.apply(thisArg, args);

// eslint-disable-next-line deprecation/deprecation
const requestTransaction = getTransactionFromRequest(req) ?? getCurrentScope().getTransaction();
if (requestTransaction) {
errorGetInitialProps._sentryTraceData = spanToTraceHeader(requestTransaction);
Expand Down
Loading