From 8eaa5628ee085b0172869145f58ed5f69a16ee3e Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 9 Sep 2024 12:40:34 +0200 Subject: [PATCH] feat(core): Allow adding measurements without global client (#13612) While working on updating [`sentry-javascript-bundler-plugins` to use v8 of the JavaScript SDK](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/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()`. --- packages/core/src/tracing/measurement.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/tracing/measurement.ts b/packages/core/src/tracing/measurement.ts index 817569a03930..c8802023bf2e 100644 --- a/packages/core/src/tracing/measurement.ts +++ b/packages/core/src/tracing/measurement.ts @@ -6,10 +6,10 @@ import { import { getActiveSpan, getRootSpan } from '../utils/spanUtils'; /** - * Adds a measurement to the current active transaction. + * Adds a measurement to the active transaction on the current global scope. You can optionally pass in a different span + * as the 4th parameter. */ -export function setMeasurement(name: string, value: number, unit: MeasurementUnit): void { - const activeSpan = getActiveSpan(); +export function setMeasurement(name: string, value: number, unit: MeasurementUnit, activeSpan = getActiveSpan()): void { const rootSpan = activeSpan && getRootSpan(activeSpan); if (rootSpan) {