Skip to content

Commit 52768f2

Browse files
elirangoshenclaude
andcommitted
Add span duration logging in dev mode
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4c3e83e commit 52768f2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/libs/telemetry/activeSpans.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type {StartSpanOptions} from '@sentry/core';
22
import * as Sentry from '@sentry/react-native';
3+
import Log from '@libs/Log';
34
import CONST from '@src/CONST';
45

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

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

2528
return span;
2629
}
@@ -34,7 +37,14 @@ function endSpan(spanId: string) {
3437
span.setStatus({code: 1});
3538
span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_FINISHED_MANUALLY, true);
3639
span.end();
40+
if (__DEV__) {
41+
const startTime = spanStartTimes.get(spanId);
42+
if (startTime !== undefined) {
43+
Log.info(`[Telemetry] Span "${spanId}" duration: ${Date.now() - startTime}ms`);
44+
}
45+
}
3746
activeSpans.delete(spanId);
47+
spanStartTimes.delete(spanId);
3848
}
3949

4050
function cancelSpan(spanId: string) {

0 commit comments

Comments
 (0)