Skip to content

Commit 8eaa562

Browse files
authored
feat(core): Allow adding measurements without global client (#13612)
While working on updating [`sentry-javascript-bundler-plugins` to use v8 of the JavaScript SDK](getsentry/sentry-javascript-bundler-plugins#579), I found that I was unable to set measurements as the global client is not used. If you're not using a global client, there is currently no way to add measurements because `Sentry.setMeasurement()` relies on `getActiveSpan()` which in turn relies on `getCurrentScope()`. This PR moves the `activeSpan` into the last parameter which defaults to `getActiveSpan()`.
1 parent 45156d2 commit 8eaa562

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/core/src/tracing/measurement.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
import { getActiveSpan, getRootSpan } from '../utils/spanUtils';
77

88
/**
9-
* Adds a measurement to the current active transaction.
9+
* Adds a measurement to the active transaction on the current global scope. You can optionally pass in a different span
10+
* as the 4th parameter.
1011
*/
11-
export function setMeasurement(name: string, value: number, unit: MeasurementUnit): void {
12-
const activeSpan = getActiveSpan();
12+
export function setMeasurement(name: string, value: number, unit: MeasurementUnit, activeSpan = getActiveSpan()): void {
1313
const rootSpan = activeSpan && getRootSpan(activeSpan);
1414

1515
if (rootSpan) {

0 commit comments

Comments
 (0)