Skip to content

Commit 64abebc

Browse files
authored
feat(core): Deprecate Transaction.setMeasurement in favor of setMeasurement (#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.
1 parent e843510 commit 64abebc

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

MIGRATION.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ In v8, the Span class is heavily reworked. The following properties & methods ar
175175
- `transaction.setMetadata()`: Use attributes instead, or set data on the scope.
176176
- `transaction.metadata`: Use attributes instead, or set data on the scope.
177177
- `transaction.setContext()`: Set context on the surrounding scope instead.
178+
- `transaction.setMeasurement()`: Use `Sentry.setMeasurement()` instead. In v8, setting measurements will be limited to
179+
the currently active root span.
178180
- `transaction.setName()`: Set the name with `.updateName()` and the source with `.setAttribute()` instead.
179181

180182
## Deprecate `pushScope` & `popScope` in favor of `withScope`

packages/core/src/tracing/measurement.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function setMeasurement(name: string, value: number, unit: MeasurementUni
99
// eslint-disable-next-line deprecation/deprecation
1010
const transaction = getActiveTransaction();
1111
if (transaction) {
12+
// eslint-disable-next-line deprecation/deprecation
1213
transaction.setMeasurement(name, value, unit);
1314
}
1415
}

packages/core/src/tracing/transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ export class Transaction extends SpanClass implements TransactionInterface {
176176

177177
/**
178178
* @inheritDoc
179+
*
180+
* @deprecated Use top-level `setMeasurement()` instead.
179181
*/
180182
public setMeasurement(name: string, value: number, unit: MeasurementUnit = ''): void {
181183
this._measurements[name] = { value, unit };

packages/tracing-internal/src/browser/metrics/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-lines */
22
import type { IdleTransaction, Transaction } from '@sentry/core';
3-
import { getActiveTransaction } from '@sentry/core';
3+
import { getActiveTransaction, setMeasurement } from '@sentry/core';
44
import type { Measurements, SpanContext } from '@sentry/types';
55
import { browserPerformanceTimeOrigin, getComponentName, htmlTreeAsString, logger } from '@sentry/utils';
66

@@ -296,11 +296,7 @@ export function addPerformanceEntries(transaction: Transaction): void {
296296
}
297297

298298
Object.keys(_measurements).forEach(measurementName => {
299-
transaction.setMeasurement(
300-
measurementName,
301-
_measurements[measurementName].value,
302-
_measurements[measurementName].unit,
303-
);
299+
setMeasurement(measurementName, _measurements[measurementName].value, _measurements[measurementName].unit);
304300
});
305301

306302
_tagMetricInfo(transaction);

packages/types/src/transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ export interface Transaction extends TransactionContext, Omit<Span, 'setName' |
123123
* @param name Name of the measurement
124124
* @param value Value of the measurement
125125
* @param unit Unit of the measurement. (Defaults to an empty string)
126+
*
127+
* @deprecated Use top-level `setMeasurement()` instead.
126128
*/
127129
setMeasurement(name: string, value: number, unit: MeasurementUnit): void;
128130

0 commit comments

Comments
 (0)