Skip to content

Commit

Permalink
feat(core): Allow adding measurements without global client (#13612)
Browse files Browse the repository at this point in the history
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()`.
  • Loading branch information
timfish committed Sep 9, 2024
1 parent 45156d2 commit 8eaa562
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/tracing/measurement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8eaa562

Please sign in to comment.