@sentry/react-native 3.3.0 → 3.3.3
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/CHANGELOG.md +21 -0
- package/RNSentry.podspec +1 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/io/sentry/react/RNSentryModule.java +11 -0
- package/dist/js/integrations/devicecontext.d.ts.map +1 -1
- package/dist/js/integrations/devicecontext.js +8 -2
- package/dist/js/integrations/devicecontext.js.map +1 -1
- package/dist/js/options.d.ts +6 -2
- package/dist/js/options.d.ts.map +1 -1
- package/dist/js/options.js.map +1 -1
- package/dist/js/tracing/reactnativenavigation.d.ts.map +1 -1
- package/dist/js/tracing/reactnativenavigation.js +24 -22
- package/dist/js/tracing/reactnativenavigation.js.map +1 -1
- package/dist/js/tracing/reactnavigation.d.ts +1 -1
- package/dist/js/tracing/reactnavigation.js +7 -7
- package/dist/js/tracing/reactnavigation.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/ios/RNSentry.m +37 -9
- package/package.json +1 -1
- package/sentry.gradle +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.3.3
|
|
4
|
+
|
|
5
|
+
- Bump: Sentry Cocoa to 7.10.2 and Sentry Android to 5.6.3 (#2145)
|
|
6
|
+
- fix(android): Upload source maps correctly regardless of version codes #2144
|
|
7
|
+
|
|
8
|
+
## 3.3.2
|
|
9
|
+
|
|
10
|
+
- fix: Do not report empty measurements #1983
|
|
11
|
+
- fix(iOS): Bump Sentry Cocoa to 7.10.1 and report slow and frozen measurements (#2132)
|
|
12
|
+
- fix(iOS): Missing userId on iOS when the user is not set in the Scope (#2133)
|
|
13
|
+
|
|
14
|
+
## 3.3.1
|
|
15
|
+
|
|
16
|
+
- feat: Support setting maxCacheItems #2102
|
|
17
|
+
- fix: Clear transaction on route change for React Native Navigation #2119
|
|
18
|
+
|
|
3
19
|
## 3.3.0
|
|
4
20
|
|
|
5
21
|
- feat: Support enableNativeCrashHandling for iOS #2101
|
|
6
22
|
- Bump: Sentry Cocoa 7.10.0 #2100
|
|
23
|
+
- feat: Touch events now track components with `sentry-label` prop, falls back to `accessibilityLabel` and then finally `displayName`. #2068
|
|
24
|
+
- fix: Respect sentryOption.debug setting instead of #DEBUG build flag for outputting logs #2039
|
|
25
|
+
- fix: Passing correct mutableOptions to iOS SDK (#2037)
|
|
26
|
+
- Bump: Bump @sentry/javascript dependencies to 6.17.9 #2082
|
|
27
|
+
- fix: Discard prior transactions on react navigation dispatch #2053
|
|
7
28
|
|
|
8
29
|
## 3.2.14-beta.2
|
|
9
30
|
|
package/RNSentry.podspec
CHANGED
package/android/build.gradle
CHANGED
|
@@ -100,6 +100,9 @@ public class RNSentryModule extends ReactContextBaseJavaModule {
|
|
|
100
100
|
if (rnOptions.hasKey("maxBreadcrumbs")) {
|
|
101
101
|
options.setMaxBreadcrumbs(rnOptions.getInt("maxBreadcrumbs"));
|
|
102
102
|
}
|
|
103
|
+
if (rnOptions.hasKey("maxCacheItems")) {
|
|
104
|
+
options.setMaxCacheItems(rnOptions.getInt("maxCacheItems"));
|
|
105
|
+
}
|
|
103
106
|
if (rnOptions.hasKey("environment") && rnOptions.getString("environment") != null) {
|
|
104
107
|
options.setEnvironment(rnOptions.getString("environment"));
|
|
105
108
|
}
|
|
@@ -115,6 +118,9 @@ public class RNSentryModule extends ReactContextBaseJavaModule {
|
|
|
115
118
|
if (rnOptions.hasKey("sessionTrackingIntervalMillis")) {
|
|
116
119
|
options.setSessionTrackingIntervalMillis(rnOptions.getInt("sessionTrackingIntervalMillis"));
|
|
117
120
|
}
|
|
121
|
+
if (rnOptions.hasKey("shutdownTimeout")) {
|
|
122
|
+
options.setShutdownTimeout(rnOptions.getInt("shutdownTimeout"));
|
|
123
|
+
}
|
|
118
124
|
if (rnOptions.hasKey("enableNdkScopeSync")) {
|
|
119
125
|
options.setEnableScopeSync(rnOptions.getBoolean("enableNdkScopeSync"));
|
|
120
126
|
}
|
|
@@ -266,6 +272,11 @@ public class RNSentryModule extends ReactContextBaseJavaModule {
|
|
|
266
272
|
}
|
|
267
273
|
}
|
|
268
274
|
|
|
275
|
+
if (totalFrames == 0 && slowFrames == 0 && frozenFrames == 0) {
|
|
276
|
+
promise.resolve(null);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
269
280
|
WritableMap map = Arguments.createMap();
|
|
270
281
|
map.putInt("totalFrames", totalFrames);
|
|
271
282
|
map.putInt("slowFrames", slowFrames);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devicecontext.d.ts","sourceRoot":"","sources":["../../../src/js/integrations/devicecontext.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"devicecontext.d.ts","sourceRoot":"","sources":["../../../src/js/integrations/devicecontext.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,WAAW,EAAE,MAAM,eAAe,CAAC;AAK7D,uCAAuC;AACvC,qBAAa,aAAc,YAAW,WAAW;IAC/C;;OAEG;IACH,OAAc,EAAE,EAAE,MAAM,CAAmB;IAE3C;;OAEG;IACI,IAAI,EAAE,MAAM,CAAoB;IAEvC;;OAEG;IACI,SAAS,IAAI,IAAI;CAyBzB"}
|
|
@@ -15,13 +15,19 @@ export class DeviceContext {
|
|
|
15
15
|
*/
|
|
16
16
|
setupOnce() {
|
|
17
17
|
addGlobalEventProcessor((event) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a, _b;
|
|
18
19
|
const self = getCurrentHub().getIntegration(DeviceContext);
|
|
19
20
|
if (!self) {
|
|
20
21
|
return event;
|
|
21
22
|
}
|
|
22
23
|
try {
|
|
23
|
-
const
|
|
24
|
-
|
|
24
|
+
const contexts = yield NATIVE.fetchNativeDeviceContexts();
|
|
25
|
+
const context = (_a = contexts['context']) !== null && _a !== void 0 ? _a : {};
|
|
26
|
+
const user = (_b = contexts['user']) !== null && _b !== void 0 ? _b : {};
|
|
27
|
+
event.contexts = Object.assign(Object.assign({}, context), event.contexts);
|
|
28
|
+
if (!event.user) {
|
|
29
|
+
event.user = Object.assign({}, user);
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
32
|
catch (e) {
|
|
27
33
|
logger.log(`Failed to get device context from native: ${e}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devicecontext.js","sourceRoot":"","sources":["../../../src/js/integrations/devicecontext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,uCAAuC;AACvC,MAAM,OAAO,aAAa;IAA1B;QAME;;WAEG;QACI,SAAI,GAAW,aAAa,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"devicecontext.js","sourceRoot":"","sources":["../../../src/js/integrations/devicecontext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,uCAAuC;AACvC,MAAM,OAAO,aAAa;IAA1B;QAME;;WAEG;QACI,SAAI,GAAW,aAAa,CAAC,EAAE,CAAC;IA8BzC,CAAC;IA5BC;;OAEG;IACI,SAAS;QACd,uBAAuB,CAAC,CAAO,KAAY,EAAE,EAAE;;YAC7C,MAAM,IAAI,GAAG,aAAa,EAAE,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;YAC3D,IAAI,CAAC,IAAI,EAAE;gBACT,OAAO,KAAK,CAAC;aACd;YAED,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,yBAAyB,EAAE,CAAC;gBAE1D,MAAM,OAAO,SAAG,QAAQ,CAAC,SAAS,CAAa,mCAAI,EAAE,CAAC;gBACtD,MAAM,IAAI,SAAG,QAAQ,CAAC,MAAM,CAAC,mCAAI,EAAE,CAAC;gBAEpC,KAAK,CAAC,QAAQ,mCAAQ,OAAO,GAAK,KAAK,CAAC,QAAQ,CAAE,CAAC;gBAEnD,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;oBACf,KAAK,CAAC,IAAI,qBAAQ,IAAI,CAAE,CAAC;iBAC1B;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,GAAG,CAAC,6CAA6C,CAAC,EAAE,CAAC,CAAC;aAC9D;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CAAA,CAAC,CAAC;IACL,CAAC;;AArCD;;GAEG;AACW,gBAAE,GAAW,eAAe,CAAC","sourcesContent":["import { addGlobalEventProcessor, getCurrentHub } from \"@sentry/core\";\nimport { Contexts, Event, Integration } from \"@sentry/types\";\nimport { logger } from \"@sentry/utils\";\n\nimport { NATIVE } from \"../wrapper\";\n\n/** Load device context from native. */\nexport class DeviceContext implements Integration {\n /**\n * @inheritDoc\n */\n public static id: string = \"DeviceContext\";\n\n /**\n * @inheritDoc\n */\n public name: string = DeviceContext.id;\n\n /**\n * @inheritDoc\n */\n public setupOnce(): void {\n addGlobalEventProcessor(async (event: Event) => {\n const self = getCurrentHub().getIntegration(DeviceContext);\n if (!self) {\n return event;\n }\n\n try {\n const contexts = await NATIVE.fetchNativeDeviceContexts();\n\n const context = contexts['context'] as Contexts ?? {};\n const user = contexts['user'] ?? {};\n\n event.contexts = { ...context, ...event.contexts };\n\n if (!event.user) {\n event.user = { ...user };\n }\n } catch (e) {\n logger.log(`Failed to get device context from native: ${e}`);\n }\n\n return event;\n });\n }\n}\n"]}
|
package/dist/js/options.d.ts
CHANGED
|
@@ -31,8 +31,6 @@ export interface ReactNativeOptions extends BrowserOptions {
|
|
|
31
31
|
* @default true
|
|
32
32
|
*/
|
|
33
33
|
autoInitializeNativeSdk?: boolean;
|
|
34
|
-
/** Maximum time to wait to drain the request queue, before the process is allowed to exit. */
|
|
35
|
-
shutdownTimeout?: number;
|
|
36
34
|
/** Should the native nagger alert be shown or not. */
|
|
37
35
|
enableNativeNagger?: boolean;
|
|
38
36
|
/** Should sessions be tracked to Sentry Health or not. */
|
|
@@ -80,6 +78,12 @@ export interface ReactNativeOptions extends BrowserOptions {
|
|
|
80
78
|
* @default true
|
|
81
79
|
*/
|
|
82
80
|
patchGlobalPromise?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The max cache items for capping the number of envelopes.
|
|
83
|
+
*
|
|
84
|
+
* @default 30
|
|
85
|
+
*/
|
|
86
|
+
maxCacheItems?: number;
|
|
83
87
|
}
|
|
84
88
|
export interface ReactNativeWrapperOptions {
|
|
85
89
|
/** Props for the root React profiler */
|
package/dist/js/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/js/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAExD;;;GAGG;AAEH,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IAEpC;;;;;;;;;;OAUG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC,
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/js/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA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EAAE,uBAAuB,CAAC;CACnD"}
|
package/dist/js/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/js/options.ts"],"names":[],"mappings":"","sourcesContent":["import { BrowserOptions } from \"@sentry/react\";\nimport { ProfilerProps } from \"@sentry/react/dist/profiler\";\nimport { CaptureContext } from \"@sentry/types/dist/scope\";\n\nimport { TouchEventBoundaryProps } from \"./touchevents\";\n\n/**\n * Configuration options for the Sentry ReactNative SDK.\n * @see ReactNativeFrontend for more information.\n */\n\nexport interface ReactNativeOptions extends BrowserOptions {\n /**\n * Enables native transport + device info + offline caching.\n * Be careful, disabling this also breaks automatic release setting.\n * This means you have to manage setting the release yourself.\n * Defaults to `true`.\n */\n enableNative?: boolean;\n\n /**\n * Enables native crashHandling. This only works if `enableNative` is `true`.\n * Defaults to `true`.\n */\n enableNativeCrashHandling?: boolean;\n\n /**\n * Initializes the native SDK on init.\n * Set this to `false` if you have an existing native SDK and don't want to re-initialize.\n *\n * NOTE: Be careful and only use this if you know what you are doing.\n * If you use this flag, make sure a native SDK is running before the JS Engine initializes or events might not be captured.\n * Also, make sure the DSN on both the React Native side and the native side are the same one.\n * We strongly recommend checking the documentation if you need to use this.\n *\n * @default true\n */\n autoInitializeNativeSdk?: boolean;\n\n /**
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/js/options.ts"],"names":[],"mappings":"","sourcesContent":["import { BrowserOptions } from \"@sentry/react\";\nimport { ProfilerProps } from \"@sentry/react/dist/profiler\";\nimport { CaptureContext } from \"@sentry/types/dist/scope\";\n\nimport { TouchEventBoundaryProps } from \"./touchevents\";\n\n/**\n * Configuration options for the Sentry ReactNative SDK.\n * @see ReactNativeFrontend for more information.\n */\n\nexport interface ReactNativeOptions extends BrowserOptions {\n /**\n * Enables native transport + device info + offline caching.\n * Be careful, disabling this also breaks automatic release setting.\n * This means you have to manage setting the release yourself.\n * Defaults to `true`.\n */\n enableNative?: boolean;\n\n /**\n * Enables native crashHandling. This only works if `enableNative` is `true`.\n * Defaults to `true`.\n */\n enableNativeCrashHandling?: boolean;\n\n /**\n * Initializes the native SDK on init.\n * Set this to `false` if you have an existing native SDK and don't want to re-initialize.\n *\n * NOTE: Be careful and only use this if you know what you are doing.\n * If you use this flag, make sure a native SDK is running before the JS Engine initializes or events might not be captured.\n * Also, make sure the DSN on both the React Native side and the native side are the same one.\n * We strongly recommend checking the documentation if you need to use this.\n *\n * @default true\n */\n autoInitializeNativeSdk?: boolean;\n\n /** Should the native nagger alert be shown or not. */\n enableNativeNagger?: boolean;\n\n /** Should sessions be tracked to Sentry Health or not. */\n enableAutoSessionTracking?: boolean;\n\n /** The interval to end a session if the App goes to the background. */\n sessionTrackingIntervalMillis?: number;\n\n /** Enable scope sync from Java to NDK on Android */\n enableNdkScopeSync?: boolean;\n\n /** When enabled, all the threads are automatically attached to all logged events on Android */\n attachThreads?: boolean;\n\n /**\n * When enabled, certain personally identifiable information (PII) is added by active integrations.\n *\n * @default false\n * */\n sendDefaultPii?: boolean;\n\n /**\n * Callback that is called after the RN SDK on the JS Layer has made contact with the Native Layer.\n */\n onReady?: (response: {\n /** `true` if the native SDK has been initialized, `false` otherwise. */\n didCallNativeInit: boolean;\n }) => void;\n\n /** Enable auto performance tracking by default. */\n enableAutoPerformanceTracking?: boolean;\n\n /**\n * Enables Out of Memory Tracking for iOS and macCatalyst.\n * See the following link for more information and possible restrictions:\n * https://docs.sentry.io/platforms/apple/guides/ios/configuration/out-of-memory/\n *\n * @default true\n * */\n enableOutOfMemoryTracking?: boolean;\n\n /**\n * Set data to the inital scope\n * @deprecated Use `Sentry.configureScope(...)`\n */\n initialScope?: CaptureContext;\n\n /**\n * When enabled, Sentry will overwrite the global Promise instance to ensure that unhandled rejections are correctly tracked.\n * If you run into issues with Promise polyfills such as `core-js`, make sure you polyfill after Sentry is initialized.\n * Read more at https://docs.sentry.io/platforms/react-native/troubleshooting/#unhandled-promise-rejections\n *\n * When disabled, this option will not disable unhandled rejection tracking. Set `onunhandledrejection: false` on the `ReactNativeErrorHandlers` integration instead.\n * @default true\n */\n patchGlobalPromise?: boolean;\n\n /**\n * The max cache items for capping the number of envelopes.\n *\n * @default 30\n */\n maxCacheItems?: number;\n}\n\nexport interface ReactNativeWrapperOptions {\n /** Props for the root React profiler */\n profilerProps?: ProfilerProps;\n\n /** Props for the root touch event boundary */\n touchEventBoundaryProps?: TouchEventBoundaryProps;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnativenavigation.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/reactnativenavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,8BAA8B,EAC9B,cAAc,EACd,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAIlC,UAAU,4BAA4B;IACpC,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAMD,UAAU,cAAc;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,aAAK,aAAa,GACd,WAAW,GACX,aAAa,GACb,kBAAkB,GAClB,cAAc,CAAC;AAEnB,MAAM,WAAW,wBAAyB,SAAQ,cAAc;IAC9D,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC;IACtD,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,IAAI,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,mCAAmC,CACjC,QAAQ,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,GAClD,mBAAmB,CAAC;IACvB,uBAAuB,CACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MA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eNavigationInstrumentation extends InternalRoutingInstrum
|
|
|
50
50
|
_onComponentWillAppear(event) {
|
|
51
51
|
var _a, _b, _c;
|
|
52
52
|
// If the route is a different key, this is so we ignore actions that pertain to the same screen.
|
|
53
|
-
if (this._latestTransaction
|
|
54
|
-
(!this._prevComponentEvent ||
|
|
55
|
-
event.componentId != this._prevComponentEvent.componentId)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
if (this._latestTransaction) {
|
|
54
|
+
if (!this._prevComponentEvent ||
|
|
55
|
+
event.componentId != this._prevComponentEvent.componentId) {
|
|
56
|
+
this._clearStateChangeTimeout();
|
|
57
|
+
const originalContext = this._latestTransaction.toContext();
|
|
58
|
+
const routeHasBeenSeen = this._recentComponentIds.includes(event.componentId);
|
|
59
|
+
const data = Object.assign(Object.assign({}, originalContext.data), { route: Object.assign(Object.assign({}, event), { name: event.componentName, hasBeenSeen: routeHasBeenSeen }), previousRoute: this._prevComponentEvent
|
|
60
|
+
? Object.assign(Object.assign({}, this._prevComponentEvent), { name: (_a = this._prevComponentEvent) === null || _a === void 0 ? void 0 : _a.componentName }) : null });
|
|
61
|
+
const updatedContext = Object.assign(Object.assign({}, originalContext), { name: event.componentName, tags: Object.assign(Object.assign({}, originalContext.tags), { "routing.route.name": event.componentName }), data });
|
|
62
|
+
let finalContext = (_b = this._beforeNavigate) === null || _b === void 0 ? void 0 : _b.call(this, updatedContext);
|
|
63
|
+
// This block is to catch users not returning a transaction context
|
|
64
|
+
if (!finalContext) {
|
|
65
|
+
logger.error(`[${ReactNativeNavigationInstrumentation.name}] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`);
|
|
66
|
+
finalContext = Object.assign(Object.assign({}, updatedContext), { sampled: false });
|
|
67
|
+
}
|
|
68
|
+
if (finalContext.sampled === false) {
|
|
69
|
+
logger.log(`[${ReactNativeNavigationInstrumentation.name}] Will not send transaction "${finalContext.name}" due to beforeNavigate.`);
|
|
70
|
+
}
|
|
71
|
+
this._latestTransaction.updateWithContext(finalContext);
|
|
72
|
+
(_c = this._onConfirmRoute) === null || _c === void 0 ? void 0 : _c.call(this, finalContext);
|
|
73
|
+
this._prevComponentEvent = event;
|
|
67
74
|
}
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
else {
|
|
76
|
+
this._discardLatestTransaction();
|
|
70
77
|
}
|
|
71
|
-
this._latestTransaction
|
|
72
|
-
(_c = this._onConfirmRoute) === null || _c === void 0 ? void 0 : _c.call(this, finalContext);
|
|
73
|
-
this._prevComponentEvent = event;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
this._discardLatestTransaction();
|
|
78
|
+
this._latestTransaction = undefined;
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
/** Cancels the latest transaction so it does not get sent to Sentry. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnativenavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnativenavigation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIvC,OAAO,EACL,8BAA8B,GAG/B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAMrD,MAAM,cAAc,GAAiC;IACnD,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAmCF;;;;;;;GAOG;AACH,MAAM,OAAO,oCAAqC,SAAQ,8BAA8B;IAYtF;IACE,uGAAuG;IACvG,UAAmB,EACnB,UAAiD,EAAE;QAEnD,KAAK,EAAE,CAAC;QAXF,wBAAmB,GAAoC,IAAI,CAAC;QAG5D,wBAAmB,GAAa,EAAE,CAAC;QAUzC,IAAI,CAAC,WAAW,GAAG,UAAgC,CAAC;QAEpD,IAAI,CAAC,QAAQ,mCACR,cAAc,GACd,OAAO,CACX,CA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IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;QAED,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAED,wEAAwE;IAChE,wBAAwB;QAC9B,IAAI,OAAO,IAAI,CAAC,mBAAmB,KAAK,WAAW,EAAE;YACnD,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACvC,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;;AA7Ja,wDAAmB,GAAW,yBAAyB,CAAC","sourcesContent":["import { Transaction as TransactionType } from \"@sentry/types\";\nimport { logger } from \"@sentry/utils\";\nimport { EmitterSubscription } from \"react-native\";\n\nimport { BeforeNavigate } from \"./reactnativetracing\";\nimport {\n InternalRoutingInstrumentation,\n OnConfirmRoute,\n TransactionCreator,\n} from \"./routingInstrumentation\";\nimport { RouteChangeContextData } from \"./types\";\nimport { getBlankTransactionContext } from \"./utils\";\n\ninterface ReactNativeNavigationOptions {\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNativeNavigationOptions = {\n routeChangeTimeoutMs: 1000,\n};\n\ninterface ComponentEvent {\n componentId: string;\n}\n\ntype ComponentType =\n | \"Component\"\n | \"TopBarTitle\"\n | \"TopBarBackground\"\n | \"TopBarButton\";\n\nexport interface ComponentWillAppearEvent extends ComponentEvent {\n componentName: string;\n passProps?: Record<string | number | symbol, unknown>;\n componentType: ComponentType;\n}\n\nexport interface EventSubscription {\n remove(): void;\n}\n\nexport interface EventsRegistry {\n registerComponentWillAppearListener(\n callback: (event: ComponentWillAppearEvent) => void\n ): EmitterSubscription;\n registerCommandListener(\n callback: (name: string, params: unknown) => void\n ): EventSubscription;\n}\n\nexport interface NavigationDelegate {\n events: () => EventsRegistry;\n}\n\n/**\n * Instrumentation for React Native Navigation. See docs or sample app for usage.\n *\n * How this works:\n * - `_onCommand` is called every time a commands happens and sets an IdleTransaction on the scope without any route context.\n * - `_onComponentWillAppear` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onComponentWillAppear` isn't called within `options.routeChangeTimeoutMs` of the dispatch, then the transaction is not sampled and finished.\n */\nexport class ReactNativeNavigationInstrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = \"react-native-navigation\";\n\n private _navigation: NavigationDelegate;\n private _options: ReactNativeNavigationOptions;\n\n private _prevComponentEvent: ComponentWillAppearEvent | null = null;\n\n private _latestTransaction?: TransactionType;\n private _recentComponentIds: string[] = [];\n private _stateChangeTimeout?: number | undefined;\n\n public constructor(\n /** The react native navigation `NavigationDelegate`. This is usually the import named `Navigation`. */\n navigation: unknown,\n options: Partial<ReactNativeNavigationOptions> = {}\n ) {\n super();\n\n this._navigation = navigation as NavigationDelegate;\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Registers the event listeners for React Native Navigation\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute\n ): void {\n super.registerRoutingInstrumentation(\n listener,\n beforeNavigate,\n onConfirmRoute\n );\n\n this._navigation\n .events()\n .registerCommandListener(this._onCommand.bind(this));\n\n this._navigation\n .events()\n .registerComponentWillAppearListener(\n this._onComponentWillAppear.bind(this)\n );\n }\n\n /**\n * To be called when a navigation command is dispatched\n */\n private _onCommand(): void {\n if (this._latestTransaction) {\n this._discardLatestTransaction();\n }\n\n this._latestTransaction = this.onRouteWillChange(\n getBlankTransactionContext(ReactNativeNavigationInstrumentation.name)\n );\n\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs\n );\n }\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n private _onComponentWillAppear(event: ComponentWillAppearEvent): void {\n // If the route is a different key, this is so we ignore actions that pertain to the same screen.\n if (\n this._latestTransaction &&\n (!this._prevComponentEvent ||\n event.componentId != this._prevComponentEvent.componentId)\n ) {\n this._clearStateChangeTimeout();\n\n const originalContext = this._latestTransaction.toContext();\n const routeHasBeenSeen = this._recentComponentIds.includes(\n event.componentId\n );\n\n const data: RouteChangeContextData = {\n ...originalContext.data,\n route: {\n ...event,\n name: event.componentName,\n hasBeenSeen: routeHasBeenSeen,\n },\n previousRoute: this._prevComponentEvent\n ? {\n ...this._prevComponentEvent,\n name: this._prevComponentEvent?.componentName,\n }\n : null,\n };\n\n const updatedContext = {\n ...originalContext,\n name: event.componentName,\n tags: {\n ...originalContext.tags,\n \"routing.route.name\": event.componentName,\n },\n data,\n };\n\n let finalContext = this._beforeNavigate?.(updatedContext);\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[${ReactNativeNavigationInstrumentation.name}] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`\n );\n\n finalContext = {\n ...updatedContext,\n sampled: false,\n };\n }\n\n if (finalContext.sampled === false) {\n logger.log(\n `[${ReactNativeNavigationInstrumentation.name}] Will not send transaction \"${finalContext.name}\" due to beforeNavigate.`\n );\n }\n\n this._latestTransaction.updateWithContext(finalContext);\n this._onConfirmRoute?.(finalContext);\n\n this._prevComponentEvent = event;\n } else {\n this._discardLatestTransaction();\n }\n }\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n\n this._clearStateChangeTimeout();\n }\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _clearStateChangeTimeout(): void {\n if (typeof this._stateChangeTimeout !== \"undefined\") {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"reactnativenavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnativenavigation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,e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,OAAO,KAAK,KAAK,EAAE;oBAClC,MAAM,CAAC,GAAG,CACR,IAAI,oCAAoC,CAAC,IAAI,gCAAgC,YAAY,CAAC,IAAI,0BAA0B,CACzH,CAAC;iBACH;gBAED,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;gBACxD,MAAA,IAAI,CAAC,eAAe,+CAApB,IAAI,EAAmB,YAAY,EAAE;gBAErC,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;aAClC;iBAAM;gBACL,IAAI,CAAC,yBAAyB,EAAE,CAAC;aAClC;YAED,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;IACH,CAAC;IAED,wEAAwE;IAChE,yBAAyB;QAC/B,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;QAED,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAED,wEAAwE;IAChE,wBAAwB;QAC9B,IAAI,OAAO,IAAI,CAAC,mBAAmB,KAAK,WAAW,EAAE;YACnD,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACvC,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;;AAhKa,wDAAmB,GAAW,yBAAyB,CAAC","sourcesContent":["import { Transaction as TransactionType } from \"@sentry/types\";\nimport { logger } from \"@sentry/utils\";\nimport { EmitterSubscription } from \"react-native\";\n\nimport { BeforeNavigate } from \"./reactnativetracing\";\nimport {\n InternalRoutingInstrumentation,\n OnConfirmRoute,\n TransactionCreator,\n} from \"./routingInstrumentation\";\nimport { RouteChangeContextData } from \"./types\";\nimport { getBlankTransactionContext } from \"./utils\";\n\ninterface ReactNativeNavigationOptions {\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNativeNavigationOptions = {\n routeChangeTimeoutMs: 1000,\n};\n\ninterface ComponentEvent {\n componentId: string;\n}\n\ntype ComponentType =\n | \"Component\"\n | \"TopBarTitle\"\n | \"TopBarBackground\"\n | \"TopBarButton\";\n\nexport interface ComponentWillAppearEvent extends ComponentEvent {\n componentName: string;\n passProps?: Record<string | number | symbol, unknown>;\n componentType: ComponentType;\n}\n\nexport interface EventSubscription {\n remove(): void;\n}\n\nexport interface EventsRegistry {\n registerComponentWillAppearListener(\n callback: (event: ComponentWillAppearEvent) => void\n ): EmitterSubscription;\n registerCommandListener(\n callback: (name: string, params: unknown) => void\n ): EventSubscription;\n}\n\nexport interface NavigationDelegate {\n events: () => EventsRegistry;\n}\n\n/**\n * Instrumentation for React Native Navigation. See docs or sample app for usage.\n *\n * How this works:\n * - `_onCommand` is called every time a commands happens and sets an IdleTransaction on the scope without any route context.\n * - `_onComponentWillAppear` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onComponentWillAppear` isn't called within `options.routeChangeTimeoutMs` of the dispatch, then the transaction is not sampled and finished.\n */\nexport class ReactNativeNavigationInstrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = \"react-native-navigation\";\n\n private _navigation: NavigationDelegate;\n private _options: ReactNativeNavigationOptions;\n\n private _prevComponentEvent: ComponentWillAppearEvent | null = null;\n\n private _latestTransaction?: TransactionType;\n private _recentComponentIds: string[] = [];\n private _stateChangeTimeout?: number | undefined;\n\n public constructor(\n /** The react native navigation `NavigationDelegate`. This is usually the import named `Navigation`. */\n navigation: unknown,\n options: Partial<ReactNativeNavigationOptions> = {}\n ) {\n super();\n\n this._navigation = navigation as NavigationDelegate;\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Registers the event listeners for React Native Navigation\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute\n ): void {\n super.registerRoutingInstrumentation(\n listener,\n beforeNavigate,\n onConfirmRoute\n );\n\n this._navigation\n .events()\n .registerCommandListener(this._onCommand.bind(this));\n\n this._navigation\n .events()\n .registerComponentWillAppearListener(\n this._onComponentWillAppear.bind(this)\n );\n }\n\n /**\n * To be called when a navigation command is dispatched\n */\n private _onCommand(): void {\n if (this._latestTransaction) {\n this._discardLatestTransaction();\n }\n\n this._latestTransaction = this.onRouteWillChange(\n getBlankTransactionContext(ReactNativeNavigationInstrumentation.name)\n );\n\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs\n );\n }\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n private _onComponentWillAppear(event: ComponentWillAppearEvent): void {\n // If the route is a different key, this is so we ignore actions that pertain to the same screen.\n if (this._latestTransaction) {\n if (\n !this._prevComponentEvent ||\n event.componentId != this._prevComponentEvent.componentId\n ) {\n this._clearStateChangeTimeout();\n\n const originalContext = this._latestTransaction.toContext();\n const routeHasBeenSeen = this._recentComponentIds.includes(\n event.componentId\n );\n\n const data: RouteChangeContextData = {\n ...originalContext.data,\n route: {\n ...event,\n name: event.componentName,\n hasBeenSeen: routeHasBeenSeen,\n },\n previousRoute: this._prevComponentEvent\n ? {\n ...this._prevComponentEvent,\n name: this._prevComponentEvent?.componentName,\n }\n : null,\n };\n\n const updatedContext = {\n ...originalContext,\n name: event.componentName,\n tags: {\n ...originalContext.tags,\n \"routing.route.name\": event.componentName,\n },\n data,\n };\n\n let finalContext = this._beforeNavigate?.(updatedContext);\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[${ReactNativeNavigationInstrumentation.name}] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`\n );\n\n finalContext = {\n ...updatedContext,\n sampled: false,\n };\n }\n\n if (finalContext.sampled === false) {\n logger.log(\n `[${ReactNativeNavigationInstrumentation.name}] Will not send transaction \"${finalContext.name}\" due to beforeNavigate.`\n );\n }\n\n this._latestTransaction.updateWithContext(finalContext);\n this._onConfirmRoute?.(finalContext);\n\n this._prevComponentEvent = event;\n } else {\n this._discardLatestTransaction();\n }\n\n this._latestTransaction = undefined;\n }\n }\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n\n this._clearStateChangeTimeout();\n }\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _clearStateChangeTimeout(): void {\n if (typeof this._stateChangeTimeout !== \"undefined\") {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n }\n}\n"]}
|
|
@@ -12,7 +12,7 @@ interface ReactNavigationOptions {
|
|
|
12
12
|
routeChangeTimeoutMs: number;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Instrumentation for React-Navigation V5. See docs or sample app for usage.
|
|
15
|
+
* Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.
|
|
16
16
|
*
|
|
17
17
|
* How this works:
|
|
18
18
|
* - `_onDispatch` is called every time a dispatch happens and sets an IdleTransaction on the scope without any route context.
|
|
@@ -5,7 +5,7 @@ const defaultOptions = {
|
|
|
5
5
|
routeChangeTimeoutMs: 1000,
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
* Instrumentation for React-Navigation V5. See docs or sample app for usage.
|
|
8
|
+
* Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.
|
|
9
9
|
*
|
|
10
10
|
* How this works:
|
|
11
11
|
* - `_onDispatch` is called every time a dispatch happens and sets an IdleTransaction on the scope without any route context.
|
|
@@ -75,17 +75,17 @@ export class ReactNavigationInstrumentation extends InternalRoutingInstrumentati
|
|
|
75
75
|
this._initialStateHandled = true;
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
|
-
logger.log("[
|
|
78
|
+
logger.log("[ReactNavigationInstrumentation] Navigation container registered, but integration has not been setup yet.");
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
_global.__sentry_rn_v5_registered = true;
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
|
-
logger.warn("[
|
|
84
|
+
logger.warn("[ReactNavigationInstrumentation] Received invalid navigation container ref!");
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
|
-
logger.log("[
|
|
88
|
+
logger.log("[ReactNavigationInstrumentation] Instrumentation already exists, but register has been called again, doing nothing.");
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
@@ -110,7 +110,7 @@ export class ReactNavigationInstrumentation extends InternalRoutingInstrumentati
|
|
|
110
110
|
// Use the getCurrentRoute method to be accurate.
|
|
111
111
|
const previousRoute = this._latestRoute;
|
|
112
112
|
if (!this._navigationContainer) {
|
|
113
|
-
logger.warn("[
|
|
113
|
+
logger.warn("[ReactNavigationInstrumentation] Missing navigation container ref. Route transactions will not be sent.");
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
116
|
const route = this._navigationContainer.getCurrentRoute();
|
|
@@ -135,12 +135,12 @@ export class ReactNavigationInstrumentation extends InternalRoutingInstrumentati
|
|
|
135
135
|
let finalContext = (_c = this._beforeNavigate) === null || _c === void 0 ? void 0 : _c.call(this, updatedContext);
|
|
136
136
|
// This block is to catch users not returning a transaction context
|
|
137
137
|
if (!finalContext) {
|
|
138
|
-
logger.error(`[
|
|
138
|
+
logger.error(`[ReactNavigationInstrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`);
|
|
139
139
|
finalContext = Object.assign(Object.assign({}, updatedContext), { sampled: false });
|
|
140
140
|
}
|
|
141
141
|
// Note: finalContext.sampled will be false at this point only if the user sets it to be so in beforeNavigate.
|
|
142
142
|
if (finalContext.sampled === false) {
|
|
143
|
-
logger.log(`[
|
|
143
|
+
logger.log(`[ReactNavigationInstrumentation] Will not send transaction "${finalContext.name}" due to beforeNavigate.`);
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
146
146
|
// Clear the timeout so the transaction does not get cancelled.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EACL,8BAA8B,GAG/B,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAqBrD,MAAM,cAAc,GAA2B;IAC7C,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,8BAA+B,SAAQ,8BAA8B;IAehF,YAAmB,UAA2C,EAAE;QAC9D,KAAK,EAAE,CAAC;QAbF,yBAAoB,GAA+B,IAAI,CAAC;QAE/C,uBAAkB,GAAW,GAAG,CAAC;QAI1C,yBAAoB,GAAY,KAAK,CAAC;QAEtC,qBAAgB,GAAa,EAAE,CAAC;QAiNxC,sGAAsG;QAC9F,wBAAmB,GAAG,CAAC,GAAW,EAAQ,EAAE;YAClD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE;gBAC1D,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CACjD,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CACvD,CAAC;aACH;QACH,CAAC,CAAC;QAnNA,IAAI,CAAC,QAAQ,mCACR,cAAc,GACd,OAAO,CACX,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,8BAA8B,CACnC,QAA4B,EAC5B,cAA8B,EAC9B,cAA8B;QAE9B,KAAK,CAAC,8BAA8B,CAClC,QAAQ,EACR,cAAc,EACd,cAAc,CACf,CAA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AAI,CAAC,YAAY,GAAG,KAAK,CAAC;aAC3B;SACF;QAED,uDAAuD;QACvD,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;IACtC,CAAC;IAaD,wEAAwE;IAChE,yBAAyB;QAC/B,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;IACH,CAAC;IAED;;OAEG;IACK,wBAAwB;QAC9B,IAAI,OAAO,IAAI,CAAC,mBAAmB,KAAK,WAAW,EAAE;YACnD,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACvC,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;;AAvPa,kDAAmB,GAAW,qBAAqB,CAAC;AA0PpE;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,8BAA8B,CAAC;AAE/E,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,IAAI,EAAE,cAAc;IACpB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EACvB,8BAA8B,CAAC,mBAAmB;KACrD;IACD,IAAI,EAAE,EAAE;CACT,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport { Transaction as TransactionType } from \"@sentry/types\";\nimport { getGlobalObject, logger } from \"@sentry/utils\";\n\nimport { BeforeNavigate } from \"./reactnativetracing\";\nimport {\n InternalRoutingInstrumentation,\n OnConfirmRoute,\n TransactionCreator,\n} from \"./routingInstrumentation\";\nimport {\n ReactNavigationTransactionContext,\n RouteChangeContextData,\n} from \"./types\";\nimport { getBlankTransactionContext } from \"./utils\";\n\nexport interface NavigationRoute {\n name: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\ninterface NavigationContainer {\n addListener: (type: string, listener: () => void) => void;\n getCurrentRoute: () => NavigationRoute;\n}\n\ninterface ReactNavigationOptions {\n /**\n * The time the transaction will wait for route to mount before it is discarded.\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationOptions = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V5. See docs or sample app for usage.\n *\n * How this works:\n * - `_onDispatch` is called every time a dispatch happens and sets an IdleTransaction on the scope without any route context.\n * - `_onStateChange` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onStateChange` isn't called within `STATE_CHANGE_TIMEOUT_DURATION` of the dispatch, then the transaction is not sampled and finished.\n */\nexport class ReactNavigationInstrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = \"react-navigation-v5\";\n\n private _navigationContainer: NavigationContainer | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _latestRoute?: NavigationRoute;\n private _latestTransaction?: TransactionType;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n private _recentRouteKeys: string[] = [];\n\n private _options: ReactNavigationOptions;\n\n public constructor(options: Partial<ReactNavigationOptions> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute\n ): void {\n super.registerRoutingInstrumentation(\n listener,\n beforeNavigate,\n onConfirmRoute\n );\n\n // We create an initial state here to ensure a transaction gets created before the first route mounts.\n if (!this._initialStateHandled) {\n this._onDispatch();\n if (this._navigationContainer) {\n // Navigation container already registered, just populate with route state\n this._onStateChange();\n\n this._initialStateHandled = true;\n }\n }\n }\n\n /**\n * Pass the ref to the navigation container to register it to the instrumentation\n * @param navigationContainerRef Ref to a `NavigationContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerNavigationContainer(navigationContainerRef: any): void {\n const _global = getGlobalObject<{ __sentry_rn_v5_registered?: boolean }>();\n\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!_global.__sentry_rn_v5_registered) {\n if (\"current\" in navigationContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._navigationContainer = navigationContainerRef.current;\n } else {\n this._navigationContainer = navigationContainerRef;\n }\n\n if (this._navigationContainer) {\n this._navigationContainer.addListener(\n \"__unsafe_action__\", // This action is emitted on every dispatch\n this._onDispatch.bind(this)\n );\n this._navigationContainer.addListener(\n \"state\", // This action is emitted on every state change\n this._onStateChange.bind(this)\n );\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n // If registerRoutingInstrumentation was called first _onDispatch has already been called\n this._onStateChange();\n\n this._initialStateHandled = true;\n } else {\n logger.log(\n \"[ReactNavigationV5Instrumentation] Navigation container registered, but integration has not been setup yet.\"\n );\n }\n }\n\n _global.__sentry_rn_v5_registered = true;\n } else {\n logger.warn(\n \"[ReactNavigationV5Instrumentation] Received invalid navigation container ref!\"\n );\n }\n } else {\n logger.log(\n \"[ReactNavigationV5Instrumentation] Instrumentation already exists, but register has been called again, doing nothing.\"\n );\n }\n }\n\n /**\n * To be called on every React-Navigation action dispatch.\n * It does not name the transaction or populate it with route information. Instead, it waits for the state to fully change\n * and gets the route information from there, @see _onStateChange\n */\n private _onDispatch(): void {\n if (this._latestTransaction) {\n logger.log(\n `[ReactNavigationInstrumentation] A transaction was detected that turned out to be a noop, discarding.`\n );\n this._discardLatestTransaction();\n this._clearStateChangeTimeout();\n }\n\n this._latestTransaction = this.onRouteWillChange(\n getBlankTransactionContext(\n ReactNavigationInstrumentation.instrumentationName\n )\n );\n\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs\n );\n }\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n private _onStateChange(): void {\n // Use the getCurrentRoute method to be accurate.\n const previousRoute = this._latestRoute;\n\n if (!this._navigationContainer) {\n logger.warn(\n \"[ReactNavigationV5Instrumentation] Missing navigation container ref. Route transactions will not be sent.\"\n );\n\n return;\n }\n\n const route = this._navigationContainer.getCurrentRoute();\n\n if (route) {\n if (this._latestTransaction) {\n if (!previousRoute || previousRoute.key !== route.key) {\n const originalContext = this._latestTransaction.toContext() as typeof BLANK_TRANSACTION_CONTEXT;\n const routeHasBeenSeen = this._recentRouteKeys.includes(route.key);\n\n const data: RouteChangeContextData = {\n ...originalContext.data,\n route: {\n name: route.name,\n key: route.key,\n params: route.params ?? {},\n hasBeenSeen: routeHasBeenSeen,\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.name,\n key: previousRoute.key,\n params: previousRoute.params ?? {},\n }\n : null,\n };\n\n const updatedContext: ReactNavigationTransactionContext = {\n ...originalContext,\n name: route.name,\n tags: {\n ...originalContext.tags,\n \"routing.route.name\": route.name,\n },\n data,\n };\n\n let finalContext = this._beforeNavigate?.(updatedContext);\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationV5Instrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`\n );\n\n finalContext = {\n ...updatedContext,\n sampled: false,\n };\n }\n\n // Note: finalContext.sampled will be false at this point only if the user sets it to be so in beforeNavigate.\n if (finalContext.sampled === false) {\n logger.log(\n `[ReactNavigationV5Instrumentation] Will not send transaction \"${finalContext.name}\" due to beforeNavigate.`\n );\n } else {\n // Clear the timeout so the transaction does not get cancelled.\n this._clearStateChangeTimeout();\n }\n\n this._latestTransaction.updateWithContext(finalContext);\n this._onConfirmRoute?.(finalContext);\n }\n\n this._pushRecentRouteKey(route.key);\n this._latestRoute = route;\n }\n }\n\n // Clear the latest transaction as it has been handled.\n this._latestTransaction = undefined;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(\n this._recentRouteKeys.length - this._maxRecentRouteLen\n );\n }\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n\n /**\n *\n */\n private _clearStateChangeTimeout(): void {\n if (typeof this._stateChangeTimeout !== \"undefined\") {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n }\n}\n\n/**\n * Backwards compatibility alias for ReactNavigationInstrumentation\n * @deprecated Use ReactNavigationInstrumentation\n */\nexport const ReactNavigationV5Instrumentation = ReactNavigationInstrumentation;\n\nexport const BLANK_TRANSACTION_CONTEXT = {\n name: \"Route Change\",\n op: \"navigation\",\n tags: {\n \"routing.instrumentation\":\n ReactNavigationInstrumentation.instrumentationName,\n },\n data: {},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"reactnavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EACL,8BAA8B,GAG/B,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAqBrD,MAAM,cAAc,GAA2B;IAC7C,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,8BAA+B,SAAQ,8BAA8B;IAehF,YAAmB,UAA2C,EAAE;QAC9D,KAAK,EAAE,CAAC;QAbF,yBAAoB,GAA+B,IAAI,CAAC;QAE/C,uBAAkB,GAAW,GAAG,CAAC;QAI1C,yBAAoB,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GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,8BAA8B,CAAC;AAE/E,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,IAAI,EAAE,cAAc;IACpB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EACvB,8BAA8B,CAAC,mBAAmB;KACrD;IACD,IAAI,EAAE,EAAE;CACT,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport { Transaction as TransactionType } from \"@sentry/types\";\nimport { getGlobalObject, logger } from \"@sentry/utils\";\n\nimport { BeforeNavigate } from \"./reactnativetracing\";\nimport {\n InternalRoutingInstrumentation,\n OnConfirmRoute,\n TransactionCreator,\n} from \"./routingInstrumentation\";\nimport {\n ReactNavigationTransactionContext,\n RouteChangeContextData,\n} from \"./types\";\nimport { getBlankTransactionContext } from \"./utils\";\n\nexport interface NavigationRoute {\n name: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\ninterface NavigationContainer {\n addListener: (type: string, listener: () => void) => void;\n getCurrentRoute: () => NavigationRoute;\n}\n\ninterface ReactNavigationOptions {\n /**\n * The time the transaction will wait for route to mount before it is discarded.\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationOptions = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.\n *\n * How this works:\n * - `_onDispatch` is called every time a dispatch happens and sets an IdleTransaction on the scope without any route context.\n * - `_onStateChange` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onStateChange` isn't called within `STATE_CHANGE_TIMEOUT_DURATION` of the dispatch, then the transaction is not sampled and finished.\n */\nexport class ReactNavigationInstrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = \"react-navigation-v5\";\n\n private _navigationContainer: NavigationContainer | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _latestRoute?: NavigationRoute;\n private _latestTransaction?: TransactionType;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n private _recentRouteKeys: string[] = [];\n\n private _options: ReactNavigationOptions;\n\n public constructor(options: Partial<ReactNavigationOptions> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute\n ): void {\n super.registerRoutingInstrumentation(\n listener,\n beforeNavigate,\n onConfirmRoute\n );\n\n // We create an initial state here to ensure a transaction gets created before the first route mounts.\n if (!this._initialStateHandled) {\n this._onDispatch();\n if (this._navigationContainer) {\n // Navigation container already registered, just populate with route state\n this._onStateChange();\n\n this._initialStateHandled = true;\n }\n }\n }\n\n /**\n * Pass the ref to the navigation container to register it to the instrumentation\n * @param navigationContainerRef Ref to a `NavigationContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerNavigationContainer(navigationContainerRef: any): void {\n const _global = getGlobalObject<{ __sentry_rn_v5_registered?: boolean }>();\n\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!_global.__sentry_rn_v5_registered) {\n if (\"current\" in navigationContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._navigationContainer = navigationContainerRef.current;\n } else {\n this._navigationContainer = navigationContainerRef;\n }\n\n if (this._navigationContainer) {\n this._navigationContainer.addListener(\n \"__unsafe_action__\", // This action is emitted on every dispatch\n this._onDispatch.bind(this)\n );\n this._navigationContainer.addListener(\n \"state\", // This action is emitted on every state change\n this._onStateChange.bind(this)\n );\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n // If registerRoutingInstrumentation was called first _onDispatch has already been called\n this._onStateChange();\n\n this._initialStateHandled = true;\n } else {\n logger.log(\n \"[ReactNavigationInstrumentation] Navigation container registered, but integration has not been setup yet.\"\n );\n }\n }\n\n _global.__sentry_rn_v5_registered = true;\n } else {\n logger.warn(\n \"[ReactNavigationInstrumentation] Received invalid navigation container ref!\"\n );\n }\n } else {\n logger.log(\n \"[ReactNavigationInstrumentation] Instrumentation already exists, but register has been called again, doing nothing.\"\n );\n }\n }\n\n /**\n * To be called on every React-Navigation action dispatch.\n * It does not name the transaction or populate it with route information. Instead, it waits for the state to fully change\n * and gets the route information from there, @see _onStateChange\n */\n private _onDispatch(): void {\n if (this._latestTransaction) {\n logger.log(\n `[ReactNavigationInstrumentation] A transaction was detected that turned out to be a noop, discarding.`\n );\n this._discardLatestTransaction();\n this._clearStateChangeTimeout();\n }\n\n this._latestTransaction = this.onRouteWillChange(\n getBlankTransactionContext(\n ReactNavigationInstrumentation.instrumentationName\n )\n );\n\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs\n );\n }\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n private _onStateChange(): void {\n // Use the getCurrentRoute method to be accurate.\n const previousRoute = this._latestRoute;\n\n if (!this._navigationContainer) {\n logger.warn(\n \"[ReactNavigationInstrumentation] Missing navigation container ref. Route transactions will not be sent.\"\n );\n\n return;\n }\n\n const route = this._navigationContainer.getCurrentRoute();\n\n if (route) {\n if (this._latestTransaction) {\n if (!previousRoute || previousRoute.key !== route.key) {\n const originalContext = this._latestTransaction.toContext() as typeof BLANK_TRANSACTION_CONTEXT;\n const routeHasBeenSeen = this._recentRouteKeys.includes(route.key);\n\n const data: RouteChangeContextData = {\n ...originalContext.data,\n route: {\n name: route.name,\n key: route.key,\n params: route.params ?? {},\n hasBeenSeen: routeHasBeenSeen,\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.name,\n key: previousRoute.key,\n params: previousRoute.params ?? {},\n }\n : null,\n };\n\n const updatedContext: ReactNavigationTransactionContext = {\n ...originalContext,\n name: route.name,\n tags: {\n ...originalContext.tags,\n \"routing.route.name\": route.name,\n },\n data,\n };\n\n let finalContext = this._beforeNavigate?.(updatedContext);\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationInstrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`\n );\n\n finalContext = {\n ...updatedContext,\n sampled: false,\n };\n }\n\n // Note: finalContext.sampled will be false at this point only if the user sets it to be so in beforeNavigate.\n if (finalContext.sampled === false) {\n logger.log(\n `[ReactNavigationInstrumentation] Will not send transaction \"${finalContext.name}\" due to beforeNavigate.`\n );\n } else {\n // Clear the timeout so the transaction does not get cancelled.\n this._clearStateChangeTimeout();\n }\n\n this._latestTransaction.updateWithContext(finalContext);\n this._onConfirmRoute?.(finalContext);\n }\n\n this._pushRecentRouteKey(route.key);\n this._latestRoute = route;\n }\n }\n\n // Clear the latest transaction as it has been handled.\n this._latestTransaction = undefined;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(\n this._recentRouteKeys.length - this._maxRecentRouteLen\n );\n }\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n\n /**\n *\n */\n private _clearStateChangeTimeout(): void {\n if (typeof this._stateChangeTimeout !== \"undefined\") {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n }\n}\n\n/**\n * Backwards compatibility alias for ReactNavigationInstrumentation\n * @deprecated Use ReactNavigationInstrumentation\n */\nexport const ReactNavigationV5Instrumentation = ReactNavigationInstrumentation;\n\nexport const BLANK_TRANSACTION_CONTEXT = {\n name: \"Route Change\",\n op: \"navigation\",\n tags: {\n \"routing.instrumentation\":\n ReactNavigationInstrumentation.instrumentationName,\n },\n data: {},\n};\n"]}
|
package/dist/js/version.d.ts
CHANGED
package/dist/js/version.js
CHANGED
package/dist/js/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/js/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,gCAAgC,CAAC;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC","sourcesContent":["export const SDK_NAME = \"sentry.javascript.react-native\";\nexport const SDK_VERSION = \"3.3.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/js/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,gCAAgC,CAAC;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC","sourcesContent":["export const SDK_NAME = \"sentry.javascript.react-native\";\nexport const SDK_VERSION = \"3.3.3\";\n"]}
|
package/ios/RNSentry.m
CHANGED
|
@@ -44,8 +44,6 @@ RCT_EXPORT_METHOD(initNativeSdk:(NSDictionary *_Nonnull)options
|
|
|
44
44
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
45
45
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
46
46
|
{
|
|
47
|
-
PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = true;
|
|
48
|
-
|
|
49
47
|
NSError *error = nil;
|
|
50
48
|
|
|
51
49
|
SentryBeforeSendEventCallback beforeSend = ^SentryEvent*(SentryEvent *event) {
|
|
@@ -76,17 +74,25 @@ RCT_EXPORT_METHOD(initNativeSdk:(NSDictionary *_Nonnull)options
|
|
|
76
74
|
reject(@"SentryReactNative", error.localizedDescription, error);
|
|
77
75
|
return;
|
|
78
76
|
}
|
|
79
|
-
|
|
77
|
+
|
|
80
78
|
if ([mutableOptions valueForKey:@"enableNativeCrashHandling"] != nil) {
|
|
81
79
|
BOOL enableNativeCrashHandling = (BOOL)[mutableOptions valueForKey:@"enableNativeCrashHandling"];
|
|
82
|
-
|
|
80
|
+
|
|
83
81
|
if (!enableNativeCrashHandling) {
|
|
84
82
|
NSMutableArray *integrations = sentryOptions.integrations.mutableCopy;
|
|
85
83
|
[integrations removeObject:@"SentryCrashIntegration"];
|
|
86
84
|
sentryOptions.integrations = integrations;
|
|
87
85
|
}
|
|
88
86
|
}
|
|
89
|
-
|
|
87
|
+
|
|
88
|
+
// Enable the App start and Frames tracking measurements
|
|
89
|
+
if ([mutableOptions valueForKey:@"enableAutoPerformanceTracking"] != nil) {
|
|
90
|
+
BOOL enableAutoPerformanceTracking = (BOOL)[mutableOptions valueForKey:@"enableAutoPerformanceTracking"];
|
|
91
|
+
|
|
92
|
+
PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = enableAutoPerformanceTracking;
|
|
93
|
+
PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode = enableAutoPerformanceTracking;
|
|
94
|
+
}
|
|
95
|
+
|
|
90
96
|
[SentrySDK startWithOptionsObject:sentryOptions];
|
|
91
97
|
|
|
92
98
|
// If the app is active/in foreground, and we have not sent the SentryHybridSdkDidBecomeActive notification, send it.
|
|
@@ -158,8 +164,19 @@ RCT_EXPORT_METHOD(fetchNativeDeviceContexts:(RCTPromiseResolveBlock)resolve
|
|
|
158
164
|
NSDictionary<NSString *, id> *serializedScope = [scope serialize];
|
|
159
165
|
// Scope serializes as 'context' instead of 'contexts' as it does for the event.
|
|
160
166
|
NSDictionary<NSString *, id> *tempContexts = [serializedScope valueForKey:@"context"];
|
|
167
|
+
|
|
168
|
+
NSMutableDictionary<NSString *, id> *user = [NSMutableDictionary new];
|
|
169
|
+
|
|
170
|
+
NSDictionary<NSString *, id> *tempUser = [serializedScope valueForKey:@"user"];
|
|
171
|
+
if (tempUser != nil) {
|
|
172
|
+
[user addEntriesFromDictionary:[tempUser valueForKey:@"user"]];
|
|
173
|
+
} else {
|
|
174
|
+
[user setValue:PrivateSentrySDKOnly.installationID forKey:@"id"];
|
|
175
|
+
}
|
|
176
|
+
[contexts setValue:user forKey:@"user"];
|
|
177
|
+
|
|
161
178
|
if (tempContexts != nil) {
|
|
162
|
-
[contexts
|
|
179
|
+
[contexts setValue:tempContexts forKey:@"context"];
|
|
163
180
|
}
|
|
164
181
|
if (sentryOptions != nil && sentryOptions.debug) {
|
|
165
182
|
NSData *data = [NSJSONSerialization dataWithJSONObject:contexts options:0 error:nil];
|
|
@@ -203,12 +220,23 @@ RCT_EXPORT_METHOD(fetchNativeFrames:(RCTPromiseResolveBlock)resolve
|
|
|
203
220
|
|
|
204
221
|
if (frames == nil) {
|
|
205
222
|
resolve(nil);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
NSNumber *total = [NSNumber numberWithLong:frames.total];
|
|
227
|
+
NSNumber *frozen = [NSNumber numberWithLong:frames.frozen];
|
|
228
|
+
NSNumber *slow = [NSNumber numberWithLong:frames.slow];
|
|
229
|
+
NSNumber *zero = [NSNumber numberWithLong:0L];
|
|
230
|
+
|
|
231
|
+
if ([total isEqualToNumber:zero] && [frozen isEqualToNumber:zero] && [slow isEqualToNumber:zero]) {
|
|
232
|
+
resolve(nil);
|
|
233
|
+
return;
|
|
206
234
|
}
|
|
207
235
|
|
|
208
236
|
resolve(@{
|
|
209
|
-
@"totalFrames":
|
|
210
|
-
@"frozenFrames":
|
|
211
|
-
@"slowFrames":
|
|
237
|
+
@"totalFrames": total,
|
|
238
|
+
@"frozenFrames": frozen,
|
|
239
|
+
@"slowFrames": slow,
|
|
212
240
|
});
|
|
213
241
|
} else {
|
|
214
242
|
resolve(nil);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@sentry/react-native",
|
|
3
3
|
"homepage": "https://github.com/getsentry/sentry-react-native",
|
|
4
4
|
"repository": "https://github.com/getsentry/sentry-react-native",
|
|
5
|
-
"version": "3.3.
|
|
5
|
+
"version": "3.3.3",
|
|
6
6
|
"description": "Official Sentry SDK for react-native",
|
|
7
7
|
"typings": "dist/js/index.d.ts",
|
|
8
8
|
"types": "dist/js/index.d.ts",
|
package/sentry.gradle
CHANGED
|
@@ -60,16 +60,23 @@ gradle.projectsEvaluated {
|
|
|
60
60
|
def previousCliTask = null
|
|
61
61
|
|
|
62
62
|
def nameCleanup = "${bundleTask.name}_SentryUploadCleanUp"
|
|
63
|
-
//
|
|
63
|
+
// Upload the source map several times if necessary: once for each release and versionCode.
|
|
64
64
|
currentVariants.each { key, currentVariant ->
|
|
65
65
|
variant = currentVariant[0]
|
|
66
66
|
releaseName = currentVariant[1]
|
|
67
67
|
versionCode = currentVariant[2]
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
// The Sentry server distinguishes source maps by release (`--release` in the command
|
|
70
|
+
// below) and distribution identifier (`--dist` below). Give the task a unique name
|
|
71
|
+
// based on where we're uploading to.
|
|
72
|
+
def nameCliTask = "${bundleTask.name}_SentryUpload_${releaseName}_${versionCode}"
|
|
73
|
+
|
|
74
|
+
// If several outputs have the same releaseName and versionCode, we'd do the exact same
|
|
75
|
+
// upload for each of them. No need to repeat.
|
|
76
|
+
try { tasks.named(nameCliTask); return } catch (Exception e) {}
|
|
70
77
|
|
|
71
78
|
/** Upload source map file to the sentry server via CLI call. */
|
|
72
|
-
def cliTask = tasks.create(
|
|
79
|
+
def cliTask = tasks.create(nameCliTask, Exec) {
|
|
73
80
|
description = "upload debug symbols to sentry"
|
|
74
81
|
group = 'sentry.io'
|
|
75
82
|
|
|
@@ -135,7 +142,8 @@ gradle.projectsEvaluated {
|
|
|
135
142
|
commandLine(*osCompatibility, *args)
|
|
136
143
|
|
|
137
144
|
enabled true
|
|
138
|
-
|
|
145
|
+
}
|
|
146
|
+
|
|
139
147
|
// chain the upload tasks so they run sequentially in order to run
|
|
140
148
|
// the cliCleanUpTask after the final upload task is run
|
|
141
149
|
if (previousCliTask != null) {
|