diff --git a/dev-packages/node-integration-tests/suites/tracing/metric-summaries/test.ts b/dev-packages/node-integration-tests/suites/tracing/metric-summaries/test.ts index 140fc6369d1a..94f5fdc30c70 100644 --- a/dev-packages/node-integration-tests/suites/tracing/metric-summaries/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/metric-summaries/test.ts @@ -11,6 +11,7 @@ const EXPECTED_TRANSACTION = { sum: 1, tags: { release: '1.0', + transaction: 'Test Transaction', email: 'jon.doe@example.com', }, }, @@ -21,6 +22,7 @@ const EXPECTED_TRANSACTION = { sum: 1, tags: { release: '1.0', + transaction: 'Test Transaction', email: 'jane.doe@example.com', }, }, @@ -39,6 +41,7 @@ const EXPECTED_TRANSACTION = { sum: 4, tags: { release: '1.0', + transaction: 'Test Transaction', }, }, ], @@ -50,6 +53,7 @@ const EXPECTED_TRANSACTION = { sum: 2, tags: { release: '1.0', + transaction: 'Test Transaction', }, }, ], @@ -61,6 +65,7 @@ const EXPECTED_TRANSACTION = { sum: 62, tags: { release: '1.0', + transaction: 'Test Transaction', }, }, ], @@ -72,6 +77,7 @@ const EXPECTED_TRANSACTION = { sum: 62, tags: { release: '1.0', + transaction: 'Test Transaction', }, }, ], diff --git a/packages/core/src/metrics/exports.ts b/packages/core/src/metrics/exports.ts index 2ed0d9cb9d51..4fb088287a40 100644 --- a/packages/core/src/metrics/exports.ts +++ b/packages/core/src/metrics/exports.ts @@ -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'; @@ -63,11 +62,11 @@ 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 = {}; if (release) { metricTags.release = release; @@ -75,8 +74,8 @@ function addToMetricsAggregator( 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}`); diff --git a/packages/core/src/scope.ts b/packages/core/src/scope.ts index d75cd521cf9f..75d4db91aaa7 100644 --- a/packages/core/src/scope.ts +++ b/packages/core/src/scope.ts @@ -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'; /** @@ -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 */ diff --git a/packages/types/src/scope.ts b/packages/types/src/scope.ts index b3b43b95439e..83a03de45125 100644 --- a/packages/types/src/scope.ts +++ b/packages/types/src/scope.ts @@ -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 */ @@ -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 */