Skip to content

ref(v8): Remove deprecated scope.getTransaction() #11365

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 2 commits into from
Apr 2, 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 @@ -11,6 +11,7 @@ const EXPECTED_TRANSACTION = {
sum: 1,
tags: {
release: '1.0',
transaction: 'Test Transaction',
email: 'jon.doe@example.com',
},
},
Expand All @@ -21,6 +22,7 @@ const EXPECTED_TRANSACTION = {
sum: 1,
tags: {
release: '1.0',
transaction: 'Test Transaction',
email: 'jane.doe@example.com',
},
},
Expand All @@ -39,6 +41,7 @@ const EXPECTED_TRANSACTION = {
sum: 4,
tags: {
release: '1.0',
transaction: 'Test Transaction',
},
},
],
Expand All @@ -50,6 +53,7 @@ const EXPECTED_TRANSACTION = {
sum: 2,
tags: {
release: '1.0',
transaction: 'Test Transaction',
},
},
],
Expand All @@ -61,6 +65,7 @@ const EXPECTED_TRANSACTION = {
sum: 62,
tags: {
release: '1.0',
transaction: 'Test Transaction',
},
},
],
Expand All @@ -72,6 +77,7 @@ const EXPECTED_TRANSACTION = {
sum: 62,
tags: {
release: '1.0',
transaction: 'Test Transaction',
},
},
],
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/metrics/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import type {
Primitive,
} from '@sentry/types';
import { getGlobalSingleton, logger } from '@sentry/utils';
import { getCurrentScope } from '../currentScopes';
import { getClient } from '../currentScopes';
import { DEBUG_BUILD } from '../debug-build';
import { spanToJSON } from '../utils/spanUtils';
import { getActiveSpan, getRootSpan, spanToJSON } from '../utils/spanUtils';
import { COUNTER_METRIC_TYPE, DISTRIBUTION_METRIC_TYPE, GAUGE_METRIC_TYPE, SET_METRIC_TYPE } from './constants';
import type { MetricType } from './types';

Expand Down Expand Up @@ -63,20 +62,20 @@ function addToMetricsAggregator(
return;
}

const scope = getCurrentScope();
const span = getActiveSpan();
const rootSpan = span ? getRootSpan(span) : undefined;

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) {
metricTags.release = release;
}
if (environment) {
metricTags.environment = environment;
}
if (transaction) {
metricTags.transaction = spanToJSON(transaction).description || '';
if (rootSpan) {
metricTags.transaction = spanToJSON(rootSpan).description || '';
}

DEBUG_BUILD && logger.log(`Adding value of ${value} to ${metricType} metric ${name}`);
Expand Down
21 changes: 0 additions & 21 deletions packages/core/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ import type {
ScopeData,
Session,
SeverityLevel,
Transaction,
User,
} from '@sentry/types';
import { dateTimestampInSeconds, isPlainObject, logger, uuid4 } from '@sentry/utils';

import { updateSession } from './session';
import type { SentrySpan } from './tracing/sentrySpan';
import { _getSpanForScope, _setSpanForScope } from './utils/spanOnScope';

/**
Expand Down Expand Up @@ -294,25 +292,6 @@ export class Scope implements ScopeInterface {
return this;
}

/**
* 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
// have a pointer to the currently-active transaction.
const span = _getSpanForScope(this);

// Cannot replace with getRootSpan because getRootSpan returns a span, not a transaction
// Also, this method will be removed anyway.
// eslint-disable-next-line deprecation/deprecation
if (span && (span as SentrySpan).transaction) {
// eslint-disable-next-line deprecation/deprecation
return (span as SentrySpan).transaction;
}
return undefined;
}

/**
* @inheritDoc
*/
Expand Down
7 changes: 0 additions & 7 deletions packages/types/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { RequestSession, Session } from './session';
import type { SeverityLevel } from './severity';
import type { Span } from './span';
import type { PropagationContext } from './tracing';
import type { Transaction } from './transaction';
import type { User } from './user';

/** JSDocs */
Expand Down Expand Up @@ -145,12 +144,6 @@ export interface Scope {
*/
setContext(name: string, context: Context | null): this;

/**
* 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.
*/
getTransaction(): Transaction | undefined;

/**
* Returns the `Session` if there is one
*/
Expand Down