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
10 changes: 0 additions & 10 deletions src/libs/telemetry/activeSpans.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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>>();
Expand All @@ -16,12 +15,6 @@ type StartSpanExtraOptions = Partial<{
function startSpan(spanId: string, options: StartSpanOptions, extraOptions: StartSpanExtraOptions = {}) {
// End any existing span for this name
cancelSpan(spanId);
Log.info(`[Sentry][${spanId}] Starting span`, undefined, {
spanId,
spanOptions: options,
spanExtraOptions: extraOptions,
timestamp: Date.now(),
});
const span = Sentry.startInactiveSpan(options);

if (extraOptions.minDuration) {
Expand All @@ -36,10 +29,8 @@ function endSpan(spanId: string) {
const span = activeSpans.get(spanId);

if (!span) {
Log.info(`[Sentry][${spanId}] Trying to end span but it does not exist`, undefined, {spanId, timestamp: Date.now()});
return;
}
Log.info(`[Sentry][${spanId}] Ending span`, undefined, {spanId, timestamp: Date.now()});
span.setStatus({code: 1});
span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_FINISHED_MANUALLY, true);
span.end();
Expand All @@ -48,7 +39,6 @@ function endSpan(spanId: string) {

function cancelSpan(spanId: string) {
const span = activeSpans.get(spanId);
Log.info(`[Sentry][${spanId}] Canceling span`, undefined, {spanId, spanExists: !!span, timestamp: Date.now()});
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 Down
15 changes: 1 addition & 14 deletions src/libs/telemetry/forwardLogsToSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as Sentry from '@sentry/react-native';

type SentryLogLevel = 'debug' | 'info' | 'warn' | 'error';

const PARAMETERS_WHITELIST = new Set(['timestamp', 'spanExists', 'spanId', 'spanOptions', 'spanExtraOptions']);

/**
* Method deciding whether a log packet should be forwarded to Sentry.
*
Expand All @@ -13,9 +11,6 @@ const PARAMETERS_WHITELIST = new Set(['timestamp', 'spanExists', 'spanId', 'span
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function shouldForwardLog(log: {message?: string; parameters?: Record<string, unknown> | undefined}) {
if (log.message?.search('[Sentry]') !== -1) {
return true;
}
return false;
}

Expand All @@ -32,14 +27,6 @@ function mapLogMessageToSentryLevel(message: string): SentryLogLevel {
return 'debug';
}

function filterParameters(parameters: Record<string, unknown> | undefined) {
if (!parameters) {
return undefined;
}

return Object.fromEntries(Object.entries(parameters).filter(([key]) => PARAMETERS_WHITELIST.has(key)));
}

function forwardLogsToSentry(logPacket: string | undefined) {
if (!logPacket) {
return;
Expand Down Expand Up @@ -72,7 +59,7 @@ function forwardLogsToSentry(logPacket: string | undefined) {
}

if (logLine.parameters) {
logMethod(logLine.message, filterParameters(logLine.parameters));
logMethod(logLine.message, logLine.parameters);
} else {
logMethod(logLine.message);
}
Expand Down
Loading