Skip to content
4 changes: 4 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,11 @@ const CONST = {
// Span names
SPAN_OPEN_REPORT: 'ManualOpenReport',
SPAN_APP_STARTUP: 'ManualAppStartup',
SPAN_JS_PARSE_TIME: 'ManualJsParseTime',
SPAN_NAVIGATE_TO_REPORTS: 'ManualNavigateToReports',
SPAN_NAVIGATE_TO_REPORTS_TAB: 'ManualNavigateToReportsTab',
SPAN_NAVIGATE_TO_REPORTS_TAB_RENDER: 'ManualNavigateToReportsTabRender',
SPAN_ON_LAYOUT_SKELETON_REPORTS: 'ManualOnLayoutSkeletonReports',
SPAN_NAVIGATE_TO_INBOX_TAB: 'ManualNavigateToInboxTab',
SPAN_OD_ND_TRANSITION: 'ManualOdNdTransition',
SPAN_OD_ND_TRANSITION_LOGGED_OUT: 'ManualOdNdTransitionLoggedOut',
Expand Down
6 changes: 3 additions & 3 deletions src/libs/telemetry/activeSpans.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {StartSpanOptions} from '@sentry/core';
import type {SpanTimeInput, StartSpanOptions} from '@sentry/core';
import * as Sentry from '@sentry/react-native';
import {spanToJSON} from '@sentry/react-native';
import Log from '@libs/Log';
Expand Down Expand Up @@ -33,7 +33,7 @@ function startSpan(spanId: string, options: StartSpanOptions, extraOptions: Star
return span;
}

function endSpan(spanId: string) {
function endSpan(spanId: string, endTime?: SpanTimeInput) {
const span = activeSpans.get(spanId);

if (!span) {
Expand All @@ -46,7 +46,7 @@ function endSpan(spanId: string) {
Log.info(`[Sentry][${spanId}] Ending span (${durationMs}ms)`, undefined, {spanId, durationMs, timestamp: now});
span.setStatus({code: 1});
span.setAttribute(CONST.TELEMETRY.ATTRIBUTE_FINISHED_MANUALLY, true);
span.end();
span.end(endTime);
activeSpans.delete(spanId);
}

Expand Down
16 changes: 16 additions & 0 deletions src/setup/telemetry/setupSentry.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import * as Sentry from '@sentry/react-native';
import {getBundleStartTimestampMs} from '@sentry/react-native/dist/js/tracing/utils';
import {Platform} from 'react-native';
import {isDevelopment} from '@libs/Environment/Environment';
import {endSpan, startSpan} from '@libs/telemetry/activeSpans';
import {breadcrumbsIntegration, browserProfilingIntegration, consoleIntegration, navigationIntegration, tracingIntegration} from '@libs/telemetry/integrations';
import {processBeforeSendLogs, processBeforeSendTransactions} from '@libs/telemetry/middlewares';
import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import pkg from '../../../package.json';
import makeDebugTransport from './debugTransport';

const bundleEndMs = Date.now();

function setupSentry(): void {
// With Sentry enabled in dev mode, profiling on iOS and Android does not work
// If you want to enable Sentry in dev, set ENABLE_SENTRY_ON_DEV=true in .env
Expand Down Expand Up @@ -35,6 +39,18 @@ function setupSentry(): void {
});

Sentry.setTag(CONST.TELEMETRY.TAG_BUILD_TYPE, CONFIG.IS_HYBRID_APP ? CONST.TELEMETRY.BUILD_TYPE_HYBRID_APP : CONST.TELEMETRY.BUILD_TYPE_STANDALONE);

const bundleStartMs = getBundleStartTimestampMs();
if (bundleStartMs) {
const durationMs = bundleEndMs - bundleStartMs;
console.debug(`[Telemetry] JS parse time: ${durationMs}ms`);
startSpan(CONST.TELEMETRY.SPAN_JS_PARSE_TIME, {
name: CONST.TELEMETRY.SPAN_JS_PARSE_TIME,
op: CONST.TELEMETRY.SPAN_JS_PARSE_TIME,
startTime: bundleStartMs / 1000,
});
endSpan(CONST.TELEMETRY.SPAN_JS_PARSE_TIME, bundleEndMs / 1000);
}
}

export default setupSentry;
Loading