UNPKG

@datadog/mobile-react-native

Version:

A client-side React Native module to interact with Datadog

28 lines (27 loc) 1.5 kB
/* * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. * This product includes software developed at Datadog (https://www.datadoghq.com/). * Copyright 2016-Present Datadog, Inc. */ import { InternalLog } from '../InternalLog'; import { SdkVerbosity } from '../SdkVerbosity'; import { bufferNativeCallReturningId, bufferNativeCallWithId } from '../sdk/DatadogProvider/Buffer/bufferNativeCall'; import { validateContext } from '../utils/argsUtils'; import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider'; const timeProvider = new DefaultTimeProvider(); class DdTraceWrapper { // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires nativeTrace = require('../specs/NativeDdTrace').default; startSpan = (operation, context = {}, timestampMs = timeProvider.now()) => { const spanId = bufferNativeCallReturningId(() => this.nativeTrace.startSpan(operation, validateContext(context), timestampMs)); InternalLog.log(`Starting span “${operation}” #${spanId}`, SdkVerbosity.DEBUG); return spanId; }; finishSpan = (spanId, context = {}, timestampMs = timeProvider.now()) => { InternalLog.log(`Finishing span #${spanId}`, SdkVerbosity.DEBUG); return bufferNativeCallWithId(id => this.nativeTrace.finishSpan(id, validateContext(context), timestampMs), spanId); }; } const DdTrace = new DdTraceWrapper(); export { DdTrace }; //# sourceMappingURL=DdTrace.js.map