Skip to content

Commit

Permalink
feat(core): Deprecate Transaction.setMeasurement in favor of `setMe…
Browse files Browse the repository at this point in the history
…asurement` (#10182)

Deprecate the `setMeasurement` API on the transaction interface
and class. It's replaced by an already existing top level
`setMeasurement` function.

The actual replacement behaviour is TBD for v8 but for now we need to
deprecate this method as it's not part of the Otel API.
  • Loading branch information
Lms24 committed Jan 15, 2024
1 parent e843510 commit 64abebc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ In v8, the Span class is heavily reworked. The following properties & methods ar
- `transaction.setMetadata()`: Use attributes instead, or set data on the scope.
- `transaction.metadata`: Use attributes instead, or set data on the scope.
- `transaction.setContext()`: Set context on the surrounding scope instead.
- `transaction.setMeasurement()`: Use `Sentry.setMeasurement()` instead. In v8, setting measurements will be limited to
the currently active root span.
- `transaction.setName()`: Set the name with `.updateName()` and the source with `.setAttribute()` instead.

## Deprecate `pushScope` & `popScope` in favor of `withScope`
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 @@ -9,6 +9,7 @@ export function setMeasurement(name: string, value: number, unit: MeasurementUni
// eslint-disable-next-line deprecation/deprecation
const transaction = getActiveTransaction();
if (transaction) {
// eslint-disable-next-line deprecation/deprecation
transaction.setMeasurement(name, value, unit);
}
}
2 changes: 2 additions & 0 deletions packages/core/src/tracing/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export class Transaction extends SpanClass implements TransactionInterface {

/**
* @inheritDoc
*
* @deprecated Use top-level `setMeasurement()` instead.
*/
public setMeasurement(name: string, value: number, unit: MeasurementUnit = ''): void {
this._measurements[name] = { value, unit };
Expand Down
8 changes: 2 additions & 6 deletions packages/tracing-internal/src/browser/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-lines */
import type { IdleTransaction, Transaction } from '@sentry/core';
import { getActiveTransaction } from '@sentry/core';
import { getActiveTransaction, setMeasurement } from '@sentry/core';
import type { Measurements, SpanContext } from '@sentry/types';
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, logger } from '@sentry/utils';

Expand Down Expand Up @@ -296,11 +296,7 @@ export function addPerformanceEntries(transaction: Transaction): void {
}

Object.keys(_measurements).forEach(measurementName => {
transaction.setMeasurement(
measurementName,
_measurements[measurementName].value,
_measurements[measurementName].unit,
);
setMeasurement(measurementName, _measurements[measurementName].value, _measurements[measurementName].unit);
});

_tagMetricInfo(transaction);
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ export interface Transaction extends TransactionContext, Omit<Span, 'setName' |
* @param name Name of the measurement
* @param value Value of the measurement
* @param unit Unit of the measurement. (Defaults to an empty string)
*
* @deprecated Use top-level `setMeasurement()` instead.
*/
setMeasurement(name: string, value: number, unit: MeasurementUnit): void;

Expand Down

0 comments on commit 64abebc

Please sign in to comment.