UNPKG

@embrace-io/react-native-tracer-provider

Version:

A React Native for the Embrace SDK that conforms to the OpenTelemetry TracerProvider interface

46 lines (45 loc) 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.recordCompletedSpan = exports.asParent = exports.endAsFailed = exports.startView = void 0; const api_1 = require("@opentelemetry/api"); /** * startView uses the given tracer to create a span that follows Embrace's semantics for representing a view */ const startView = (tracer, viewName) => tracer.startSpan("emb-screen-view", { attributes: { "view.name": viewName, "emb.type": "ux.view", }, }); exports.startView = startView; /** * endAsFailed offers a shortcut for setting the span's status as ERROR and then ending it */ const endAsFailed = (span) => { span.setStatus({ code: api_1.SpanStatusCode.ERROR }); span.end(); }; exports.endAsFailed = endAsFailed; /** * asParent puts the given span into a context that can then be used as an argument to a tracer's * `startSpan` call, e.g.: `tracer.startSpan("the-child", {}, asParent(parentSpan));` */ const asParent = (span) => api_1.trace.setSpan(api_1.context.active(), span); exports.asParent = asParent; const recordCompletedSpan = (tracer, name, options = {}) => { const span = tracer.startSpan(name, { kind: options.kind, attributes: options.attributes, links: options.links, startTime: options.startTime, root: options.root, }, options.parent ? asParent(options.parent) : undefined); if (options.events) { options.events.forEach(e => span.addEvent(e.name, e.attributes, e.timeStamp)); } if (options.status) { span.setStatus(options.status); } span.end(options.endTime); }; exports.recordCompletedSpan = recordCompletedSpan;