Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 5 additions & 19 deletions src/libs/telemetry/activeSpans.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {SpanAttributeValue, StartSpanOptions} from '@sentry/core';
import * as Sentry from '@sentry/react-native';
import {AppState} from 'react-native';
import Log from '@libs/Log';
import CONST from '@src/CONST';

type ActiveSpanEntry = {
Expand All @@ -25,7 +24,7 @@ function startSpan(spanId: string, options: StartSpanOptions, extraOptions: Star
}
// End any existing span for this name
cancelSpan(spanId);
Log.info(`[Sentry][${spanId}] Starting span`, undefined, {
console.debug(`[Sentry][${spanId}] Starting span`, {
spanId,
spanOptions: options,
spanExtraOptions: extraOptions,
Expand All @@ -45,13 +44,13 @@ function endSpan(spanId: string) {
const entry = activeSpans.get(spanId);

if (!entry) {
Log.info(`[Sentry][${spanId}] Trying to end span but it does not exist`, undefined, {spanId, timestamp: Date.now()});
console.debug(`[Sentry][${spanId}] Trying to end span but it does not exist`, {spanId, timestamp: Date.now()});
return;
}
const {span, startTime} = entry;
const now = performance.now();
const durationMs = Math.round(now - startTime);
Log.info(`[Sentry][${spanId}] Ending span (${durationMs}ms)`, undefined, {spanId, durationMs, timestamp: now});
console.debug(`[Sentry][${spanId}] Ending span (${durationMs}ms)`, {spanId, durationMs, timestamp: now});
span.setStatus({code: 1});
span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_FINISHED_MANUALLY, true);
span.end();
Expand All @@ -63,7 +62,7 @@ function cancelSpan(spanId: string) {
if (!entry) {
return;
}
Log.info(`[Sentry][${spanId}] Canceling span`, undefined, {spanId, timestamp: Date.now()});
console.debug(`[Sentry][${spanId}] Canceling span`, {spanId, timestamp: Date.now()});
entry.span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_CANCELED, true);
// In Sentry there are only OK or ERROR status codes.
// We treat canceled spans as OK, so we can properly track spans that are not finished at all (their status would be different)
Expand All @@ -85,19 +84,6 @@ function cancelSpansByPrefix(prefix: string) {
}
}

/**
* Ends a span only if it's currently active. Unlike `endSpan`, this silently no-ops
* when the span doesn't exist, making it safe for render paths where the span
* may or may not have been started.
Comment on lines -89 to -91
Copy link
Contributor

@mkhutornyi mkhutornyi Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Is this no longer needed? I think was good for optimization.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah @TMisiukiewicz added it very recently, should we keep it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was added so we don't send too much of trying to end nonexistent span logs to /api/Log. Now when we don't send these logs at all this is unnecessary and only duplicates the code.

*/
function tryEndSpan(spanId: string): boolean {
if (!activeSpans.has(spanId)) {
return false;
}
endSpan(spanId);
return true;
}

function getSpan(spanId: string) {
return activeSpans.get(spanId)?.span;
}
Expand All @@ -108,4 +94,4 @@ function endSpanWithAttributes(spanId: string, attributes: Record<string, SpanAt
endSpan(spanId);
}

export {startSpan, endSpan, tryEndSpan, endSpanWithAttributes, getSpan, cancelSpan, cancelAllSpans, cancelSpansByPrefix};
export {startSpan, endSpan, endSpanWithAttributes, getSpan, cancelSpan, cancelAllSpans, cancelSpansByPrefix};
4 changes: 2 additions & 2 deletions src/pages/inbox/report/comment/TextCommentFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {containsOnlyCustomEmoji as containsOnlyCustomEmojiUtil, containsOnlyEmoj
import hydrateEmojiHtml from '@libs/hydrateEmojiHtml';
import Parser from '@libs/Parser';
import {getHtmlWithAttachmentID, getTextFromHtml} from '@libs/ReportActionsUtils';
import {tryEndSpan} from '@libs/telemetry/activeSpans';
import {endSpan} from '@libs/telemetry/activeSpans';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type {OriginalMessageSource} from '@src/types/onyx/OriginalMessage';
Expand Down Expand Up @@ -67,7 +67,7 @@ function TextCommentFragment({fragment, styleAsDeleted, reportActionID, styleAsM
if (!reportActionID) {
return;
}
tryEndSpan(`${CONST.TELEMETRY.SPAN_SEND_MESSAGE}_${reportActionID}`);
endSpan(`${CONST.TELEMETRY.SPAN_SEND_MESSAGE}_${reportActionID}`);
}, [reportActionID]);

// If the only difference between fragment.text and fragment.html is <br /> tags and emoji tag
Expand Down
Loading