package.build.esm.tracing.measurement.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Base implementation for all Sentry JavaScript SDKs
{"version":3,"file":"measurement.js","sources":["../../../src/tracing/measurement.ts"],"sourcesContent":["import type { MeasurementUnit, Measurements, TimedEvent } from '@sentry/types';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT,\n SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE,\n} from '../semanticAttributes';\nimport { getActiveSpan, getRootSpan } from '../utils/spanUtils';\n\n/**\n * Adds a measurement to the current active transaction.\n */\nexport function setMeasurement(name: string, value: number, unit: MeasurementUnit): void {\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan && getRootSpan(activeSpan);\n\n if (rootSpan) {\n rootSpan.addEvent(name, {\n [SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: value,\n [SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: unit as string,\n });\n }\n}\n\n/**\n * Convert timed events to measurements.\n */\nexport function timedEventsToMeasurements(events: TimedEvent[]): Measurements | undefined {\n if (!events || events.length === 0) {\n return undefined;\n }\n\n const measurements: Measurements = {};\n events.forEach(event => {\n const attributes = event.attributes || {};\n const unit = attributes[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT] as MeasurementUnit | undefined;\n const value = attributes[SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE] as number | undefined;\n\n if (typeof unit === 'string' && typeof value === 'number') {\n measurements[event.name] = { value, unit };\n }\n });\n\n return measurements;\n}\n"],"names":[],"mappings":";;;AAOA;AACA;AACA;AACO,SAAS,cAAc,CAAC,IAAI,EAAU,KAAK,EAAU,IAAI,EAAyB;AACzF,EAAE,MAAM,UAAA,GAAa,aAAa,EAAE,CAAA;AACpC,EAAE,MAAM,WAAW,UAAA,IAAc,WAAW,CAAC,UAAU,CAAC,CAAA;AACxD;AACA,EAAE,IAAI,QAAQ,EAAE;AAChB,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;AAC5B,MAAM,CAAC,2CAA2C,GAAG,KAAK;AAC1D,MAAM,CAAC,0CAA0C,GAAG,IAAK;AACzD,KAAK,CAAC,CAAA;AACN,GAAE;AACF,CAAA;AACA;AACA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,MAAM,EAA0C;AAC1F,EAAE,IAAI,CAAC,MAAO,IAAG,MAAM,CAAC,MAAA,KAAW,CAAC,EAAE;AACtC,IAAI,OAAO,SAAS,CAAA;AACpB,GAAE;AACF;AACA,EAAE,MAAM,YAAY,GAAiB,EAAE,CAAA;AACvC,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS;AAC1B,IAAI,MAAM,aAAa,KAAK,CAAC,UAAW,IAAG,EAAE,CAAA;AAC7C,IAAI,MAAM,IAAK,GAAE,UAAU,CAAC,0CAA0C,CAAE,EAAA;AACxE,IAAI,MAAM,KAAM,GAAE,UAAU,CAAC,2CAA2C,CAAE,EAAA;AAC1E;AACA,IAAI,IAAI,OAAO,IAAK,KAAI,QAAS,IAAG,OAAO,KAAA,KAAU,QAAQ,EAAE;AAC/D,MAAM,YAAY,CAAC,KAAK,CAAC,IAAI,CAAE,GAAE,EAAE,KAAK,EAAE,IAAA,EAAM,CAAA;AAChD,KAAI;AACJ,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,OAAO,YAAY,CAAA;AACrB;;;;"}