Skip to content
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

feat(core): Deprecate Transaction.setMeasurement in favor of setMeasurement #10182

Merged
merged 2 commits into from
Jan 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,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