@coralogix/react-native-plugin 0.1.6 → 0.1.7

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 CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.1.7 (2025-11-02)
2
+
3
+ ### 🚀 Features
4
+
5
+ - added automatic navigation detection using the @react-navigation/native package
6
+
7
+ ### Patch
8
+ - Bump android native version to 2.5.6
9
+
1
10
  ## 0.1.6 (2025-10-26)
2
11
  ### Patch
3
12
  - Bump android native version to 2.5.51
package/README.md CHANGED
@@ -78,15 +78,16 @@ CoralogixRum.setViewContext({
78
78
  ```
79
79
 
80
80
  You can automatically track view changes by using [react-navigation](https://reactnavigation.org/docs/navigation-container/#onstatechange).
81
+ Wrap your navigation ref with our `attachReactNavigationObserver` hook like so:
81
82
 
82
83
  ```javascript
84
+ const navigationRef = createNavigationContainerRef();
85
+ const navHooks = attachReactNavigationObserver(navigationRef);
86
+
83
87
  <NavigationContainer
84
88
  ref={navigationRef}
85
- onStateChange={() => {
86
- const currentRouteName = navigationRef.current.getCurrentRoute().name;
87
-
88
- CoralogixRum.setViewContext({ view: currentRouteName });
89
- }}
89
+ onReady={navHooks.onReady}
90
+ onStateChange={navHooks.onStateChange}
90
91
  >
91
92
  >{/* ... */}
92
93
  </NavigationContainer>
@@ -75,7 +75,7 @@ dependencies {
75
75
  implementation "com.facebook.react:react-android"
76
76
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
77
 
78
- implementation "com.coralogix:android-sdk:2.5.51"
78
+ implementation "com.coralogix:android-sdk:2.5.6"
79
79
  }
80
80
 
81
81
  react {
package/index.cjs.js CHANGED
@@ -219,7 +219,7 @@ function stopJsRefreshRateSampler() {
219
219
  appStateSub = null;
220
220
  }
221
221
 
222
- var version = "0.1.6";
222
+ var version = "0.1.7";
223
223
  var pkg = {
224
224
  version: version};
225
225
 
@@ -373,6 +373,34 @@ class CoralogixFetchInstrumentation extends instrumentationFetch.FetchInstrument
373
373
  }
374
374
  }
375
375
 
376
+ let lastRouteName;
377
+ function getLastNavigationRouteDetected() {
378
+ return lastRouteName;
379
+ }
380
+ function attachReactNavigationObserver(ref) {
381
+ const report = () => {
382
+ const route = ref.getCurrentRoute();
383
+ if (!route) return;
384
+ const name = route.name;
385
+ if (name !== lastRouteName) {
386
+ if (CoralogixRum.isInited) {
387
+ CoralogixRum.setViewContext({
388
+ view: name
389
+ });
390
+ }
391
+ lastRouteName = name;
392
+ }
393
+ };
394
+ const onReady = () => {
395
+ // Wait a tick to ensure the route is initialized
396
+ setTimeout(report, 0);
397
+ };
398
+ return {
399
+ onReady,
400
+ onStateChange: report
401
+ };
402
+ }
403
+
376
404
  let CoralogixDomain = /*#__PURE__*/function (CoralogixDomain) {
377
405
  CoralogixDomain["EU1"] = "EU1";
378
406
  CoralogixDomain["EU2"] = "EU2";
@@ -418,7 +446,18 @@ const CoralogixRum = {
418
446
  return;
419
447
  }
420
448
  await registerCoralogixInstrumentations(resolvedOptions);
421
- await CxSdk.initialize(_extends({}, resolvedOptions, {
449
+ let finalOptions;
450
+ const lastNavRoute = getLastNavigationRouteDetected();
451
+ if (lastNavRoute) {
452
+ finalOptions = _extends({}, resolvedOptions, {
453
+ view_context: {
454
+ view: lastNavRoute
455
+ }
456
+ });
457
+ } else {
458
+ finalOptions = resolvedOptions;
459
+ }
460
+ await CxSdk.initialize(_extends({}, finalOptions, {
422
461
  frameworkVersion: pkg.version
423
462
  }));
424
463
  isInited = true;
@@ -690,3 +729,4 @@ const subscription = eventEmitter.addListener('onBeforeSend', events => {
690
729
  exports.CoralogixDomain = CoralogixDomain;
691
730
  exports.CoralogixLogSeverity = CoralogixLogSeverity;
692
731
  exports.CoralogixRum = CoralogixRum;
732
+ exports.attachReactNavigationObserver = attachReactNavigationObserver;
package/index.esm.js CHANGED
@@ -217,7 +217,7 @@ function stopJsRefreshRateSampler() {
217
217
  appStateSub = null;
218
218
  }
219
219
 
220
- var version = "0.1.6";
220
+ var version = "0.1.7";
221
221
  var pkg = {
222
222
  version: version};
223
223
 
@@ -371,6 +371,34 @@ class CoralogixFetchInstrumentation extends FetchInstrumentation {
371
371
  }
372
372
  }
373
373
 
374
+ let lastRouteName;
375
+ function getLastNavigationRouteDetected() {
376
+ return lastRouteName;
377
+ }
378
+ function attachReactNavigationObserver(ref) {
379
+ const report = () => {
380
+ const route = ref.getCurrentRoute();
381
+ if (!route) return;
382
+ const name = route.name;
383
+ if (name !== lastRouteName) {
384
+ if (CoralogixRum.isInited) {
385
+ CoralogixRum.setViewContext({
386
+ view: name
387
+ });
388
+ }
389
+ lastRouteName = name;
390
+ }
391
+ };
392
+ const onReady = () => {
393
+ // Wait a tick to ensure the route is initialized
394
+ setTimeout(report, 0);
395
+ };
396
+ return {
397
+ onReady,
398
+ onStateChange: report
399
+ };
400
+ }
401
+
374
402
  let CoralogixDomain = /*#__PURE__*/function (CoralogixDomain) {
375
403
  CoralogixDomain["EU1"] = "EU1";
376
404
  CoralogixDomain["EU2"] = "EU2";
@@ -416,7 +444,18 @@ const CoralogixRum = {
416
444
  return;
417
445
  }
418
446
  await registerCoralogixInstrumentations(resolvedOptions);
419
- await CxSdk.initialize(_extends({}, resolvedOptions, {
447
+ let finalOptions;
448
+ const lastNavRoute = getLastNavigationRouteDetected();
449
+ if (lastNavRoute) {
450
+ finalOptions = _extends({}, resolvedOptions, {
451
+ view_context: {
452
+ view: lastNavRoute
453
+ }
454
+ });
455
+ } else {
456
+ finalOptions = resolvedOptions;
457
+ }
458
+ await CxSdk.initialize(_extends({}, finalOptions, {
420
459
  frameworkVersion: pkg.version
421
460
  }));
422
461
  isInited = true;
@@ -685,4 +724,4 @@ const subscription = eventEmitter.addListener('onBeforeSend', events => {
685
724
  }
686
725
  });
687
726
 
688
- export { CoralogixDomain, CoralogixLogSeverity, CoralogixRum };
727
+ export { CoralogixDomain, CoralogixLogSeverity, CoralogixRum, attachReactNavigationObserver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/react-native-plugin",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Official Coralogix React Native plugin",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "main": "./index.cjs.js",
27
27
  "dependencies": {
28
- "@opentelemetry/instrumentation-fetch": "0.203.0",
29
28
  "@opentelemetry/instrumentation": "0.48.0",
29
+ "@opentelemetry/instrumentation-fetch": "0.203.0",
30
30
  "@opentelemetry/sdk-trace-web": "1.30.1"
31
31
  },
32
32
  "module": "./index.esm.js",
package/src/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export { type CoralogixOtelWebOptionsInstrumentations } from './model/CoralogixO
9
9
  export { type CustomMeasurement } from './model/CustomMeasurement';
10
10
  export { type NetworkRequestDetails } from './model/NetworkRequestDetails';
11
11
  export { type CoralogixMobileVitals } from './model/CoralogixMobileVitals';
12
+ export { attachReactNavigationObserver } from './instrumentations/navigation/NavigationInstrumentation';
@@ -0,0 +1,8 @@
1
+ export declare function getLastNavigationRouteDetected(): string | undefined;
2
+ export type CurrentRouteProvider = {
3
+ getCurrentRoute: any;
4
+ };
5
+ export declare function attachReactNavigationObserver(ref: CurrentRouteProvider): {
6
+ onReady: () => void;
7
+ onStateChange: () => void;
8
+ };