@sentry/react-native 7.6.0 → 7.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RNSentry.podspec +1 -1
- package/android/build.gradle +1 -1
- package/android/libs/replay-stubs.jar +0 -0
- package/android/replay-stubs/build.gradle +1 -1
- package/android/src/main/java/io/sentry/react/RNSentryVersion.java +1 -1
- package/dist/js/client.d.ts.map +1 -1
- package/dist/js/client.js +9 -0
- package/dist/js/client.js.map +1 -1
- package/dist/js/feedback/FeedbackWidgetProvider.d.ts.map +1 -1
- package/dist/js/feedback/FeedbackWidgetProvider.js.map +1 -1
- package/dist/js/feedback/integration.d.ts.map +1 -1
- package/dist/js/feedback/integration.js.map +1 -1
- package/dist/js/index.d.ts +2 -2
- package/dist/js/index.d.ts.map +1 -1
- package/dist/js/index.js +1 -1
- package/dist/js/index.js.map +1 -1
- package/dist/js/integrations/default.js +1 -1
- package/dist/js/integrations/default.js.map +1 -1
- package/dist/js/integrations/expocontext.d.ts.map +1 -1
- package/dist/js/integrations/expocontext.js.map +1 -1
- package/dist/js/options.d.ts +9 -0
- package/dist/js/options.d.ts.map +1 -1
- package/dist/js/options.js.map +1 -1
- package/dist/js/replay/mobilereplay.d.ts +12 -2
- package/dist/js/replay/mobilereplay.d.ts.map +1 -1
- package/dist/js/replay/mobilereplay.js +43 -8
- package/dist/js/replay/mobilereplay.js.map +1 -1
- package/dist/js/tools/sentryMetroSerializer.d.ts.map +1 -1
- package/dist/js/tools/sentryMetroSerializer.js +9 -11
- package/dist/js/tools/sentryMetroSerializer.js.map +1 -1
- package/dist/js/tracing/integrations/nativeFrames.d.ts +2 -1
- package/dist/js/tracing/integrations/nativeFrames.d.ts.map +1 -1
- package/dist/js/tracing/integrations/nativeFrames.js +68 -25
- package/dist/js/tracing/integrations/nativeFrames.js.map +1 -1
- package/dist/js/tracing/onSpanEndUtils.d.ts +9 -0
- package/dist/js/tracing/onSpanEndUtils.d.ts.map +1 -1
- package/dist/js/tracing/onSpanEndUtils.js +52 -12
- package/dist/js/tracing/onSpanEndUtils.js.map +1 -1
- package/dist/js/tracing/reactnativenavigation.d.ts.map +1 -1
- package/dist/js/tracing/reactnativenavigation.js +4 -1
- package/dist/js/tracing/reactnativenavigation.js.map +1 -1
- package/dist/js/tracing/reactnavigation.d.ts +12 -1
- package/dist/js/tracing/reactnavigation.d.ts.map +1 -1
- package/dist/js/tracing/reactnavigation.js +51 -12
- package/dist/js/tracing/reactnavigation.js.map +1 -1
- package/dist/js/tracing/span.d.ts +18 -1
- package/dist/js/tracing/span.d.ts.map +1 -1
- package/dist/js/tracing/span.js +9 -2
- package/dist/js/tracing/span.js.map +1 -1
- package/dist/js/tracing/timetodisplay.d.ts.map +1 -1
- package/dist/js/tracing/timetodisplay.js +206 -21
- package/dist/js/tracing/timetodisplay.js.map +1 -1
- package/dist/js/version.d.ts +1 -1
- package/dist/js/version.js +1 -1
- package/dist/js/version.js.map +1 -1
- package/dist/js/wrapper.d.ts.map +1 -1
- package/dist/js/wrapper.js +5 -3
- package/dist/js/wrapper.js.map +1 -1
- package/ios/RNSentryVersion.m +1 -1
- package/package.json +13 -13
- package/ts3.8/dist/js/index.d.ts +2 -2
- package/ts3.8/dist/js/options.d.ts +9 -0
- package/ts3.8/dist/js/replay/mobilereplay.d.ts +12 -2
- package/ts3.8/dist/js/tracing/integrations/nativeFrames.d.ts +2 -1
- package/ts3.8/dist/js/tracing/onSpanEndUtils.d.ts +9 -0
- package/ts3.8/dist/js/tracing/reactnavigation.d.ts +12 -1
- package/ts3.8/dist/js/tracing/span.d.ts +18 -1
- package/ts3.8/dist/js/version.d.ts +1 -1
|
@@ -57,7 +57,23 @@ export const mobileReplayIntegration = (initOptions = defaultOptions) => {
|
|
|
57
57
|
return mobileReplayIntegrationNoop();
|
|
58
58
|
}
|
|
59
59
|
const options = mergeOptions(initOptions);
|
|
60
|
-
|
|
60
|
+
// Cache the replay ID in JavaScript to avoid excessive bridge calls
|
|
61
|
+
// This will be updated when we know the replay ID changes (e.g., after captureReplay)
|
|
62
|
+
let cachedReplayId = null;
|
|
63
|
+
function updateCachedReplayId(replayId) {
|
|
64
|
+
cachedReplayId = replayId;
|
|
65
|
+
}
|
|
66
|
+
function getCachedReplayId() {
|
|
67
|
+
if (cachedReplayId !== null) {
|
|
68
|
+
return cachedReplayId;
|
|
69
|
+
}
|
|
70
|
+
const nativeReplayId = NATIVE.getCurrentReplayId();
|
|
71
|
+
if (nativeReplayId) {
|
|
72
|
+
cachedReplayId = nativeReplayId;
|
|
73
|
+
}
|
|
74
|
+
return nativeReplayId;
|
|
75
|
+
}
|
|
76
|
+
function processEvent(event, hint) {
|
|
61
77
|
var _a;
|
|
62
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
79
|
const hasException = ((_a = event.exception) === null || _a === void 0 ? void 0 : _a.values) && event.exception.values.length > 0;
|
|
@@ -65,19 +81,36 @@ export const mobileReplayIntegration = (initOptions = defaultOptions) => {
|
|
|
65
81
|
// Event is not an error, will not capture replay
|
|
66
82
|
return event;
|
|
67
83
|
}
|
|
84
|
+
// Check if beforeErrorSampling callback filters out this error
|
|
85
|
+
if (initOptions.beforeErrorSampling) {
|
|
86
|
+
try {
|
|
87
|
+
if (initOptions.beforeErrorSampling(event, hint) === false) {
|
|
88
|
+
debug.log(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} not sent; beforeErrorSampling conditions not met for event ${event.event_id}.`);
|
|
89
|
+
return event;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
debug.error(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} beforeErrorSampling callback threw an error, proceeding with replay capture`, error);
|
|
94
|
+
// Continue with replay capture if callback throws
|
|
95
|
+
}
|
|
96
|
+
}
|
|
68
97
|
const replayId = yield NATIVE.captureReplay(isHardCrash(event));
|
|
69
|
-
if (
|
|
98
|
+
if (replayId) {
|
|
99
|
+
updateCachedReplayId(replayId);
|
|
100
|
+
debug.log(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} Captured recording replay ${replayId} for event ${event.event_id}.`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Check if there's an ongoing recording and update cache if found
|
|
70
104
|
const recordingReplayId = NATIVE.getCurrentReplayId();
|
|
71
105
|
if (recordingReplayId) {
|
|
106
|
+
updateCachedReplayId(recordingReplayId);
|
|
72
107
|
debug.log(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} assign already recording replay ${recordingReplayId} for event ${event.event_id}.`);
|
|
73
108
|
}
|
|
74
109
|
else {
|
|
110
|
+
updateCachedReplayId(null);
|
|
75
111
|
debug.log(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} not sampled for event ${event.event_id}.`);
|
|
76
112
|
}
|
|
77
113
|
}
|
|
78
|
-
else {
|
|
79
|
-
debug.log(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} Captured recording replay ${replayId} for event ${event.event_id}.`);
|
|
80
|
-
}
|
|
81
114
|
return event;
|
|
82
115
|
});
|
|
83
116
|
}
|
|
@@ -85,12 +118,14 @@ export const mobileReplayIntegration = (initOptions = defaultOptions) => {
|
|
|
85
118
|
if (!hasHooks(client)) {
|
|
86
119
|
return;
|
|
87
120
|
}
|
|
121
|
+
// Initialize the cached replay ID on setup
|
|
122
|
+
cachedReplayId = NATIVE.getCurrentReplayId();
|
|
88
123
|
client.on('createDsc', (dsc) => {
|
|
89
124
|
if (dsc.replay_id) {
|
|
90
125
|
return;
|
|
91
126
|
}
|
|
92
|
-
//
|
|
93
|
-
const currentReplayId =
|
|
127
|
+
// Use cached replay ID to avoid bridge calls
|
|
128
|
+
const currentReplayId = getCachedReplayId();
|
|
94
129
|
if (currentReplayId) {
|
|
95
130
|
dsc.replay_id = currentReplayId;
|
|
96
131
|
}
|
|
@@ -98,7 +133,7 @@ export const mobileReplayIntegration = (initOptions = defaultOptions) => {
|
|
|
98
133
|
client.on('beforeAddBreadcrumb', enrichXhrBreadcrumbsForMobileReplay);
|
|
99
134
|
}
|
|
100
135
|
function getReplayId() {
|
|
101
|
-
return
|
|
136
|
+
return getCachedReplayId();
|
|
102
137
|
}
|
|
103
138
|
// TODO: When adding manual API, ensure overlap with the web replay so users can use the same API interchangeably
|
|
104
139
|
// https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/integration.ts#L45
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobilereplay.js","sourceRoot":"","sources":["../../../src/js/replay/mobilereplay.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,CAAC,MAAM,8BAA8B,GAAG,cAAc,CAAC;AAyF7D,MAAM,cAAc,GAAkC;IACpD,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,IAAI;IACnB,cAAc,EAAE,IAAI;IACpB,8BAA8B,EAAE,KAAK;IACrC,oBAAoB,EAAE,IAAI;IAC1B,uBAAuB,EAAE,KAAK;IAC9B,kBAAkB,EAAE,WAAW;CAChC,CAAC;AAEF,SAAS,YAAY,CAAC,WAAyC;IAC7D,MAAM,MAAM,mCACP,cAAc,GACd,WAAW,CACf,CAAC;IAEF,IAAI,WAAW,CAAC,oBAAoB,KAAK,SAAS,IAAI,WAAW,CAAC,8BAA8B,KAAK,SAAS,EAAE;QAC9G,MAAM,CAAC,oBAAoB,GAAG,WAAW,CAAC,8BAA8B,CAAC;KAC1E;IAED,OAAO,MAAM,CAAC;AAChB,CAAC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,OAAO,KAAK,CAAC;;KACd;IAED,SAAS,KAAK,CAAC,MAAc;QAC3B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACrB,OAAO;SACR;QAED,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,GAA2B,EAAE,EAAE;YACrD,IAAI,GAAG,CAAC,SAAS,EAAE;gBACjB,OAAO;aACR;YAED,6GAA6G;YAC7G,MAAM,eAAe,GAAG,MAAM,CAAC,kBAAkB,EAAE,CAAC;YACpD,IAAI,eAAe,EAAE;gBACnB,GAAG,CAAC,SAAS,GAAG,eAAe,CAAC;aACjC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,qBAAqB,EAAE,mCAAmC,CAAC,CAAC;IACxE,CAAC;IAED,SAAS,WAAW;QAClB,OAAO,MAAM,CAAC,kBAAkB,EAAE,CAAC;IACrC,CAAC;IAED,iHAAiH;IACjH,8GAA8G;IAC9G,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,KAAK;QACL,YAAY;QACZ,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,WAAW;KACzB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,GAA4B,EAAE;IAChE,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,OAAO,EAAE,cAAc;QACvB,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,uCAAuC;KACjE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Client, DynamicSamplingContext, Event, Integration } from '@sentry/core';\nimport { debug } from '@sentry/core';\nimport { isHardCrash } from '../misc';\nimport { hasHooks } from '../utils/clientutils';\nimport { isExpoGo, notMobileOs } from '../utils/environment';\nimport { NATIVE } from '../wrapper';\nimport { enrichXhrBreadcrumbsForMobileReplay } from './xhrUtils';\n\nexport const MOBILE_REPLAY_INTEGRATION_NAME = 'MobileReplay';\n\n/**\n * Screenshot strategy type for Android Session Replay.\n *\n * - `'canvas'`: Canvas-based screenshot strategy. This strategy does **not** support any masking options, it always masks text and images. Use this if your application has strict PII requirements.\n * - `'pixelCopy'`: Pixel copy screenshot strategy (default). Supports all masking options.\n */\nexport type ScreenshotStrategy = 'canvas' | 'pixelCopy';\n\nexport interface MobileReplayOptions {\n /**\n * Mask all text in recordings\n *\n * @default true\n */\n maskAllText?: boolean;\n\n /**\n * Mask all images in recordings\n *\n * @default true\n */\n maskAllImages?: boolean;\n\n /**\n * Mask all vector graphics in recordings\n * Supports `react-native-svg`\n *\n * @default true\n */\n maskAllVectors?: boolean;\n\n /**\n * Enables the up to 5x faster experimental view renderer used by the Session Replay integration on iOS.\n *\n * Enabling this flag will reduce the amount of time it takes to render each frame of the session replay on the main thread, therefore reducing\n * interruptions and visual lag.\n *\n * - Experiment: This is an experimental feature and is therefore disabled by default.\n *\n * @deprecated Use `enableViewRendererV2` instead.\n * @platform ios\n */\n enableExperimentalViewRenderer?: boolean;\n\n /**\n * Enables up to 5x faster new view renderer used by the Session Replay integration on iOS.\n *\n * Enabling this flag will reduce the amount of time it takes to render each frame of the session replay on the main thread, therefore reducing\n * interruptions and visual lag. [Our benchmarks](https://github.com/getsentry/sentry-cocoa/pull/4940) have shown a significant improvement of\n * **up to 4-5x faster rendering** (reducing `~160ms` to `~36ms` per frame) on older devices.\n *\n * - Experiment: In case you are noticing issues with the new view renderer, please report the issue on [GitHub](https://github.com/getsentry/sentry-cocoa).\n * Eventually, we will remove this feature flag and use the new view renderer by default.\n *\n * @default true\n * @platform ios\n */\n enableViewRendererV2?: boolean;\n\n /**\n * Enables up to 5x faster but incomplete view rendering used by the Session Replay integration on iOS.\n *\n * Enabling this flag will reduce the amount of time it takes to render each frame of the session replay on the main thread, therefore reducing\n * interruptions and visual lag.\n *\n * - Note: This flag can only be used together with `enableExperimentalViewRenderer` with up to 20% faster render times.\n * - Experiment: This is an experimental feature and is therefore disabled by default.\n *\n * @default false\n * @platform ios\n */\n enableFastViewRendering?: boolean;\n\n /**\n * Sets the screenshot strategy used by the Session Replay integration on Android.\n *\n * If your application has strict PII requirements we recommend using `'canvas'`.\n * This strategy does **not** support any masking options, it always masks text and images.\n *\n * - Experiment: In case you are noticing issues with the canvas screenshot strategy, please report the issue on [GitHub](https://github.com/getsentry/sentry-java).\n *\n * @default 'pixelCopy'\n * @platform android\n */\n screenshotStrategy?: ScreenshotStrategy;\n}\n\nconst defaultOptions: Required<MobileReplayOptions> = {\n maskAllText: true,\n maskAllImages: true,\n maskAllVectors: true,\n enableExperimentalViewRenderer: false,\n enableViewRendererV2: true,\n enableFastViewRendering: false,\n screenshotStrategy: 'pixelCopy',\n};\n\nfunction mergeOptions(initOptions: Partial<MobileReplayOptions>): Required<MobileReplayOptions> {\n const merged = {\n ...defaultOptions,\n ...initOptions,\n };\n\n if (initOptions.enableViewRendererV2 === undefined && initOptions.enableExperimentalViewRenderer !== undefined) {\n merged.enableViewRendererV2 = initOptions.enableExperimentalViewRenderer;\n }\n\n return merged;\n}\n\ntype MobileReplayIntegration = Integration & {\n options: Required<MobileReplayOptions>;\n getReplayId: () => string | null;\n};\n\n/**\n * The Mobile Replay Integration, let's you adjust the default mobile replay options.\n * To be passed to `Sentry.init` with `replaysOnErrorSampleRate` or `replaysSessionSampleRate`.\n *\n * ```javascript\n * Sentry.init({\n * replaysOnErrorSampleRate: 1.0,\n * replaysSessionSampleRate: 1.0,\n * integrations: [mobileReplayIntegration({\n * // Adjust the default options\n * })],\n * });\n * ```\n *\n * @experimental\n */\nexport const mobileReplayIntegration = (initOptions: MobileReplayOptions = defaultOptions): MobileReplayIntegration => {\n if (isExpoGo()) {\n debug.warn(\n `[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} is not supported in Expo Go. Use EAS Build or \\`expo prebuild\\` to enable it.`,\n );\n }\n if (notMobileOs()) {\n debug.warn(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} is not supported on this platform.`);\n }\n\n if (isExpoGo() || notMobileOs()) {\n return mobileReplayIntegrationNoop();\n }\n\n const options = mergeOptions(initOptions);\n\n async function processEvent(event: Event): Promise<Event> {\n const hasException = event.exception?.values && event.exception.values.length > 0;\n if (!hasException) {\n // Event is not an error, will not capture replay\n return event;\n }\n\n const replayId = await NATIVE.captureReplay(isHardCrash(event));\n if (!replayId) {\n const recordingReplayId = NATIVE.getCurrentReplayId();\n if (recordingReplayId) {\n debug.log(\n `[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} assign already recording replay ${recordingReplayId} for event ${event.event_id}.`,\n );\n } else {\n debug.log(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} not sampled for event ${event.event_id}.`);\n }\n } else {\n debug.log(\n `[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} Captured recording replay ${replayId} for event ${event.event_id}.`,\n );\n }\n\n return event;\n }\n\n function setup(client: Client): void {\n if (!hasHooks(client)) {\n return;\n }\n\n client.on('createDsc', (dsc: DynamicSamplingContext) => {\n if (dsc.replay_id) {\n return;\n }\n\n // TODO: For better performance, we should emit replayId changes on native, and hold the replayId value in JS\n const currentReplayId = NATIVE.getCurrentReplayId();\n if (currentReplayId) {\n dsc.replay_id = currentReplayId;\n }\n });\n\n client.on('beforeAddBreadcrumb', enrichXhrBreadcrumbsForMobileReplay);\n }\n\n function getReplayId(): string | null {\n return NATIVE.getCurrentReplayId();\n }\n\n // TODO: When adding manual API, ensure overlap with the web replay so users can use the same API interchangeably\n // https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/integration.ts#L45\n return {\n name: MOBILE_REPLAY_INTEGRATION_NAME,\n setup,\n processEvent,\n options: options,\n getReplayId: getReplayId,\n };\n};\n\nconst mobileReplayIntegrationNoop = (): MobileReplayIntegration => {\n return {\n name: MOBILE_REPLAY_INTEGRATION_NAME,\n options: defaultOptions,\n getReplayId: () => null, // Mock implementation for noop version\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"mobilereplay.js","sourceRoot":"","sources":["../../../src/js/replay/mobilereplay.ts"],"names":[],"mappings":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BAA8B;QACpC,KAAK;QACL,YAAY;QACZ,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,WAAW;KACzB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,2BAA2B,GAAG,GAA4B,EAAE;IAChE,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,OAAO,EAAE,cAAc;QACvB,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,uCAAuC;KACjE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Client, DynamicSamplingContext, Event, EventHint, Integration } from '@sentry/core';\nimport { debug } from '@sentry/core';\nimport { isHardCrash } from '../misc';\nimport { hasHooks } from '../utils/clientutils';\nimport { isExpoGo, notMobileOs } from '../utils/environment';\nimport { NATIVE } from '../wrapper';\nimport { enrichXhrBreadcrumbsForMobileReplay } from './xhrUtils';\n\nexport const MOBILE_REPLAY_INTEGRATION_NAME = 'MobileReplay';\n\n/**\n * Screenshot strategy type for Android Session Replay.\n *\n * - `'canvas'`: Canvas-based screenshot strategy. This strategy does **not** support any masking options, it always masks text and images. Use this if your application has strict PII requirements.\n * - `'pixelCopy'`: Pixel copy screenshot strategy (default). Supports all masking options.\n */\nexport type ScreenshotStrategy = 'canvas' | 'pixelCopy';\n\nexport interface MobileReplayOptions {\n /**\n * Mask all text in recordings\n *\n * @default true\n */\n maskAllText?: boolean;\n\n /**\n * Mask all images in recordings\n *\n * @default true\n */\n maskAllImages?: boolean;\n\n /**\n * Mask all vector graphics in recordings\n * Supports `react-native-svg`\n *\n * @default true\n */\n maskAllVectors?: boolean;\n\n /**\n * Enables the up to 5x faster experimental view renderer used by the Session Replay integration on iOS.\n *\n * Enabling this flag will reduce the amount of time it takes to render each frame of the session replay on the main thread, therefore reducing\n * interruptions and visual lag.\n *\n * - Experiment: This is an experimental feature and is therefore disabled by default.\n *\n * @deprecated Use `enableViewRendererV2` instead.\n * @platform ios\n */\n enableExperimentalViewRenderer?: boolean;\n\n /**\n * Enables up to 5x faster new view renderer used by the Session Replay integration on iOS.\n *\n * Enabling this flag will reduce the amount of time it takes to render each frame of the session replay on the main thread, therefore reducing\n * interruptions and visual lag. [Our benchmarks](https://github.com/getsentry/sentry-cocoa/pull/4940) have shown a significant improvement of\n * **up to 4-5x faster rendering** (reducing `~160ms` to `~36ms` per frame) on older devices.\n *\n * - Experiment: In case you are noticing issues with the new view renderer, please report the issue on [GitHub](https://github.com/getsentry/sentry-cocoa).\n * Eventually, we will remove this feature flag and use the new view renderer by default.\n *\n * @default true\n * @platform ios\n */\n enableViewRendererV2?: boolean;\n\n /**\n * Enables up to 5x faster but incomplete view rendering used by the Session Replay integration on iOS.\n *\n * Enabling this flag will reduce the amount of time it takes to render each frame of the session replay on the main thread, therefore reducing\n * interruptions and visual lag.\n *\n * - Note: This flag can only be used together with `enableExperimentalViewRenderer` with up to 20% faster render times.\n * - Experiment: This is an experimental feature and is therefore disabled by default.\n *\n * @default false\n * @platform ios\n */\n enableFastViewRendering?: boolean;\n\n /**\n * Sets the screenshot strategy used by the Session Replay integration on Android.\n *\n * If your application has strict PII requirements we recommend using `'canvas'`.\n * This strategy does **not** support any masking options, it always masks text and images.\n *\n * - Experiment: In case you are noticing issues with the canvas screenshot strategy, please report the issue on [GitHub](https://github.com/getsentry/sentry-java).\n *\n * @default 'pixelCopy'\n * @platform android\n */\n screenshotStrategy?: ScreenshotStrategy;\n\n /**\n * Callback to determine if a replay should be captured for a specific error.\n * When this callback returns `false`, no replay will be captured for the error.\n * This callback is only called when an error occurs and `replaysOnErrorSampleRate` is set.\n *\n * @param event The error event\n * @param hint Additional event information\n * @returns `false` to skip capturing a replay for this error, `true` or `undefined` to proceed with sampling\n */\n beforeErrorSampling?: (event: Event, hint: EventHint) => boolean;\n}\n\nconst defaultOptions: MobileReplayOptions = {\n maskAllText: true,\n maskAllImages: true,\n maskAllVectors: true,\n enableExperimentalViewRenderer: false,\n enableViewRendererV2: true,\n enableFastViewRendering: false,\n screenshotStrategy: 'pixelCopy',\n};\n\nfunction mergeOptions(initOptions: Partial<MobileReplayOptions>): MobileReplayOptions {\n const merged = {\n ...defaultOptions,\n ...initOptions,\n };\n\n if (initOptions.enableViewRendererV2 === undefined && initOptions.enableExperimentalViewRenderer !== undefined) {\n merged.enableViewRendererV2 = initOptions.enableExperimentalViewRenderer;\n }\n\n return merged;\n}\n\ntype MobileReplayIntegration = Integration & {\n options: MobileReplayOptions;\n getReplayId: () => string | null;\n};\n\n/**\n * The Mobile Replay Integration, let's you adjust the default mobile replay options.\n * To be passed to `Sentry.init` with `replaysOnErrorSampleRate` or `replaysSessionSampleRate`.\n *\n * ```javascript\n * Sentry.init({\n * replaysOnErrorSampleRate: 1.0,\n * replaysSessionSampleRate: 1.0,\n * integrations: [mobileReplayIntegration({\n * // Adjust the default options\n * })],\n * });\n * ```\n *\n * @experimental\n */\nexport const mobileReplayIntegration = (initOptions: MobileReplayOptions = defaultOptions): MobileReplayIntegration => {\n if (isExpoGo()) {\n debug.warn(\n `[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} is not supported in Expo Go. Use EAS Build or \\`expo prebuild\\` to enable it.`,\n );\n }\n if (notMobileOs()) {\n debug.warn(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} is not supported on this platform.`);\n }\n\n if (isExpoGo() || notMobileOs()) {\n return mobileReplayIntegrationNoop();\n }\n\n const options = mergeOptions(initOptions);\n\n // Cache the replay ID in JavaScript to avoid excessive bridge calls\n // This will be updated when we know the replay ID changes (e.g., after captureReplay)\n let cachedReplayId: string | null = null;\n\n function updateCachedReplayId(replayId: string | null): void {\n cachedReplayId = replayId;\n }\n\n function getCachedReplayId(): string | null {\n if (cachedReplayId !== null) {\n return cachedReplayId;\n }\n const nativeReplayId = NATIVE.getCurrentReplayId();\n if (nativeReplayId) {\n cachedReplayId = nativeReplayId;\n }\n return nativeReplayId;\n }\n\n async function processEvent(event: Event, hint: EventHint): Promise<Event> {\n const hasException = event.exception?.values && event.exception.values.length > 0;\n if (!hasException) {\n // Event is not an error, will not capture replay\n return event;\n }\n\n // Check if beforeErrorSampling callback filters out this error\n if (initOptions.beforeErrorSampling) {\n try {\n if (initOptions.beforeErrorSampling(event, hint) === false) {\n debug.log(\n `[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} not sent; beforeErrorSampling conditions not met for event ${event.event_id}.`,\n );\n return event;\n }\n } catch (error) {\n debug.error(\n `[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} beforeErrorSampling callback threw an error, proceeding with replay capture`,\n error,\n );\n // Continue with replay capture if callback throws\n }\n }\n\n const replayId = await NATIVE.captureReplay(isHardCrash(event));\n if (replayId) {\n updateCachedReplayId(replayId);\n debug.log(\n `[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} Captured recording replay ${replayId} for event ${event.event_id}.`,\n );\n } else {\n // Check if there's an ongoing recording and update cache if found\n const recordingReplayId = NATIVE.getCurrentReplayId();\n if (recordingReplayId) {\n updateCachedReplayId(recordingReplayId);\n debug.log(\n `[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} assign already recording replay ${recordingReplayId} for event ${event.event_id}.`,\n );\n } else {\n updateCachedReplayId(null);\n debug.log(`[Sentry] ${MOBILE_REPLAY_INTEGRATION_NAME} not sampled for event ${event.event_id}.`);\n }\n }\n\n return event;\n }\n\n function setup(client: Client): void {\n if (!hasHooks(client)) {\n return;\n }\n\n // Initialize the cached replay ID on setup\n cachedReplayId = NATIVE.getCurrentReplayId();\n\n client.on('createDsc', (dsc: DynamicSamplingContext) => {\n if (dsc.replay_id) {\n return;\n }\n\n // Use cached replay ID to avoid bridge calls\n const currentReplayId = getCachedReplayId();\n if (currentReplayId) {\n dsc.replay_id = currentReplayId;\n }\n });\n\n client.on('beforeAddBreadcrumb', enrichXhrBreadcrumbsForMobileReplay);\n }\n\n function getReplayId(): string | null {\n return getCachedReplayId();\n }\n\n // TODO: When adding manual API, ensure overlap with the web replay so users can use the same API interchangeably\n // https://github.com/getsentry/sentry-javascript/blob/develop/packages/replay-internal/src/integration.ts#L45\n return {\n name: MOBILE_REPLAY_INTEGRATION_NAME,\n setup,\n processEvent,\n options: options,\n getReplayId: getReplayId,\n };\n};\n\nconst mobileReplayIntegrationNoop = (): MobileReplayIntegration => {\n return {\n name: MOBILE_REPLAY_INTEGRATION_NAME,\n options: defaultOptions,\n getReplayId: () => null, // Mock implementation for noop version\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentryMetroSerializer.d.ts","sourceRoot":"","sources":["../../../src/js/tools/sentryMetroSerializer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,KAAK,EAAU,eAAe,EAA4D,MAAM,SAAS,CAAC;AAkBjH;;GAEG;AACH,wBAAgB,6CAA6C,CAAC,EAC5D,UAAU,EACV,OAAO,GACR,EAAE;IACD,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,EAAE,CAcX;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,sBAAuB,eAAe,KAAG,
|
|
1
|
+
{"version":3,"file":"sentryMetroSerializer.d.ts","sourceRoot":"","sources":["../../../src/js/tools/sentryMetroSerializer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,KAAK,EAAU,eAAe,EAA4D,MAAM,SAAS,CAAC;AAkBjH;;GAEG;AACH,wBAAgB,6CAA6C,CAAC,EAC5D,UAAU,EACV,OAAO,GACR,EAAE;IACD,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,MAAM,EAAE,CAcX;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,sBAAuB,eAAe,KAAG,eA4DhF,CAAC"}
|
|
@@ -68,9 +68,7 @@ const createSentryMetroSerializer = (customSerializer) => {
|
|
|
68
68
|
// That needs to be done because when Metro 0.83.2 stopped importing `BabelSourceMapSegment`
|
|
69
69
|
// from `@babel/generator` and defined it locally, it subtly changed the source map output format.
|
|
70
70
|
// https://github.com/facebook/metro/blob/main/packages/metro-source-map/src/source-map.js#L47
|
|
71
|
-
|
|
72
|
-
hash.update(bundleCode);
|
|
73
|
-
debugId = (0, utils_1.stringToUUID)(hash.digest('hex'));
|
|
71
|
+
debugId = calculateDebugId(bundleCode);
|
|
74
72
|
// eslint-disable-next-line no-console
|
|
75
73
|
console.log('info ' + `Bundle Debug ID (calculated): ${debugId}`);
|
|
76
74
|
}
|
|
@@ -106,7 +104,7 @@ exports.createSentryMetroSerializer = createSentryMetroSerializer;
|
|
|
106
104
|
*/
|
|
107
105
|
function createSentryBundleCallback(debugIdModule) {
|
|
108
106
|
return (bundle) => {
|
|
109
|
-
const debugId = calculateDebugId(bundle);
|
|
107
|
+
const debugId = calculateDebugId(bundle.pre, bundle.modules);
|
|
110
108
|
debugIdModule.setSource(injectDebugId(debugIdModule.getSource().toString(), debugId));
|
|
111
109
|
bundle.pre = injectDebugId(bundle.pre, debugId);
|
|
112
110
|
return bundle;
|
|
@@ -130,15 +128,15 @@ function extractSerializerResult(serializerResult) {
|
|
|
130
128
|
function createDebugIdModule(debugId) {
|
|
131
129
|
return (0, utils_1.createVirtualJSModule)(DEBUG_ID_MODULE_PATH, (0, utils_1.createDebugIdSnippet)(debugId));
|
|
132
130
|
}
|
|
133
|
-
function calculateDebugId(
|
|
131
|
+
function calculateDebugId(bundleCode, modules) {
|
|
134
132
|
const hash = crypto.createHash('md5');
|
|
135
|
-
hash.update(
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
hash.update(bundleCode);
|
|
134
|
+
if (modules) {
|
|
135
|
+
for (const [, code] of modules) {
|
|
136
|
+
hash.update(code);
|
|
137
|
+
}
|
|
138
138
|
}
|
|
139
|
-
hash.
|
|
140
|
-
const debugId = (0, utils_1.stringToUUID)(hash.digest('hex'));
|
|
141
|
-
return debugId;
|
|
139
|
+
return (0, utils_1.stringToUUID)(hash.digest('hex'));
|
|
142
140
|
}
|
|
143
141
|
function injectDebugId(code, debugId) {
|
|
144
142
|
// eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentryMetroSerializer.js","sourceRoot":"","sources":["../../../src/js/tools/sentryMetroSerializer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiC;AAIjC,mCAMiB;AACjB,gDAAoE;AAIpE,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AAC1D,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAE3C,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC;;GAEG;AACH,SAAgB,6CAA6C,CAAC,EAC5D,UAAU,EACV,OAAO,GAKR;IACC,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,UAAU,CAAC;KACnB;IAED,MAAM,mBAAmB,GAAG,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;IACvG,IAAI,mBAAmB,EAAE;QACvB,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC;QAClF,OAAO,UAAU,CAAC;KACnB;IAED,MAAM,aAAa,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACnD,OAAO,IAAA,qBAAa,EAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAClD,CAAC;AArBD,sGAqBC;AAED;;;;;GAKG;AACI,MAAM,2BAA2B,GAAG,CAAC,gBAAkC,E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AAK,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE;QACrC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KACnB;IACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEzB,MAAM,OAAO,GAAG,IAAA,oBAAY,EAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACjD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CAAC,IAAY,EAAE,OAAe;IAClD,sEAAsE;IACtE,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,qBAAqB,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import * as crypto from 'crypto';\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport type { MixedOutput, Module, ReadOnlyGraph } from 'metro';\nimport type { Bundle, MetroSerializer, MetroSerializerOutput, SerializedBundle, VirtualJSOutput } from './utils';\nimport {\n createDebugIdSnippet,\n createVirtualJSModule,\n determineDebugIdFromBundleSource,\n prependModule,\n stringToUUID,\n} from './utils';\nimport { createDefaultMetroSerializer } from './vendor/metro/utils';\n\ntype SourceMap = Record<string, unknown>;\n\nconst DEBUG_ID_PLACE_HOLDER = '__debug_id_place_holder__';\nconst DEBUG_ID_MODULE_PATH = '__debugid__';\n\nconst SOURCE_MAP_COMMENT = '//# sourceMappingURL=';\nconst DEBUG_ID_COMMENT = '//# debugId=';\n\n/**\n * Adds Sentry Debug ID polyfill module to the bundle.\n */\nexport function unstableBeforeAssetSerializationDebugIdPlugin({\n premodules,\n debugId,\n}: {\n graph: ReadOnlyGraph<MixedOutput>;\n premodules: Module[];\n debugId?: string;\n}): Module[] {\n if (!debugId) {\n return premodules;\n }\n\n const debugIdModuleExists = premodules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) != -1;\n if (debugIdModuleExists) {\n // eslint-disable-next-line no-console\n console.warn('\\n\\nDebug ID module found. Skipping Sentry Debug ID module...\\n\\n');\n return premodules;\n }\n\n const debugIdModule = createDebugIdModule(debugId);\n return prependModule(premodules, debugIdModule);\n}\n\n/**\n * Creates a Metro serializer that adds Debug ID module to the plain bundle.\n * The Debug ID module is a virtual module that provides a debug ID in runtime.\n *\n * RAM Bundles do not support custom serializers.\n */\nexport const createSentryMetroSerializer = (customSerializer?: MetroSerializer): MetroSerializer => {\n const serializer = customSerializer || createDefaultMetroSerializer();\n return async function (entryPoint, preModules, graph, options) {\n if (graph.transformOptions.hot) {\n return serializer(entryPoint, preModules, graph, options);\n }\n\n const debugIdModuleExists = preModules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) != -1;\n if (debugIdModuleExists) {\n // eslint-disable-next-line no-console\n console.warn('Debug ID module found. Skipping Sentry Debug ID module...');\n return serializer(entryPoint, preModules, graph, options);\n }\n\n const debugIdModule = createDebugIdModule(DEBUG_ID_PLACE_HOLDER);\n options.sentryBundleCallback = createSentryBundleCallback(debugIdModule);\n const modifiedPreModules = prependModule(preModules, debugIdModule);\n\n // Run wrapped serializer\n const serializerResult = serializer(entryPoint, modifiedPreModules, graph, options);\n const { code: bundleCode, map: bundleMapString } = await extractSerializerResult(serializerResult);\n\n // Add debug id comment to the bundle\n let debugId = determineDebugIdFromBundleSource(bundleCode);\n if (!debugId) {\n // For lazy-loaded chunks or bundles without the debug ID module,\n // calculate the debug ID from the bundle content.\n // This ensures Metro 0.83.2+ code-split bundles get debug IDs.\n // That needs to be done because when Metro 0.83.2 stopped importing `BabelSourceMapSegment`\n // from `@babel/generator` and defined it locally, it subtly changed the source map output format.\n // https://github.com/facebook/metro/blob/main/packages/metro-source-map/src/source-map.js#L47\n const hash = crypto.createHash('md5');\n hash.update(bundleCode);\n debugId = stringToUUID(hash.digest('hex'));\n // eslint-disable-next-line no-console\n console.log('info ' + `Bundle Debug ID (calculated): ${debugId}`);\n }\n // Only print debug id for command line builds => not hot reload from dev server\n // eslint-disable-next-line no-console\n console.log('info ' + `Bundle Debug ID: ${debugId}`);\n\n const debugIdComment = `${DEBUG_ID_COMMENT}${debugId}`;\n const indexOfSourceMapComment = bundleCode.lastIndexOf(SOURCE_MAP_COMMENT);\n const bundleCodeWithDebugId =\n indexOfSourceMapComment === -1\n ? // If source map comment is missing lets just add the debug id comment\n `${bundleCode}\\n${debugIdComment}`\n : // If source map comment is present lets add the debug id comment before it\n `${bundleCode.substring(0, indexOfSourceMapComment) + debugIdComment}\\n${bundleCode.substring(\n indexOfSourceMapComment,\n )}`;\n\n const bundleMap: SourceMap = JSON.parse(bundleMapString);\n // For now we write both fields until we know what will become the standard - if ever.\n bundleMap['debug_id'] = debugId;\n bundleMap['debugId'] = debugId;\n\n return {\n code: bundleCodeWithDebugId,\n map: JSON.stringify(bundleMap),\n };\n };\n};\n\n/**\n * This function is expected to be called after serializer creates the final bundle object\n * and before the source maps are generated.\n *\n * It injects a debug ID into the bundle and returns the modified bundle.\n *\n * Access it via `options.sentryBundleCallback` in your custom serializer.\n */\nfunction createSentryBundleCallback(debugIdModule: Module<VirtualJSOutput> & { setSource: (code: string) => void }) {\n return (bundle: Bundle) => {\n const debugId = calculateDebugId(bundle);\n debugIdModule.setSource(injectDebugId(debugIdModule.getSource().toString(), debugId));\n bundle.pre = injectDebugId(bundle.pre, debugId);\n return bundle;\n };\n}\n\nasync function extractSerializerResult(serializerResult: MetroSerializerOutput): Promise<SerializedBundle> {\n if (typeof serializerResult === 'string') {\n return { code: serializerResult, map: '{}' };\n }\n\n if ('map' in serializerResult) {\n return { code: serializerResult.code, map: serializerResult.map };\n }\n\n const awaitedResult = await serializerResult;\n if (typeof awaitedResult === 'string') {\n return { code: awaitedResult, map: '{}' };\n }\n\n return { code: awaitedResult.code, map: awaitedResult.map };\n}\n\nfunction createDebugIdModule(debugId: string): Module<VirtualJSOutput> & { setSource: (code: string) => void } {\n return createVirtualJSModule(DEBUG_ID_MODULE_PATH, createDebugIdSnippet(debugId));\n}\n\nfunction calculateDebugId(bundle: Bundle): string {\n const hash = crypto.createHash('md5');\n hash.update(bundle.pre);\n for (const [, code] of bundle.modules) {\n hash.update(code);\n }\n hash.update(bundle.post);\n\n const debugId = stringToUUID(hash.digest('hex'));\n return debugId;\n}\n\nfunction injectDebugId(code: string, debugId: string): string {\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n return code.replace(new RegExp(DEBUG_ID_PLACE_HOLDER, 'g'), debugId);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sentryMetroSerializer.js","sourceRoot":"","sources":["../../../src/js/tools/sentryMetroSerializer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiC;AAIjC,mCAMiB;AACjB,gDAAoE;AAIpE,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AAC1D,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAE3C,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AACnD,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC;;GAEG;AACH,SAAgB,6CAA6C,CAAC,EAC5D,UAAU,EACV,OAAO,GAKR;IACC,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,UAAU,CAAC;KACnB;IAED,MAAM,mBAAmB,GAAG,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;IACvG,IAAI,mBAAmB,EAAE;QACvB,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC;QAClF,OAAO,UAAU,CAAC;KACnB;IAED,MAAM,aAAa,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACnD,OAAO,IAAA,qBAAa,EAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAClD,CAAC;AArBD,sGAqBC;AAED;;;;;GAKG;AACI,MAAM,2BAA2B,GAAG,CAAC,gBAAkC,EAAmB,EAAE;IACjG,MAAM,UAAU,GAAG,gBA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oBAAY,EAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,aAAa,CAAC,IAAY,EAAE,OAAe;IAClD,sEAAsE;IACtE,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,qBAAqB,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import * as crypto from 'crypto';\n// eslint-disable-next-line import/no-extraneous-dependencies\nimport type { MixedOutput, Module, ReadOnlyGraph } from 'metro';\nimport type { Bundle, MetroSerializer, MetroSerializerOutput, SerializedBundle, VirtualJSOutput } from './utils';\nimport {\n createDebugIdSnippet,\n createVirtualJSModule,\n determineDebugIdFromBundleSource,\n prependModule,\n stringToUUID,\n} from './utils';\nimport { createDefaultMetroSerializer } from './vendor/metro/utils';\n\ntype SourceMap = Record<string, unknown>;\n\nconst DEBUG_ID_PLACE_HOLDER = '__debug_id_place_holder__';\nconst DEBUG_ID_MODULE_PATH = '__debugid__';\n\nconst SOURCE_MAP_COMMENT = '//# sourceMappingURL=';\nconst DEBUG_ID_COMMENT = '//# debugId=';\n\n/**\n * Adds Sentry Debug ID polyfill module to the bundle.\n */\nexport function unstableBeforeAssetSerializationDebugIdPlugin({\n premodules,\n debugId,\n}: {\n graph: ReadOnlyGraph<MixedOutput>;\n premodules: Module[];\n debugId?: string;\n}): Module[] {\n if (!debugId) {\n return premodules;\n }\n\n const debugIdModuleExists = premodules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) != -1;\n if (debugIdModuleExists) {\n // eslint-disable-next-line no-console\n console.warn('\\n\\nDebug ID module found. Skipping Sentry Debug ID module...\\n\\n');\n return premodules;\n }\n\n const debugIdModule = createDebugIdModule(debugId);\n return prependModule(premodules, debugIdModule);\n}\n\n/**\n * Creates a Metro serializer that adds Debug ID module to the plain bundle.\n * The Debug ID module is a virtual module that provides a debug ID in runtime.\n *\n * RAM Bundles do not support custom serializers.\n */\nexport const createSentryMetroSerializer = (customSerializer?: MetroSerializer): MetroSerializer => {\n const serializer = customSerializer || createDefaultMetroSerializer();\n return async function (entryPoint, preModules, graph, options) {\n if (graph.transformOptions.hot) {\n return serializer(entryPoint, preModules, graph, options);\n }\n\n const debugIdModuleExists = preModules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) != -1;\n if (debugIdModuleExists) {\n // eslint-disable-next-line no-console\n console.warn('Debug ID module found. Skipping Sentry Debug ID module...');\n return serializer(entryPoint, preModules, graph, options);\n }\n\n const debugIdModule = createDebugIdModule(DEBUG_ID_PLACE_HOLDER);\n options.sentryBundleCallback = createSentryBundleCallback(debugIdModule);\n const modifiedPreModules = prependModule(preModules, debugIdModule);\n\n // Run wrapped serializer\n const serializerResult = serializer(entryPoint, modifiedPreModules, graph, options);\n const { code: bundleCode, map: bundleMapString } = await extractSerializerResult(serializerResult);\n\n // Add debug id comment to the bundle\n let debugId = determineDebugIdFromBundleSource(bundleCode);\n if (!debugId) {\n // For lazy-loaded chunks or bundles without the debug ID module,\n // calculate the debug ID from the bundle content.\n // This ensures Metro 0.83.2+ code-split bundles get debug IDs.\n // That needs to be done because when Metro 0.83.2 stopped importing `BabelSourceMapSegment`\n // from `@babel/generator` and defined it locally, it subtly changed the source map output format.\n // https://github.com/facebook/metro/blob/main/packages/metro-source-map/src/source-map.js#L47\n debugId = calculateDebugId(bundleCode);\n // eslint-disable-next-line no-console\n console.log('info ' + `Bundle Debug ID (calculated): ${debugId}`);\n }\n // Only print debug id for command line builds => not hot reload from dev server\n // eslint-disable-next-line no-console\n console.log('info ' + `Bundle Debug ID: ${debugId}`);\n\n const debugIdComment = `${DEBUG_ID_COMMENT}${debugId}`;\n const indexOfSourceMapComment = bundleCode.lastIndexOf(SOURCE_MAP_COMMENT);\n const bundleCodeWithDebugId =\n indexOfSourceMapComment === -1\n ? // If source map comment is missing lets just add the debug id comment\n `${bundleCode}\\n${debugIdComment}`\n : // If source map comment is present lets add the debug id comment before it\n `${bundleCode.substring(0, indexOfSourceMapComment) + debugIdComment}\\n${bundleCode.substring(\n indexOfSourceMapComment,\n )}`;\n\n const bundleMap: SourceMap = JSON.parse(bundleMapString);\n // For now we write both fields until we know what will become the standard - if ever.\n bundleMap['debug_id'] = debugId;\n bundleMap['debugId'] = debugId;\n\n return {\n code: bundleCodeWithDebugId,\n map: JSON.stringify(bundleMap),\n };\n };\n};\n\n/**\n * This function is expected to be called after serializer creates the final bundle object\n * and before the source maps are generated.\n *\n * It injects a debug ID into the bundle and returns the modified bundle.\n *\n * Access it via `options.sentryBundleCallback` in your custom serializer.\n */\nfunction createSentryBundleCallback(debugIdModule: Module<VirtualJSOutput> & { setSource: (code: string) => void }) {\n return (bundle: Bundle) => {\n const debugId = calculateDebugId(bundle.pre, bundle.modules);\n debugIdModule.setSource(injectDebugId(debugIdModule.getSource().toString(), debugId));\n bundle.pre = injectDebugId(bundle.pre, debugId);\n return bundle;\n };\n}\n\nasync function extractSerializerResult(serializerResult: MetroSerializerOutput): Promise<SerializedBundle> {\n if (typeof serializerResult === 'string') {\n return { code: serializerResult, map: '{}' };\n }\n\n if ('map' in serializerResult) {\n return { code: serializerResult.code, map: serializerResult.map };\n }\n\n const awaitedResult = await serializerResult;\n if (typeof awaitedResult === 'string') {\n return { code: awaitedResult, map: '{}' };\n }\n\n return { code: awaitedResult.code, map: awaitedResult.map };\n}\n\nfunction createDebugIdModule(debugId: string): Module<VirtualJSOutput> & { setSource: (code: string) => void } {\n return createVirtualJSModule(DEBUG_ID_MODULE_PATH, createDebugIdSnippet(debugId));\n}\n\nfunction calculateDebugId(bundleCode: string, modules?: Array<[id: number, code: string]>): string {\n const hash = crypto.createHash('md5');\n hash.update(bundleCode);\n if (modules) {\n for (const [, code] of modules) {\n hash.update(code);\n }\n }\n return stringToUUID(hash.digest('hex'));\n}\n\nfunction injectDebugId(code: string, debugId: string): string {\n // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor\n return code.replace(new RegExp(DEBUG_ID_PLACE_HOLDER, 'g'), debugId);\n}\n"]}
|
|
@@ -15,7 +15,8 @@ export interface FramesMeasurements extends Measurements {
|
|
|
15
15
|
}
|
|
16
16
|
export declare const createNativeFramesIntegrations: (enable: boolean | undefined) => Integration | undefined;
|
|
17
17
|
/**
|
|
18
|
-
* Instrumentation to add native slow/frozen frames measurements onto transactions
|
|
18
|
+
* Instrumentation to add native slow/frozen frames measurements onto transactions
|
|
19
|
+
* and frame data (frames.total, frames.slow, frames.frozen) onto all spans.
|
|
19
20
|
*/
|
|
20
21
|
export declare const nativeFramesIntegration: () => Integration;
|
|
21
22
|
//# sourceMappingURL=nativeFrames.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeFrames.d.ts","sourceRoot":"","sources":["../../../../src/js/tracing/integrations/nativeFrames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,WAAW,EAAE,YAAY,EAAE,eAAe,EAAQ,MAAM,cAAc,CAAC;AAkCpG,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,YAAY,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC;IACvD,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC;IACtD,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC;CACzD;AAOD,eAAO,MAAM,8BAA8B,WAAY,OAAO,GAAG,SAAS,KAAG,WAAW,GAAG,SAQ1F,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"nativeFrames.d.ts","sourceRoot":"","sources":["../../../../src/js/tracing/integrations/nativeFrames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,WAAW,EAAE,YAAY,EAAE,eAAe,EAAQ,MAAM,cAAc,CAAC;AAkCpG,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,YAAY,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC;IACvD,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC;IACtD,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC;CACzD;AAOD,eAAO,MAAM,8BAA8B,WAAY,OAAO,GAAG,SAAS,KAAG,WAAW,GAAG,SAQ1F,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,QAAO,WAgN1C,CAAC"}
|
|
@@ -42,7 +42,8 @@ export const createNativeFramesIntegrations = (enable) => {
|
|
|
42
42
|
return nativeFramesIntegration();
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
|
-
* Instrumentation to add native slow/frozen frames measurements onto transactions
|
|
45
|
+
* Instrumentation to add native slow/frozen frames measurements onto transactions
|
|
46
|
+
* and frame data (frames.total, frames.slow, frames.frozen) onto all spans.
|
|
46
47
|
*/
|
|
47
48
|
export const nativeFramesIntegration = () => {
|
|
48
49
|
/** The native frames at the finish time of the most recent span. */
|
|
@@ -63,12 +64,10 @@ export const nativeFramesIntegration = () => {
|
|
|
63
64
|
client.on('spanStart', fetchStartFramesForSpan);
|
|
64
65
|
client.on('spanEnd', fetchEndFramesForSpan);
|
|
65
66
|
};
|
|
66
|
-
const fetchStartFramesForSpan = (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
const spanId = rootSpan.spanContext().spanId;
|
|
71
|
-
debug.log(`[${INTEGRATION_NAME}] Fetching frames for root span start (${spanId}).`);
|
|
67
|
+
const fetchStartFramesForSpan = (span) => {
|
|
68
|
+
const spanId = span.spanContext().spanId;
|
|
69
|
+
const spanType = isRootSpan(span) ? 'root' : 'child';
|
|
70
|
+
debug.log(`[${INTEGRATION_NAME}] Fetching frames for ${spanType} span start (${spanId}).`);
|
|
72
71
|
_spanToNativeFramesAtStartMap.set(spanId, new Promise(resolve => {
|
|
73
72
|
fetchNativeFrames()
|
|
74
73
|
.then(frames => resolve(frames))
|
|
@@ -78,15 +77,24 @@ export const nativeFramesIntegration = () => {
|
|
|
78
77
|
});
|
|
79
78
|
}));
|
|
80
79
|
};
|
|
81
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Fetches end frames for a span and attaches frame data as span attributes.
|
|
82
|
+
*
|
|
83
|
+
* Note: This makes one native bridge call per span end. While this creates O(n) calls
|
|
84
|
+
* for n spans, it's necessary for accuracy. Frame counts are cumulative and continuously
|
|
85
|
+
* incrementing, so each span needs the exact frame count at its end time. Caching would
|
|
86
|
+
* produce incorrect deltas. The native bridge calls are async and non-blocking.
|
|
87
|
+
*/
|
|
88
|
+
const fetchEndFramesForSpan = (span) => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
89
|
const timestamp = timestampInSeconds();
|
|
83
90
|
const spanId = span.spanContext().spanId;
|
|
91
|
+
const hasStartFrames = _spanToNativeFramesAtStartMap.has(spanId);
|
|
92
|
+
if (!hasStartFrames) {
|
|
93
|
+
// We don't have start frames, won't be able to calculate the difference.
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
84
96
|
if (isRootSpan(span)) {
|
|
85
|
-
|
|
86
|
-
if (!hasStartFrames) {
|
|
87
|
-
// We don't have start frames, won't be able to calculate the difference.
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
97
|
+
// Root spans: Store end frames for transaction measurements (backward compatibility)
|
|
90
98
|
debug.log(`[${INTEGRATION_NAME}] Fetch frames for root span end (${spanId}).`);
|
|
91
99
|
_spanToNativeFramesAtEndMap.set(spanId, new Promise(resolve => {
|
|
92
100
|
fetchNativeFrames()
|
|
@@ -101,20 +109,41 @@ export const nativeFramesIntegration = () => {
|
|
|
101
109
|
resolve(null);
|
|
102
110
|
});
|
|
103
111
|
}));
|
|
104
|
-
return undefined;
|
|
105
112
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
// All spans (root and child): Attach frame data as span attributes
|
|
114
|
+
try {
|
|
115
|
+
const startFrames = yield _spanToNativeFramesAtStartMap.get(spanId);
|
|
116
|
+
if (!startFrames) {
|
|
117
|
+
debug.log(`[${INTEGRATION_NAME}] No start frames found for span ${spanId}, skipping frame data.`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// NOTE: For root spans, this is the second call to fetchNativeFrames() for the same span.
|
|
121
|
+
// The calls are very close together (microseconds apart), so inconsistency is minimal.
|
|
122
|
+
// Future optimization: reuse the first call's promise to avoid redundant native bridge call.
|
|
123
|
+
const endFrames = yield fetchNativeFrames();
|
|
124
|
+
// Calculate deltas
|
|
125
|
+
const totalFrames = endFrames.totalFrames - startFrames.totalFrames;
|
|
126
|
+
const slowFrames = endFrames.slowFrames - startFrames.slowFrames;
|
|
127
|
+
const frozenFrames = endFrames.frozenFrames - startFrames.frozenFrames;
|
|
128
|
+
// Only attach if we have meaningful data
|
|
129
|
+
if (totalFrames > 0 || slowFrames > 0 || frozenFrames > 0) {
|
|
130
|
+
span.setAttribute('frames.total', totalFrames);
|
|
131
|
+
span.setAttribute('frames.slow', slowFrames);
|
|
132
|
+
span.setAttribute('frames.frozen', frozenFrames);
|
|
133
|
+
debug.log(`[${INTEGRATION_NAME}] Attached frame data to span ${spanId}: total=${totalFrames}, slow=${slowFrames}, frozen=${frozenFrames}`);
|
|
134
|
+
}
|
|
135
|
+
// Update last child span end frames for root span fallback logic
|
|
136
|
+
if (!isRootSpan(span)) {
|
|
110
137
|
_lastChildSpanEndFrames = {
|
|
111
138
|
timestamp,
|
|
112
|
-
nativeFrames:
|
|
139
|
+
nativeFrames: endFrames,
|
|
113
140
|
};
|
|
114
|
-
}
|
|
115
|
-
.catch(error => debug.log(`[${INTEGRATION_NAME}] Error while fetching native frames.`, error));
|
|
141
|
+
}
|
|
116
142
|
}
|
|
117
|
-
|
|
143
|
+
catch (error) {
|
|
144
|
+
debug.log(`[${INTEGRATION_NAME}] Error while capturing end frames for span ${spanId}.`, error);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
118
147
|
const processEvent = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
148
|
var _a;
|
|
120
149
|
if (event.type !== 'transaction' ||
|
|
@@ -181,8 +210,20 @@ export const nativeFramesIntegration = () => {
|
|
|
181
210
|
};
|
|
182
211
|
function fetchNativeFrames() {
|
|
183
212
|
return new Promise((resolve, reject) => {
|
|
213
|
+
let settled = false;
|
|
214
|
+
const timeoutId = setTimeout(() => {
|
|
215
|
+
if (!settled) {
|
|
216
|
+
settled = true;
|
|
217
|
+
reject('Fetching native frames took too long. Dropping frames.');
|
|
218
|
+
}
|
|
219
|
+
}, FETCH_FRAMES_TIMEOUT_MS);
|
|
184
220
|
NATIVE.fetchNativeFrames()
|
|
185
221
|
.then(value => {
|
|
222
|
+
if (settled) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
clearTimeout(timeoutId);
|
|
226
|
+
settled = true;
|
|
186
227
|
if (!value) {
|
|
187
228
|
reject('Native frames response is null.');
|
|
188
229
|
return;
|
|
@@ -190,11 +231,13 @@ function fetchNativeFrames() {
|
|
|
190
231
|
resolve(value);
|
|
191
232
|
})
|
|
192
233
|
.then(undefined, error => {
|
|
234
|
+
if (settled) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
clearTimeout(timeoutId);
|
|
238
|
+
settled = true;
|
|
193
239
|
reject(error);
|
|
194
240
|
});
|
|
195
|
-
setTimeout(() => {
|
|
196
|
-
reject('Fetching native frames took too long. Dropping frames.');
|
|
197
|
-
}, FETCH_FRAMES_TIMEOUT_MS);
|
|
198
241
|
});
|
|
199
242
|
}
|
|
200
243
|
function isClose(t1, t2) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeFrames.js","sourceRoot":"","sources":["../../../../src/js/tracing/integrations/nativeFrames.ts"],"names":[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K,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;QAEL,UAAU,CAAC,GAAG,EAAE;YACd,MAAM,CAAC,wDAAwD,CAAC,CAAC;QACnE,CAAC,EAAE,uBAAuB,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,EAAU,EAAE,EAAU;IACrC,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,uBAAuB,CAAC;AACrD,CAAC","sourcesContent":["import type { Client, Event, Integration, Measurements, MeasurementUnit, Span } from '@sentry/core';\nimport { debug, timestampInSeconds } from '@sentry/core';\nimport type { NativeFramesResponse } from '../../NativeRNSentry';\nimport { AsyncExpiringMap } from '../../utils/AsyncExpiringMap';\nimport { isRootSpan } from '../../utils/span';\nimport { NATIVE } from '../../wrapper';\n\n/**\n * Timeout from the start of a span to fetching the associated native frames.\n */\nconst FETCH_FRAMES_TIMEOUT_MS = 2_000;\n\n/**\n * This is the time end frames data from the native layer will be\n * kept in memory and waiting for the event processing. This ensures that spans\n * which are never processed are not leaking memory.\n */\nconst END_FRAMES_TIMEOUT_MS = 2_000;\n\n/**\n * This is the time start frames data from the native layer will be\n * kept in memory and waiting for span end. This ensures that spans\n * which never end or are not processed are not leaking memory.\n */\nconst START_FRAMES_TIMEOUT_MS = 60_000;\n\n/**\n * A margin of error of 50ms is allowed for the async native bridge call.\n * Anything larger would reduce the accuracy of our frames measurements.\n */\nconst MARGIN_OF_ERROR_SECONDS = 0.05;\n\nconst INTEGRATION_NAME = 'NativeFrames';\n\nexport interface FramesMeasurements extends Measurements {\n frames_total: { value: number; unit: MeasurementUnit };\n frames_slow: { value: number; unit: MeasurementUnit };\n frames_frozen: { value: number; unit: MeasurementUnit };\n}\n\ninterface NativeFramesResponseWithTimestamp {\n timestamp: number;\n nativeFrames: NativeFramesResponse;\n}\n\nexport const createNativeFramesIntegrations = (enable: boolean | undefined): Integration | undefined => {\n if (!enable && NATIVE.enableNative) {\n // On Android this will free up resource when JS reloaded (native modules stay) and thus JS side of the SDK reinitialized.\n NATIVE.disableNativeFramesTracking();\n return undefined;\n }\n\n return nativeFramesIntegration();\n};\n\n/**\n * Instrumentation to add native slow/frozen frames measurements onto transactions.\n */\nexport const nativeFramesIntegration = (): Integration => {\n /** The native frames at the finish time of the most recent span. */\n let _lastChildSpanEndFrames: NativeFramesResponseWithTimestamp | null = null;\n const _spanToNativeFramesAtStartMap: AsyncExpiringMap<string, NativeFramesResponse | null> = new AsyncExpiringMap({\n ttl: START_FRAMES_TIMEOUT_MS,\n });\n const _spanToNativeFramesAtEndMap: AsyncExpiringMap<string, NativeFramesResponseWithTimestamp | null> =\n new AsyncExpiringMap({ ttl: END_FRAMES_TIMEOUT_MS });\n\n /**\n * Hooks into the client start and end span events.\n */\n const setup = (client: Client): void => {\n if (!NATIVE.enableNative) {\n debug.warn(\n `[${INTEGRATION_NAME}] This is not available on the Web, Expo Go and other platforms without native modules.`,\n );\n return undefined;\n }\n\n NATIVE.enableNativeFramesTracking();\n client.on('spanStart', fetchStartFramesForSpan);\n client.on('spanEnd', fetchEndFramesForSpan);\n };\n\n const fetchStartFramesForSpan = (rootSpan: Span): void => {\n if (!isRootSpan(rootSpan)) {\n return;\n }\n\n const spanId = rootSpan.spanContext().spanId;\n debug.log(`[${INTEGRATION_NAME}] Fetching frames for root span start (${spanId}).`);\n _spanToNativeFramesAtStartMap.set(\n spanId,\n new Promise<NativeFramesResponse | null>(resolve => {\n fetchNativeFrames()\n .then(frames => resolve(frames))\n .then(undefined, error => {\n debug.log(`[${INTEGRATION_NAME}] Error while fetching native frames.`, error);\n resolve(null);\n });\n }),\n );\n };\n\n const fetchEndFramesForSpan = (span: Span): void => {\n const timestamp = timestampInSeconds();\n const spanId = span.spanContext().spanId;\n\n if (isRootSpan(span)) {\n const hasStartFrames = _spanToNativeFramesAtStartMap.has(spanId);\n if (!hasStartFrames) {\n // We don't have start frames, won't be able to calculate the difference.\n return;\n }\n\n debug.log(`[${INTEGRATION_NAME}] Fetch frames for root span end (${spanId}).`);\n _spanToNativeFramesAtEndMap.set(\n spanId,\n new Promise<NativeFramesResponseWithTimestamp | null>(resolve => {\n fetchNativeFrames()\n .then(frames => {\n resolve({\n timestamp,\n nativeFrames: frames,\n });\n })\n .then(undefined, error => {\n debug.log(`[${INTEGRATION_NAME}] Error while fetching native frames.`, error);\n resolve(null);\n });\n }),\n );\n return undefined;\n } else {\n debug.log(`[${INTEGRATION_NAME}] Fetch frames for child span end (${spanId}).`);\n fetchNativeFrames()\n .then(frames => {\n _lastChildSpanEndFrames = {\n timestamp,\n nativeFrames: frames,\n };\n })\n .catch(error => debug.log(`[${INTEGRATION_NAME}] Error while fetching native frames.`, error));\n }\n };\n\n const processEvent = async (event: Event): Promise<Event> => {\n if (\n event.type !== 'transaction' ||\n !event.transaction ||\n !event.contexts ||\n !event.contexts.trace ||\n !event.timestamp ||\n !event.contexts.trace.span_id\n ) {\n return event;\n }\n\n const traceOp = event.contexts.trace.op;\n const spanId = event.contexts.trace.span_id;\n const startFrames = await _spanToNativeFramesAtStartMap.pop(spanId);\n if (!startFrames) {\n debug.warn(\n `[${INTEGRATION_NAME}] Start frames of transaction ${event.transaction} (eventId, ${event.event_id}) are missing, but the transaction already ended.`,\n );\n return event;\n }\n\n const endFrames = await _spanToNativeFramesAtEndMap.pop(spanId);\n let finalEndFrames: NativeFramesResponse | undefined;\n\n if (endFrames && isClose(endFrames.timestamp, event.timestamp)) {\n // Must be in the margin of error of the actual transaction finish time (finalEndTimestamp)\n debug.log(`[${INTEGRATION_NAME}] Using frames from root span end (spanId, ${spanId}).`);\n finalEndFrames = endFrames.nativeFrames;\n } else if (_lastChildSpanEndFrames && isClose(_lastChildSpanEndFrames.timestamp, event.timestamp)) {\n // Fallback to the last span finish if it is within the margin of error of the actual finish timestamp.\n // This should be the case for trimEnd.\n debug.log(`[${INTEGRATION_NAME}] Using native frames from last child span end (spanId, ${spanId}).`);\n finalEndFrames = _lastChildSpanEndFrames.nativeFrames;\n } else {\n debug.warn(\n `[${INTEGRATION_NAME}] Frames were collected within larger than margin of error delay for spanId (${spanId}). Dropping the inaccurate values.`,\n );\n return event;\n }\n\n const measurements = {\n frames_total: {\n value: finalEndFrames.totalFrames - startFrames.totalFrames,\n unit: 'none',\n },\n frames_frozen: {\n value: finalEndFrames.frozenFrames - startFrames.frozenFrames,\n unit: 'none',\n },\n frames_slow: {\n value: finalEndFrames.slowFrames - startFrames.slowFrames,\n unit: 'none',\n },\n };\n\n if (\n measurements.frames_frozen.value <= 0 &&\n measurements.frames_slow.value <= 0 &&\n measurements.frames_total.value <= 0\n ) {\n debug.warn(\n `[${INTEGRATION_NAME}] Detected zero slow or frozen frames. Not adding measurements to spanId (${spanId}).`,\n );\n return event;\n }\n\n debug.log(\n `[${INTEGRATION_NAME}] Adding measurements to ${traceOp} transaction ${event.transaction}: ${JSON.stringify(\n measurements,\n undefined,\n 2,\n )}`,\n );\n event.measurements = {\n ...(event.measurements ?? {}),\n ...measurements,\n };\n return event;\n };\n\n return {\n name: INTEGRATION_NAME,\n setup,\n processEvent,\n };\n};\n\nfunction fetchNativeFrames(): Promise<NativeFramesResponse> {\n return new Promise<NativeFramesResponse>((resolve, reject) => {\n NATIVE.fetchNativeFrames()\n .then(value => {\n if (!value) {\n reject('Native frames response is null.');\n return;\n }\n resolve(value);\n })\n .then(undefined, error => {\n reject(error);\n });\n\n setTimeout(() => {\n reject('Fetching native frames took too long. Dropping frames.');\n }, FETCH_FRAMES_TIMEOUT_MS);\n });\n}\n\nfunction isClose(t1: number, t2: number): boolean {\n return Math.abs(t1 - t2) < MARGIN_OF_ERROR_SECONDS;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nativeFrames.js","sourceRoot":"","sources":["../../../../src/js/tracing/integrations/nativeFrames.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,gBAAg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AG,IAAI,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,EAAU,EAAE,EAAU;IACrC,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,uBAAuB,CAAC;AACrD,CAAC","sourcesContent":["import type { Client, Event, Integration, Measurements, MeasurementUnit, Span } from '@sentry/core';\nimport { debug, timestampInSeconds } from '@sentry/core';\nimport type { NativeFramesResponse } from '../../NativeRNSentry';\nimport { AsyncExpiringMap } from '../../utils/AsyncExpiringMap';\nimport { isRootSpan } from '../../utils/span';\nimport { NATIVE } from '../../wrapper';\n\n/**\n * Timeout from the start of a span to fetching the associated native frames.\n */\nconst FETCH_FRAMES_TIMEOUT_MS = 2_000;\n\n/**\n * This is the time end frames data from the native layer will be\n * kept in memory and waiting for the event processing. This ensures that spans\n * which are never processed are not leaking memory.\n */\nconst END_FRAMES_TIMEOUT_MS = 2_000;\n\n/**\n * This is the time start frames data from the native layer will be\n * kept in memory and waiting for span end. This ensures that spans\n * which never end or are not processed are not leaking memory.\n */\nconst START_FRAMES_TIMEOUT_MS = 60_000;\n\n/**\n * A margin of error of 50ms is allowed for the async native bridge call.\n * Anything larger would reduce the accuracy of our frames measurements.\n */\nconst MARGIN_OF_ERROR_SECONDS = 0.05;\n\nconst INTEGRATION_NAME = 'NativeFrames';\n\nexport interface FramesMeasurements extends Measurements {\n frames_total: { value: number; unit: MeasurementUnit };\n frames_slow: { value: number; unit: MeasurementUnit };\n frames_frozen: { value: number; unit: MeasurementUnit };\n}\n\ninterface NativeFramesResponseWithTimestamp {\n timestamp: number;\n nativeFrames: NativeFramesResponse;\n}\n\nexport const createNativeFramesIntegrations = (enable: boolean | undefined): Integration | undefined => {\n if (!enable && NATIVE.enableNative) {\n // On Android this will free up resource when JS reloaded (native modules stay) and thus JS side of the SDK reinitialized.\n NATIVE.disableNativeFramesTracking();\n return undefined;\n }\n\n return nativeFramesIntegration();\n};\n\n/**\n * Instrumentation to add native slow/frozen frames measurements onto transactions\n * and frame data (frames.total, frames.slow, frames.frozen) onto all spans.\n */\nexport const nativeFramesIntegration = (): Integration => {\n /** The native frames at the finish time of the most recent span. */\n let _lastChildSpanEndFrames: NativeFramesResponseWithTimestamp | null = null;\n const _spanToNativeFramesAtStartMap: AsyncExpiringMap<string, NativeFramesResponse | null> = new AsyncExpiringMap({\n ttl: START_FRAMES_TIMEOUT_MS,\n });\n const _spanToNativeFramesAtEndMap: AsyncExpiringMap<string, NativeFramesResponseWithTimestamp | null> =\n new AsyncExpiringMap({ ttl: END_FRAMES_TIMEOUT_MS });\n\n /**\n * Hooks into the client start and end span events.\n */\n const setup = (client: Client): void => {\n if (!NATIVE.enableNative) {\n debug.warn(\n `[${INTEGRATION_NAME}] This is not available on the Web, Expo Go and other platforms without native modules.`,\n );\n return undefined;\n }\n\n NATIVE.enableNativeFramesTracking();\n client.on('spanStart', fetchStartFramesForSpan);\n client.on('spanEnd', fetchEndFramesForSpan);\n };\n\n const fetchStartFramesForSpan = (span: Span): void => {\n const spanId = span.spanContext().spanId;\n const spanType = isRootSpan(span) ? 'root' : 'child';\n debug.log(`[${INTEGRATION_NAME}] Fetching frames for ${spanType} span start (${spanId}).`);\n\n _spanToNativeFramesAtStartMap.set(\n spanId,\n new Promise<NativeFramesResponse | null>(resolve => {\n fetchNativeFrames()\n .then(frames => resolve(frames))\n .then(undefined, error => {\n debug.log(`[${INTEGRATION_NAME}] Error while fetching native frames.`, error);\n resolve(null);\n });\n }),\n );\n };\n\n /**\n * Fetches end frames for a span and attaches frame data as span attributes.\n *\n * Note: This makes one native bridge call per span end. While this creates O(n) calls\n * for n spans, it's necessary for accuracy. Frame counts are cumulative and continuously\n * incrementing, so each span needs the exact frame count at its end time. Caching would\n * produce incorrect deltas. The native bridge calls are async and non-blocking.\n */\n const fetchEndFramesForSpan = async (span: Span): Promise<void> => {\n const timestamp = timestampInSeconds();\n const spanId = span.spanContext().spanId;\n const hasStartFrames = _spanToNativeFramesAtStartMap.has(spanId);\n\n if (!hasStartFrames) {\n // We don't have start frames, won't be able to calculate the difference.\n return;\n }\n\n if (isRootSpan(span)) {\n // Root spans: Store end frames for transaction measurements (backward compatibility)\n debug.log(`[${INTEGRATION_NAME}] Fetch frames for root span end (${spanId}).`);\n _spanToNativeFramesAtEndMap.set(\n spanId,\n new Promise<NativeFramesResponseWithTimestamp | null>(resolve => {\n fetchNativeFrames()\n .then(frames => {\n resolve({\n timestamp,\n nativeFrames: frames,\n });\n })\n .then(undefined, error => {\n debug.log(`[${INTEGRATION_NAME}] Error while fetching native frames.`, error);\n resolve(null);\n });\n }),\n );\n }\n\n // All spans (root and child): Attach frame data as span attributes\n try {\n const startFrames = await _spanToNativeFramesAtStartMap.get(spanId);\n if (!startFrames) {\n debug.log(`[${INTEGRATION_NAME}] No start frames found for span ${spanId}, skipping frame data.`);\n return;\n }\n\n // NOTE: For root spans, this is the second call to fetchNativeFrames() for the same span.\n // The calls are very close together (microseconds apart), so inconsistency is minimal.\n // Future optimization: reuse the first call's promise to avoid redundant native bridge call.\n const endFrames = await fetchNativeFrames();\n\n // Calculate deltas\n const totalFrames = endFrames.totalFrames - startFrames.totalFrames;\n const slowFrames = endFrames.slowFrames - startFrames.slowFrames;\n const frozenFrames = endFrames.frozenFrames - startFrames.frozenFrames;\n\n // Only attach if we have meaningful data\n if (totalFrames > 0 || slowFrames > 0 || frozenFrames > 0) {\n span.setAttribute('frames.total', totalFrames);\n span.setAttribute('frames.slow', slowFrames);\n span.setAttribute('frames.frozen', frozenFrames);\n debug.log(\n `[${INTEGRATION_NAME}] Attached frame data to span ${spanId}: total=${totalFrames}, slow=${slowFrames}, frozen=${frozenFrames}`,\n );\n }\n\n // Update last child span end frames for root span fallback logic\n if (!isRootSpan(span)) {\n _lastChildSpanEndFrames = {\n timestamp,\n nativeFrames: endFrames,\n };\n }\n } catch (error) {\n debug.log(`[${INTEGRATION_NAME}] Error while capturing end frames for span ${spanId}.`, error);\n }\n };\n\n const processEvent = async (event: Event): Promise<Event> => {\n if (\n event.type !== 'transaction' ||\n !event.transaction ||\n !event.contexts ||\n !event.contexts.trace ||\n !event.timestamp ||\n !event.contexts.trace.span_id\n ) {\n return event;\n }\n\n const traceOp = event.contexts.trace.op;\n const spanId = event.contexts.trace.span_id;\n const startFrames = await _spanToNativeFramesAtStartMap.pop(spanId);\n if (!startFrames) {\n debug.warn(\n `[${INTEGRATION_NAME}] Start frames of transaction ${event.transaction} (eventId, ${event.event_id}) are missing, but the transaction already ended.`,\n );\n return event;\n }\n\n const endFrames = await _spanToNativeFramesAtEndMap.pop(spanId);\n let finalEndFrames: NativeFramesResponse | undefined;\n\n if (endFrames && isClose(endFrames.timestamp, event.timestamp)) {\n // Must be in the margin of error of the actual transaction finish time (finalEndTimestamp)\n debug.log(`[${INTEGRATION_NAME}] Using frames from root span end (spanId, ${spanId}).`);\n finalEndFrames = endFrames.nativeFrames;\n } else if (_lastChildSpanEndFrames && isClose(_lastChildSpanEndFrames.timestamp, event.timestamp)) {\n // Fallback to the last span finish if it is within the margin of error of the actual finish timestamp.\n // This should be the case for trimEnd.\n debug.log(`[${INTEGRATION_NAME}] Using native frames from last child span end (spanId, ${spanId}).`);\n finalEndFrames = _lastChildSpanEndFrames.nativeFrames;\n } else {\n debug.warn(\n `[${INTEGRATION_NAME}] Frames were collected within larger than margin of error delay for spanId (${spanId}). Dropping the inaccurate values.`,\n );\n return event;\n }\n\n const measurements = {\n frames_total: {\n value: finalEndFrames.totalFrames - startFrames.totalFrames,\n unit: 'none',\n },\n frames_frozen: {\n value: finalEndFrames.frozenFrames - startFrames.frozenFrames,\n unit: 'none',\n },\n frames_slow: {\n value: finalEndFrames.slowFrames - startFrames.slowFrames,\n unit: 'none',\n },\n };\n\n if (\n measurements.frames_frozen.value <= 0 &&\n measurements.frames_slow.value <= 0 &&\n measurements.frames_total.value <= 0\n ) {\n debug.warn(\n `[${INTEGRATION_NAME}] Detected zero slow or frozen frames. Not adding measurements to spanId (${spanId}).`,\n );\n return event;\n }\n\n debug.log(\n `[${INTEGRATION_NAME}] Adding measurements to ${traceOp} transaction ${event.transaction}: ${JSON.stringify(\n measurements,\n undefined,\n 2,\n )}`,\n );\n event.measurements = {\n ...(event.measurements ?? {}),\n ...measurements,\n };\n return event;\n };\n\n return {\n name: INTEGRATION_NAME,\n setup,\n processEvent,\n };\n};\n\nfunction fetchNativeFrames(): Promise<NativeFramesResponse> {\n return new Promise<NativeFramesResponse>((resolve, reject) => {\n let settled = false;\n\n const timeoutId = setTimeout(() => {\n if (!settled) {\n settled = true;\n reject('Fetching native frames took too long. Dropping frames.');\n }\n }, FETCH_FRAMES_TIMEOUT_MS);\n\n NATIVE.fetchNativeFrames()\n .then(value => {\n if (settled) {\n return;\n }\n clearTimeout(timeoutId);\n settled = true;\n\n if (!value) {\n reject('Native frames response is null.');\n return;\n }\n resolve(value);\n })\n .then(undefined, error => {\n if (settled) {\n return;\n }\n clearTimeout(timeoutId);\n settled = true;\n reject(error);\n });\n });\n}\n\nfunction isClose(t1: number, t2: number): boolean {\n return Math.abs(t1 - t2) < MARGIN_OF_ERROR_SECONDS;\n}\n"]}
|
|
@@ -5,6 +5,15 @@ import type { Client, Span } from '@sentry/core';
|
|
|
5
5
|
export declare function onThisSpanEnd(client: Client, span: Span, callback: (span: Span) => void): void;
|
|
6
6
|
export declare const adjustTransactionDuration: (client: Client, span: Span, maxDurationMs: number) => void;
|
|
7
7
|
export declare const ignoreEmptyBackNavigation: (client: Client | undefined, span: Span | undefined) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Discards empty "Route Change" transactions that never received route information.
|
|
10
|
+
* This happens when navigation library emits a route change event but getCurrentRoute() returns undefined.
|
|
11
|
+
* Such transactions don't contain any useful information and should not be sent to Sentry.
|
|
12
|
+
*
|
|
13
|
+
* This function must be called with a reference tracker function that can check if the span
|
|
14
|
+
* was cleared from the integration's tracking (indicating it went through the state listener).
|
|
15
|
+
*/
|
|
16
|
+
export declare const ignoreEmptyRouteChangeTransactions: (client: Client | undefined, span: Span | undefined, defaultNavigationSpanName: string, isSpanStillTracked: () => boolean) => void;
|
|
8
17
|
/**
|
|
9
18
|
* Idle Transaction callback to only sample transactions with child spans.
|
|
10
19
|
* To avoid side effects of other callbacks this should be hooked as the last callback.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onSpanEndUtils.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/onSpanEndUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAMjD;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,GAAG,IAAI,CAO9F;AAED,eAAO,MAAM,yBAAyB,WAAY,MAAM,QAAQ,IAAI,iBAAiB,MAAM,KAAG,IAyB7F,CAAC;
|
|
1
|
+
{"version":3,"file":"onSpanEndUtils.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/onSpanEndUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAMjD;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,GAAG,IAAI,CAO9F;AAED,eAAO,MAAM,yBAAyB,WAAY,MAAM,QAAQ,IAAI,iBAAiB,MAAM,KAAG,IAyB7F,CAAC;AAwDF,eAAO,MAAM,yBAAyB,WAAY,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG,SAAS,KAAG,IAa9F,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kCAAkC,WACrC,MAAM,GAAG,SAAS,QACpB,IAAI,GAAG,SAAS,6BACK,MAAM,sBACb,MAAM,OAAO,KAChC,IAoBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,WAAY,MAAM,QAAQ,IAAI,KAAG,IAmBnE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,WAAY,MAAM,QAAQ,IAAI,KAAG,IAgB/D,CAAC"}
|
|
@@ -35,7 +35,19 @@ export const adjustTransactionDuration = (client, span, maxDurationMs) => {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Helper function to filter out auto-instrumentation child spans.
|
|
40
|
+
*/
|
|
41
|
+
function getMeaningfulChildSpans(span) {
|
|
42
|
+
const children = getSpanDescendants(span);
|
|
43
|
+
return children.filter(child => child.spanContext().spanId !== span.spanContext().spanId &&
|
|
44
|
+
spanToJSON(child).op !== 'ui.load.initial_display' &&
|
|
45
|
+
spanToJSON(child).op !== 'navigation.processing');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generic helper to discard empty navigation spans based on a condition.
|
|
49
|
+
*/
|
|
50
|
+
function discardEmptyNavigationSpan(client, span, shouldDiscardFn, onDiscardFn) {
|
|
39
51
|
if (!client) {
|
|
40
52
|
debug.warn('Could not hook on spanEnd event because client is not defined.');
|
|
41
53
|
return;
|
|
@@ -45,28 +57,56 @@ export const ignoreEmptyBackNavigation = (client, span) => {
|
|
|
45
57
|
return;
|
|
46
58
|
}
|
|
47
59
|
if (!isRootSpan(span) || !isSentrySpan(span)) {
|
|
48
|
-
debug.warn('Not sampling empty
|
|
60
|
+
debug.warn('Not sampling empty navigation spans only works for Sentry Transactions (Root Spans).');
|
|
49
61
|
return;
|
|
50
62
|
}
|
|
51
63
|
client.on('spanEnd', (endedSpan) => {
|
|
52
|
-
var _a;
|
|
53
64
|
if (endedSpan !== span) {
|
|
54
65
|
return;
|
|
55
66
|
}
|
|
56
|
-
if (!(
|
|
67
|
+
if (!shouldDiscardFn(span)) {
|
|
57
68
|
return;
|
|
58
69
|
}
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
spanToJSON(child).op !== 'navigation.processing');
|
|
63
|
-
if (filtered.length <= 0) {
|
|
64
|
-
// filter children must include at least one span not created by the navigation automatic instrumentation
|
|
65
|
-
debug.log('Not sampling transaction as route has been seen before. Pass ignoreEmptyBackNavigationTransactions = false to disable this feature.');
|
|
66
|
-
// Route has been seen before and has no child spans.
|
|
70
|
+
const meaningfulChildren = getMeaningfulChildSpans(span);
|
|
71
|
+
if (meaningfulChildren.length <= 0) {
|
|
72
|
+
onDiscardFn(span);
|
|
67
73
|
span['_sampled'] = false;
|
|
68
74
|
}
|
|
69
75
|
});
|
|
76
|
+
}
|
|
77
|
+
export const ignoreEmptyBackNavigation = (client, span) => {
|
|
78
|
+
discardEmptyNavigationSpan(client, span,
|
|
79
|
+
// Only discard if route has been seen before
|
|
80
|
+
span => { var _a; return ((_a = spanToJSON(span).data) === null || _a === void 0 ? void 0 : _a['route.has_been_seen']) === true; },
|
|
81
|
+
// Log message when discarding
|
|
82
|
+
() => {
|
|
83
|
+
debug.log('Not sampling transaction as route has been seen before. Pass ignoreEmptyBackNavigationTransactions = false to disable this feature.');
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Discards empty "Route Change" transactions that never received route information.
|
|
88
|
+
* This happens when navigation library emits a route change event but getCurrentRoute() returns undefined.
|
|
89
|
+
* Such transactions don't contain any useful information and should not be sent to Sentry.
|
|
90
|
+
*
|
|
91
|
+
* This function must be called with a reference tracker function that can check if the span
|
|
92
|
+
* was cleared from the integration's tracking (indicating it went through the state listener).
|
|
93
|
+
*/
|
|
94
|
+
export const ignoreEmptyRouteChangeTransactions = (client, span, defaultNavigationSpanName, isSpanStillTracked) => {
|
|
95
|
+
discardEmptyNavigationSpan(client, span,
|
|
96
|
+
// Only discard if:
|
|
97
|
+
// 1. Still has default name
|
|
98
|
+
// 2. No route information was set
|
|
99
|
+
// 3. Still being tracked (state listener never called)
|
|
100
|
+
span => {
|
|
101
|
+
var _a;
|
|
102
|
+
const spanJSON = spanToJSON(span);
|
|
103
|
+
return (spanJSON.description === defaultNavigationSpanName && !((_a = spanJSON.data) === null || _a === void 0 ? void 0 : _a['route.name']) && isSpanStillTracked());
|
|
104
|
+
},
|
|
105
|
+
// Log and record dropped event
|
|
106
|
+
_span => {
|
|
107
|
+
debug.log(`Discarding empty "${defaultNavigationSpanName}" transaction that never received route information.`);
|
|
108
|
+
client === null || client === void 0 ? void 0 : client.recordDroppedEvent('sample_rate', 'transaction');
|
|
109
|
+
});
|
|
70
110
|
};
|
|
71
111
|
/**
|
|
72
112
|
* Idle Transaction callback to only sample transactions with child spans.
|