Skip to content

Commit

Permalink
ref(v8): Remove deprecated scope.getTransaction() (#11365)
Browse files Browse the repository at this point in the history
This depends on
#11363 being merged
first...
  • Loading branch information
mydea committed Apr 2, 2024
1 parent cc0599f commit 2e6f903
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 35 deletions.
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

0 comments on commit 2e6f903

Please sign in to comment.