From 52768f289abfc6b4eb48f15dd4e8004852670c93 Mon Sep 17 00:00:00 2001 From: eliran goshen Date: Mon, 23 Feb 2026 13:54:37 +0100 Subject: [PATCH] Add span duration logging in dev mode Co-Authored-By: Claude Sonnet 4.6 --- src/libs/telemetry/activeSpans.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libs/telemetry/activeSpans.ts b/src/libs/telemetry/activeSpans.ts index 57694ff3b5c09..93e65a4593c75 100644 --- a/src/libs/telemetry/activeSpans.ts +++ b/src/libs/telemetry/activeSpans.ts @@ -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>(); +const spanStartTimes = new Map(); type StartSpanExtraOptions = Partial<{ /** @@ -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; } @@ -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) {