@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
46 lines (37 loc) • 1.38 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
const semanticAttributes = require('../semanticAttributes.js');
const spanUtils = require('../utils/spanUtils.js');
/**
* Adds a measurement to the current active transaction.
*/
function setMeasurement(name, value, unit) {
const activeSpan = spanUtils.getActiveSpan();
const rootSpan = activeSpan && spanUtils.getRootSpan(activeSpan);
if (rootSpan) {
rootSpan.addEvent(name, {
[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE]: value,
[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT]: unit ,
});
}
}
/**
* Convert timed events to measurements.
*/
function timedEventsToMeasurements(events) {
if (!events || events.length === 0) {
return undefined;
}
const measurements = {};
events.forEach(event => {
const attributes = event.attributes || {};
const unit = attributes[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT] ;
const value = attributes[semanticAttributes.SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE] ;
if (typeof unit === 'string' && typeof value === 'number') {
measurements[event.name] = { value, unit };
}
});
return measurements;
}
exports.setMeasurement = setMeasurement;
exports.timedEventsToMeasurements = timedEventsToMeasurements;
//# sourceMappingURL=measurement.js.map