Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/libs/telemetry/activeSpans.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type {StartSpanOptions} from '@sentry/core';
import * as Sentry from '@sentry/react-native';
import Log from '@libs/Log';
import CONST from '@src/CONST';

const activeSpans = new Map<string, ReturnType<typeof Sentry.startInactiveSpan>>();
const spanStartTimes = new Map<string, number>();

type StartSpanExtraOptions = Partial<{
/**
Expand All @@ -21,6 +23,7 @@ function startSpan(spanId: string, options: StartSpanOptions, extraOptions: Star
span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_MIN_DURATION, extraOptions.minDuration);
}
activeSpans.set(spanId, span);
spanStartTimes.set(spanId, options.startTime ? Number(options.startTime) * 1000 : Date.now());

return span;
}
Expand All @@ -34,7 +37,14 @@ function endSpan(spanId: string) {
span.setStatus({code: 1});
span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_FINISHED_MANUALLY, true);
span.end();
if (__DEV__) {
const startTime = spanStartTimes.get(spanId);
if (startTime !== undefined) {
Log.info(`[Telemetry] Span "${spanId}" duration: ${Date.now() - startTime}ms`);
}
}
activeSpans.delete(spanId);
spanStartTimes.delete(spanId);
}

function cancelSpan(spanId: string) {
Expand Down
Loading