UNPKG

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

Version:

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

53 lines (52 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.logWarning = exports.isAttributes = exports.normalizeLinks = exports.normalizeAttributes = exports.normalizeTime = void 0; /** * Several different primitive types are valid as TimeInput, normalize to a number representing epoch milliseconds * to simplify communication with the native modules * * See https://reactnative.dev/docs/native-modules-android#argument-types and https://reactnative.dev/docs/native-modules-ios#argument-types */ const normalizeTime = (time) => { if (time === undefined) { return 0; } if (typeof time === "number") { return time; } if (time instanceof Date) { return time.getTime(); } // HrTime if (Array.isArray(time) && time.length === 2) { const epochMilliseconds = time[0] * 1000; const extraMilliseconds = Math.round(time[1] / 1e6); return epochMilliseconds + extraMilliseconds; } return 0; }; exports.normalizeTime = normalizeTime; /** * Parsing is handled on the native side, just need to make sure it is always defined */ const normalizeAttributes = (attributes) => { return attributes || {}; }; exports.normalizeAttributes = normalizeAttributes; /** * Parsing is handled on the native side, just need to make sure it is always defined */ const normalizeLinks = (links) => { return links || []; }; exports.normalizeLinks = normalizeLinks; const isAttributes = (attributesOrTimeInput) => { return (typeof attributesOrTimeInput === "object" && !(attributesOrTimeInput instanceof Date) && !Array.isArray(attributesOrTimeInput)); }; exports.isAttributes = isAttributes; const logWarning = (msg) => { console.warn(`[Embrace] ${msg}`); }; exports.logWarning = logWarning;