@coralogix/react-native-plugin 0.18.0 → 0.19.1

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,29 @@
1
+ ## 0.19.1 (2026-11-19)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - `event_context.source` is now set only on errors, logs and network requests, and on an error it says how the error was caught (`captured` for `reportError`, `console` for `console.error`, `code` for uncaught errors, `crash` for fatal ones, `anr` for ANRs), so queries that filter errors on `source: console` may return fewer results.
6
+
7
+ ### ⬆️ Dependency Updates
8
+
9
+ - Native iOS SDK bumped to **2.24.2** and native Android SDK to **2.28.1**.
10
+
11
+ ## 0.19.0 (2026-11-17)
12
+
13
+ ### 🚀 Features
14
+
15
+ - Sensitive URL parameters are now masked by default. In every reported URL, including network requests and the URLs inside error messages, the values of parameters such as `code`, `state`, `access_token`, `password` or `api_key`, JWTs and URL credentials are replaced with `[REDACTED]`. This changes the data you see for existing apps. Masking can't be turned off.
16
+ - New `urlMasking` option: `params` masks more parameter names, and `mode` (`'mask'`, `'maskAll'` or `'dropQuery'`) chooses how much of the query is masked.
17
+
18
+ ### 🩹 Fixes
19
+
20
+ - When the app moves to the background, a life-cycle event is now sent with the session's error, view and action counts.
21
+ - On Android, fixed a crash from native memory growth in apps that use their own `Resources` implementation, such as an over-the-air translation library.
22
+
23
+ ### ⬆️ Dependency Updates
24
+
25
+ - Native iOS SDK bumped to **2.24.1** and native Android SDK to **2.28.0**, which do the masking.
26
+
1
27
  ## 0.18.0 (2026-11-12)
2
28
 
3
29
  ### 🚀 Features
package/CxSdk.podspec CHANGED
@@ -26,7 +26,7 @@ Pod::Spec.new do |s|
26
26
  # stay on that version while SPM moves ahead of it.
27
27
  #
28
28
  # scripts/check-ios-sdk-pins.sh keeps the two versions consistent.
29
- cx_ios_sdk_version = '2.23.0'
29
+ cx_ios_sdk_version = '2.24.2'
30
30
  cx_ios_sdk_products = ['Coralogix', 'CoralogixInternal', 'SessionReplay']
31
31
  cx_ios_sdk_frozen_file = File.join(__dir__, 'ios', 'COCOAPODS_FROZEN_SDK_VERSION')
32
32
  cx_ios_sdk_pod_version =
package/README.md CHANGED
@@ -580,6 +580,47 @@ Everything else — `event_context` (including `severity`), `labels`,
580
580
  `environment`, `device_context`, `device_state`, `version_metadata` — is editable,
581
581
  and returning `null` still drops the event entirely.
582
582
 
583
+ ### URL masking
584
+
585
+ From version 0.19.0, the SDK masks sensitive URL parameters before it reports a URL,
586
+ including network request URLs and the URLs inside error messages. The value is replaced
587
+ with `[REDACTED]`, and the parameter name and the rest of the URL are kept:
588
+ `https://app.com/callback?code=abc&page=2#access_token=xyz` is reported as
589
+ `https://app.com/callback?code=[REDACTED]&page=2#access_token=[REDACTED]`.
590
+
591
+ Masked by default: parameters named `code`, `state`, `key`, `sig`, `otp` and similar,
592
+ any parameter whose name contains `token`, `secret`, `password`, `session`, `apikey`,
593
+ `signature` or `jwt` and similar, JWTs anywhere in the URL, and credentials in the URL
594
+ (`https://user:password@host`). Names are compared ignoring case and punctuation, so
595
+ `api_key`, `apiKey` and `API-Key` are the same name.
596
+
597
+ Use `urlMasking` to mask more:
598
+
599
+ ```javascript
600
+ await CoralogixRum.init({
601
+ // ...
602
+ urlMasking: {
603
+ params: ['tenant_id', /^customer/i], // optional, more names to mask
604
+ mode: 'mask', // 'mask' (default), 'maskAll' or 'dropQuery'
605
+ },
606
+ });
607
+ ```
608
+
609
+ - `params`: a string matches the whole parameter name, ignoring case and punctuation. A
610
+ regular expression is tested against the decoded name; only its `i` flag is used. The
611
+ native SDKs compile it (Java on Android, ICU on iOS), so keep to syntax all three accept:
612
+ a pattern that does not compile there is skipped with a warning in the device log, while
613
+ the default masking still applies.
614
+ - `mode`: `'mask'` masks the sensitive parameters, `'maskAll'` masks every parameter
615
+ value, and `'dropQuery'` reports the URL without its query and fragment.
616
+
617
+ You cannot turn masking off or remove a default. `ignoreUrls` matches the original URL,
618
+ and `beforeSend` receives the masked one.
619
+
620
+ > [!WARNING]
621
+ > A header you list in `networkExtraConfig` (`reqHeaders` or `resHeaders`) is captured as
622
+ > sent, including `Authorization` and `Cookie`. Do not list a header that carries credentials.
623
+
583
624
  ### Proxy URL
584
625
 
585
626
  Proxy configuration to route requests.
@@ -596,6 +637,8 @@ await CoralogixRum.init({
596
637
  });
597
638
  ```
598
639
 
640
+ For what the proxy must do with each request, where to host it, and complete Node.js and Nginx examples, see the [Proxy URL guide](https://coralogix.com/docs/user-guides/rum/proxy-url/).
641
+
599
642
  <!-- /split -->
600
643
  <!-- split title="Session Replay" path="features/session-replay.md" -->
601
644
  ### Session Replay
@@ -91,7 +91,7 @@ dependencies {
91
91
  // reportUserInteraction reads instead of reimplementing the SDK's mask rule here.
92
92
  // 2.25.0 adds CoralogixRum.networkRequestSampling() and the traceparent echo fields on
93
93
  // NetworkRequestDetails, which the JS traceparent flag depends on.
94
- implementation "com.coralogix:android-sdk:2.26.0"
94
+ implementation "com.coralogix:android-sdk:2.28.1"
95
95
 
96
96
  testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
97
97
  testImplementation "org.mockito:mockito-core:5.12.0"
@@ -26,6 +26,8 @@ import com.coralogix.android.sdk.model.Instrumentation
26
26
  import com.coralogix.android.sdk.model.MobileVitalType
27
27
  import com.coralogix.android.sdk.model.NetworkCaptureRule
28
28
  import com.coralogix.android.sdk.model.TraceParentInHeaderConfig
29
+ import com.coralogix.android.sdk.model.UrlMaskingMode
30
+ import com.coralogix.android.sdk.model.UrlMaskingOptions
29
31
  import com.coralogix.android.sdk.model.TraceParentInHeaderConfigOptions
30
32
  import com.coralogix.android.sdk.model.UserContext
31
33
  import com.coralogix.android.sdk.model.ViewContext
@@ -230,7 +232,8 @@ class CxSdkModule(reactContext: ReactApplicationContext) :
230
232
  isCrash = isCrash,
231
233
  customAttributes = customAttributes,
232
234
  labels = eventLabels
233
- )
235
+ ),
236
+ toErrorSource(details)
234
237
  )
235
238
  }
236
239
 
@@ -683,6 +686,7 @@ class CxSdkModule(reactContext: ReactApplicationContext) :
683
686
  beforeSendCallback = if (hasKey("hasBeforeSend") && getBoolean("hasBeforeSend")) ::beforeSendCallback else null,
684
687
  collectIPData = collectIpData,
685
688
  networkCaptureConfig = networkExtraConfig,
689
+ urlMasking = toUrlMaskingOptions(if (hasKey("urlMasking") && !isNull("urlMasking")) getMap("urlMasking")?.toHashMap() else null),
686
690
  tracesExporter = if (hasKey("hasTracesExporter") && getBoolean("hasTracesExporter")) {
687
691
  { data: CoralogixTraceExporterData ->
688
692
  if (reactApplicationContext.hasActiveReactInstance()) {
@@ -1113,6 +1117,10 @@ class CxSdkModule(reactContext: ReactApplicationContext) :
1113
1117
  companion object {
1114
1118
  const val NAME = "CxSdk"
1115
1119
 
1120
+ /** How JS caught the error; the native SDK falls back to `captured` when it is null. */
1121
+ internal fun toErrorSource(details: ReadableMap): String? =
1122
+ if (details.hasKey("source") && !details.isNull("source")) details.getString("source") else null
1123
+
1116
1124
  // Matches the iOS bridge's rejection code for the same failure.
1117
1125
  private const val MASK_VIEW_ERROR = "MASK_VIEW_ERROR"
1118
1126
 
@@ -1157,6 +1165,37 @@ class CxSdkModule(reactContext: ReactApplicationContext) :
1157
1165
  return known.mapNotNull { EXCLUDABLE_INSTRUMENTATIONS[it] }.distinct()
1158
1166
  }
1159
1167
 
1168
+ // Spelled out because the native enum's `rawValue` is internal.
1169
+ private val URL_MASKING_MODES = mapOf(
1170
+ "mask" to UrlMaskingMode.MASK,
1171
+ "maskAll" to UrlMaskingMode.MASK_ALL,
1172
+ "dropQuery" to UrlMaskingMode.DROP_QUERY,
1173
+ )
1174
+
1175
+ /**
1176
+ * Builds the native options from the JS `serializeUrlMasking` output. Bad entries are
1177
+ * dropped with a warning: they must not fail init, since masking runs either way.
1178
+ */
1179
+ internal fun toUrlMaskingOptions(raw: Map<String, Any?>?): UrlMaskingOptions {
1180
+ if (raw == null) return UrlMaskingOptions()
1181
+ val params = (raw["params"] as? List<*>)?.filterIsInstance<String>() ?: emptyList()
1182
+ val patterns = (raw["paramPatterns"] as? List<*>)?.mapNotNull { entry ->
1183
+ val source = (entry as? Map<*, *>)?.get("source") as? String ?: return@mapNotNull null
1184
+ val ignoreCase = ((entry["flags"] as? String) ?: "").contains('i')
1185
+ try {
1186
+ if (ignoreCase) Regex(source, RegexOption.IGNORE_CASE) else Regex(source)
1187
+ } catch (e: IllegalArgumentException) {
1188
+ Log.w(NAME, "urlMasking: ignoring a pattern that does not compile: $source")
1189
+ null
1190
+ }
1191
+ } ?: emptyList()
1192
+ val rawMode = raw["mode"] as? String
1193
+ val mode = URL_MASKING_MODES[rawMode] ?: UrlMaskingMode.MASK.also {
1194
+ if (raw["mode"] != null) Log.w(NAME, "urlMasking: unknown mode ${raw["mode"]}, using mask")
1195
+ }
1196
+ return UrlMaskingOptions(params = params, paramPatterns = patterns, mode = mode)
1197
+ }
1198
+
1160
1199
  internal fun toInstrumentationMap(map: ReadableMap): Map<Instrumentation, Boolean> =
1161
1200
  INSTRUMENTATION_KEYS.entries.associate { (key, instrumentation) ->
1162
1201
  // Only an explicit boolean switches an instrumentation; null or a wrong type keeps the default.
@@ -0,0 +1,35 @@
1
+ package com.cxsdk
2
+
3
+ import com.facebook.react.bridge.ReadableMap
4
+ import org.mockito.ArgumentMatchers.anyString
5
+ import org.mockito.Mockito.mock
6
+ import org.mockito.Mockito.`when`
7
+ import kotlin.test.Test
8
+ import kotlin.test.assertEquals
9
+ import kotlin.test.assertNull
10
+
11
+ class ReportErrorSourceBridgeTest {
12
+
13
+ /** A ReadableMap holding exactly [entries], as `ErrorInstrumentation` sends them. */
14
+ private fun readableMap(vararg entries: Pair<String, String?>): ReadableMap {
15
+ val values = entries.toMap()
16
+ val map = mock(ReadableMap::class.java)
17
+ `when`(map.hasKey(anyString())).thenAnswer { values.containsKey(it.arguments[0]) }
18
+ `when`(map.isNull(anyString())).thenAnswer { values[it.arguments[0]] == null }
19
+ `when`(map.getString(anyString())).thenAnswer { values[it.arguments[0]] }
20
+ return map
21
+ }
22
+
23
+ @Test
24
+ fun `each JS source reaches the native SDK unchanged`() {
25
+ for (source in listOf("captured", "console", "code", "crash")) {
26
+ assertEquals(source, CxSdkModule.toErrorSource(readableMap("source" to source)))
27
+ }
28
+ }
29
+
30
+ @Test
31
+ fun `a missing or null source leaves the native fallback in charge`() {
32
+ assertNull(CxSdkModule.toErrorSource(readableMap("error_message" to "boom")))
33
+ assertNull(CxSdkModule.toErrorSource(readableMap("source" to null)))
34
+ }
35
+ }
@@ -0,0 +1,61 @@
1
+ package com.cxsdk
2
+
3
+ import com.coralogix.android.sdk.model.UrlMaskingMode
4
+ import kotlin.test.Test
5
+ import kotlin.test.assertEquals
6
+
7
+ class UrlMaskingOptionsBridgeTest {
8
+
9
+ @Test
10
+ fun `nothing configured gives the native defaults`() {
11
+ val options = CxSdkModule.toUrlMaskingOptions(null)
12
+
13
+ assertEquals(emptyList(), options.params)
14
+ assertEquals(emptyList(), options.paramPatterns.map { it.pattern })
15
+ assertEquals(UrlMaskingMode.MASK, options.mode)
16
+ }
17
+
18
+ @Test
19
+ fun `each JS mode maps to its native mode`() {
20
+ val modes = mapOf(
21
+ "mask" to UrlMaskingMode.MASK,
22
+ "maskAll" to UrlMaskingMode.MASK_ALL,
23
+ "dropQuery" to UrlMaskingMode.DROP_QUERY,
24
+ )
25
+ for ((js, native) in modes) {
26
+ assertEquals(native, CxSdkModule.toUrlMaskingOptions(mapOf("mode" to js)).mode, js)
27
+ }
28
+ }
29
+
30
+ @Test
31
+ fun `an unknown or missing mode falls back to mask`() {
32
+ assertEquals(UrlMaskingMode.MASK, CxSdkModule.toUrlMaskingOptions(mapOf("mode" to "off")).mode)
33
+ assertEquals(UrlMaskingMode.MASK, CxSdkModule.toUrlMaskingOptions(mapOf("mode" to null)).mode)
34
+ }
35
+
36
+ @Test
37
+ fun `names and patterns are passed through, with the i flag kept`() {
38
+ val options = CxSdkModule.toUrlMaskingOptions(
39
+ mapOf(
40
+ "params" to listOf("tenant_id", 3.0, null),
41
+ "paramPatterns" to listOf(
42
+ mapOf("source" to "^customer", "flags" to "i"),
43
+ mapOf("source" to "^acct", "flags" to ""),
44
+ ),
45
+ )
46
+ )
47
+
48
+ assertEquals(listOf("tenant_id"), options.params)
49
+ assertEquals(true, options.paramPatterns[0].containsMatchIn("CUSTOMER_ID"))
50
+ assertEquals(false, options.paramPatterns[1].containsMatchIn("ACCT_ID"))
51
+ }
52
+
53
+ @Test
54
+ fun `a pattern that does not compile is dropped, not thrown`() {
55
+ val options = CxSdkModule.toUrlMaskingOptions(
56
+ mapOf("paramPatterns" to listOf(mapOf("source" to "("), mapOf("source" to "ok")))
57
+ )
58
+
59
+ assertEquals(listOf("ok"), options.paramPatterns.map { it.pattern })
60
+ }
61
+ }
package/index.cjs.js CHANGED
@@ -39,6 +39,15 @@ let CoralogixEventType = /*#__PURE__*/function (CoralogixEventType) {
39
39
  CoralogixEventType["NAVIGATION"] = "navigation";
40
40
  return CoralogixEventType;
41
41
  }({});
42
+ let EventSource = /*#__PURE__*/function (EventSource) {
43
+ EventSource["CAPTURED"] = "captured";
44
+ EventSource["CONSOLE"] = "console";
45
+ EventSource["CODE"] = "code";
46
+ EventSource["CRASH"] = "crash";
47
+ EventSource["ANR"] = "anr";
48
+ EventSource["FETCH"] = "fetch";
49
+ return EventSource;
50
+ }({});
42
51
  let CoralogixLogSeverity = /*#__PURE__*/function (CoralogixLogSeverity) {
43
52
  CoralogixLogSeverity[CoralogixLogSeverity["Debug"] = 1] = "Debug";
44
53
  CoralogixLogSeverity[CoralogixLogSeverity["Verbose"] = 2] = "Verbose";
@@ -81,6 +90,11 @@ const MESSAGE_LIMIT = 1024;
81
90
  // The `console.error` handler installed by this module, so a repeated `enable()` can tell
82
91
  // our own handler apart from anyone else's and leave it in place.
83
92
  let installedConsoleError;
93
+
94
+ // True while the global handler hands an error to React Native's default handler, which logs
95
+ // it through `console.error` in release builds too. That echo is the error we just reported
96
+ // with its own source, so the `console.error` wrapper must not report it again as `console`.
97
+ let forwardingToDefaultHandler = false;
84
98
  const getCircularReplacer = () => {
85
99
  const seen = new WeakSet();
86
100
  return (_key, value) => {
@@ -123,45 +137,48 @@ class CoralogixErrorInstrumentation extends instrumentation.InstrumentationBase
123
137
  const previousConsoleError = typeof console.error === 'function' ? console.error : () => undefined;
124
138
  const onConsoleError = (...params) => {
125
139
  previousConsoleError.apply(console, params);
126
- this.report(params, false);
140
+ if (!forwardingToDefaultHandler) {
141
+ this.report(params, EventSource.CONSOLE);
142
+ }
127
143
  };
128
144
  installedConsoleError = onConsoleError;
129
145
  console.error = onConsoleError;
130
146
  }
131
- report(arg, isFatal) {
147
+ report(arg, source) {
132
148
  if (Array.isArray(arg)) {
133
149
  if (arg.length === 0) {
134
150
  return;
135
151
  }
136
152
  }
137
153
  if (arg instanceof Error) {
138
- this.reportError(arg, isFatal);
154
+ this.reportError(arg, source);
139
155
  } else if (typeof arg === 'string') {
140
- this.reportString(arg, isFatal);
156
+ this.reportString(arg, source);
141
157
  } else if (Array.isArray(arg)) {
142
158
  // if any arguments are Errors then add the stack trace even though the message is handled differently
143
159
  const firstError = arg.find(x => x instanceof Error);
144
160
  const message = arg.map(msg => typeof msg === 'string' ? msg : this.parseErrorObject(msg)).join(' ');
145
- this.reportString(message, isFatal, firstError);
161
+ this.reportString(message, source, firstError);
146
162
  } else {
147
- this.reportString(typeof arg === 'string' ? arg : this.getPossibleEventMessage(arg), isFatal);
163
+ this.reportString(typeof arg === 'string' ? arg : this.getPossibleEventMessage(arg), source);
148
164
  }
149
165
  }
150
- reportError(error, isFatal) {
151
- const errorDetails = this.buildErrorDetails(error, error.message, isFatal);
166
+ reportError(error, source) {
167
+ const errorDetails = this.buildErrorDetails(error, error.message, source);
152
168
  CxSdk.reportError(errorDetails);
153
169
  }
154
- reportString(message, isFatal, firstError) {
170
+ reportString(message, source, firstError) {
155
171
  const truncatedMessage = message == null ? void 0 : message.substring(0, MESSAGE_LIMIT);
156
- const errorDetails = this.buildErrorDetails(firstError, truncatedMessage, isFatal);
172
+ const errorDetails = this.buildErrorDetails(firstError, truncatedMessage, source);
157
173
  CxSdk.reportError(errorDetails);
158
174
  }
159
- buildErrorDetails(error, errorMessage, isCrash) {
175
+ buildErrorDetails(error, errorMessage, source) {
160
176
  return {
161
177
  error_type: (error == null ? void 0 : error.name) || 'CONSOLE',
162
178
  error_message: errorMessage || '',
163
179
  stack_trace: error ? parseErrorStack(error) : [],
164
- is_crash: isCrash != null ? isCrash : false
180
+ is_crash: source === EventSource.CRASH,
181
+ source
165
182
  };
166
183
  }
167
184
  getPossibleEventMessage(event) {
@@ -182,18 +199,26 @@ class CoralogixErrorInstrumentation extends instrumentation.InstrumentationBase
182
199
  enable() {
183
200
  const defaultHandler = ErrorUtils.getGlobalHandler();
184
201
  ErrorUtils.setGlobalHandler((error, isFatal) => {
185
- this.report(error, isFatal);
202
+ this.report(error, isFatal ? EventSource.CRASH : EventSource.CODE);
186
203
  if (!defaultHandler) {
187
204
  return;
188
205
  }
206
+ const forward = () => {
207
+ forwardingToDefaultHandler = true;
208
+ try {
209
+ defaultHandler(error, isFatal);
210
+ } finally {
211
+ forwardingToDefaultHandler = false;
212
+ }
213
+ };
189
214
  if (isFatal) {
190
215
  // In release builds the default handler terminates the app (RCTFatal),
191
216
  // killing any crash event still queued in the native batch processor —
192
217
  // flush it out first. waitForFatalErrorFlush never rejects and is
193
218
  // time-capped, so the handover is guaranteed.
194
- waitForFatalErrorFlush().catch(() => undefined).finally(() => defaultHandler(error, isFatal));
219
+ waitForFatalErrorFlush().catch(() => undefined).finally(forward);
195
220
  } else {
196
- defaultHandler(error, isFatal);
221
+ forward();
197
222
  }
198
223
  });
199
224
  this.listenToConsoleError();
@@ -1104,7 +1129,7 @@ function stopJsRefreshRateSampler() {
1104
1129
  appStateSub = null;
1105
1130
  }
1106
1131
 
1107
- var version = "0.18.0";
1132
+ var version = "0.19.1";
1108
1133
  var pkg = {
1109
1134
  version: version};
1110
1135
 
@@ -1726,6 +1751,26 @@ function headersToRecord(headers) {
1726
1751
  return result;
1727
1752
  }
1728
1753
 
1754
+ /** What `urlMasking` looks like on the bridge: a RegExp cannot cross it, so patterns travel as strings. */
1755
+
1756
+ /**
1757
+ * Converts `urlMasking` to a form that can cross the JS→native bridge: names and
1758
+ * RegExps go in separate lists, each RegExp as its `source` and `flags` strings.
1759
+ * Entries of any other type are dropped.
1760
+ */
1761
+ function serializeUrlMasking(options) {
1762
+ if (!options) return undefined;
1763
+ const entries = Array.isArray(options.params) ? options.params : [];
1764
+ return {
1765
+ params: entries.filter(p => typeof p === 'string'),
1766
+ paramPatterns: entries.filter(p => p instanceof RegExp).map(p => ({
1767
+ source: p.source,
1768
+ flags: p.flags.replace(/[gy]/g, '')
1769
+ })),
1770
+ mode: options.mode
1771
+ };
1772
+ }
1773
+
1729
1774
  function isSessionReplayOptionsValid(options) {
1730
1775
  const scaleValid = options.captureScale > 0 && options.captureScale <= 1;
1731
1776
  const sampleRateValid = options.sessionRecordingSampleRate >= 0 && options.sessionRecordingSampleRate <= 100;
@@ -2090,6 +2135,7 @@ progress) {
2090
2135
  frameworkVersion: pkg.version,
2091
2136
  networkExtraConfig: finalOptions.networkExtraConfig ? serializeNetworkCaptureRules(finalOptions.networkExtraConfig) : undefined,
2092
2137
  traceParentInHeader: serializeTraceParentInHeader(finalOptions.traceParentInHeader),
2138
+ urlMasking: serializeUrlMasking(finalOptions.urlMasking),
2093
2139
  hasBeforeSend: !!finalOptions.beforeSend,
2094
2140
  hasTracesExporter: !!finalOptions.tracesExporter,
2095
2141
  reportHybridColdStart: ((_finalOptions$instrum = finalOptions.instrumentations) == null ? void 0 : _finalOptions$instrum.mobile_vitals) !== false && ((_finalOptions$mobileV = finalOptions.mobileVitals) == null ? void 0 : _finalOptions$mobileV.cold) !== false
@@ -2332,7 +2378,8 @@ const CoralogixRum = {
2332
2378
  error_type: error.name,
2333
2379
  error_message: error.message,
2334
2380
  stack_trace: parseErrorStack(error),
2335
- is_crash: isCrash
2381
+ is_crash: isCrash,
2382
+ source: EventSource.CAPTURED
2336
2383
  };
2337
2384
  if (data && Object.keys(data).length > 0) {
2338
2385
  errorDetails.data = data;
package/index.esm.js CHANGED
@@ -37,6 +37,15 @@ let CoralogixEventType = /*#__PURE__*/function (CoralogixEventType) {
37
37
  CoralogixEventType["NAVIGATION"] = "navigation";
38
38
  return CoralogixEventType;
39
39
  }({});
40
+ let EventSource = /*#__PURE__*/function (EventSource) {
41
+ EventSource["CAPTURED"] = "captured";
42
+ EventSource["CONSOLE"] = "console";
43
+ EventSource["CODE"] = "code";
44
+ EventSource["CRASH"] = "crash";
45
+ EventSource["ANR"] = "anr";
46
+ EventSource["FETCH"] = "fetch";
47
+ return EventSource;
48
+ }({});
40
49
  let CoralogixLogSeverity = /*#__PURE__*/function (CoralogixLogSeverity) {
41
50
  CoralogixLogSeverity[CoralogixLogSeverity["Debug"] = 1] = "Debug";
42
51
  CoralogixLogSeverity[CoralogixLogSeverity["Verbose"] = 2] = "Verbose";
@@ -79,6 +88,11 @@ const MESSAGE_LIMIT = 1024;
79
88
  // The `console.error` handler installed by this module, so a repeated `enable()` can tell
80
89
  // our own handler apart from anyone else's and leave it in place.
81
90
  let installedConsoleError;
91
+
92
+ // True while the global handler hands an error to React Native's default handler, which logs
93
+ // it through `console.error` in release builds too. That echo is the error we just reported
94
+ // with its own source, so the `console.error` wrapper must not report it again as `console`.
95
+ let forwardingToDefaultHandler = false;
82
96
  const getCircularReplacer = () => {
83
97
  const seen = new WeakSet();
84
98
  return (_key, value) => {
@@ -121,45 +135,48 @@ class CoralogixErrorInstrumentation extends InstrumentationBase {
121
135
  const previousConsoleError = typeof console.error === 'function' ? console.error : () => undefined;
122
136
  const onConsoleError = (...params) => {
123
137
  previousConsoleError.apply(console, params);
124
- this.report(params, false);
138
+ if (!forwardingToDefaultHandler) {
139
+ this.report(params, EventSource.CONSOLE);
140
+ }
125
141
  };
126
142
  installedConsoleError = onConsoleError;
127
143
  console.error = onConsoleError;
128
144
  }
129
- report(arg, isFatal) {
145
+ report(arg, source) {
130
146
  if (Array.isArray(arg)) {
131
147
  if (arg.length === 0) {
132
148
  return;
133
149
  }
134
150
  }
135
151
  if (arg instanceof Error) {
136
- this.reportError(arg, isFatal);
152
+ this.reportError(arg, source);
137
153
  } else if (typeof arg === 'string') {
138
- this.reportString(arg, isFatal);
154
+ this.reportString(arg, source);
139
155
  } else if (Array.isArray(arg)) {
140
156
  // if any arguments are Errors then add the stack trace even though the message is handled differently
141
157
  const firstError = arg.find(x => x instanceof Error);
142
158
  const message = arg.map(msg => typeof msg === 'string' ? msg : this.parseErrorObject(msg)).join(' ');
143
- this.reportString(message, isFatal, firstError);
159
+ this.reportString(message, source, firstError);
144
160
  } else {
145
- this.reportString(typeof arg === 'string' ? arg : this.getPossibleEventMessage(arg), isFatal);
161
+ this.reportString(typeof arg === 'string' ? arg : this.getPossibleEventMessage(arg), source);
146
162
  }
147
163
  }
148
- reportError(error, isFatal) {
149
- const errorDetails = this.buildErrorDetails(error, error.message, isFatal);
164
+ reportError(error, source) {
165
+ const errorDetails = this.buildErrorDetails(error, error.message, source);
150
166
  CxSdk.reportError(errorDetails);
151
167
  }
152
- reportString(message, isFatal, firstError) {
168
+ reportString(message, source, firstError) {
153
169
  const truncatedMessage = message == null ? void 0 : message.substring(0, MESSAGE_LIMIT);
154
- const errorDetails = this.buildErrorDetails(firstError, truncatedMessage, isFatal);
170
+ const errorDetails = this.buildErrorDetails(firstError, truncatedMessage, source);
155
171
  CxSdk.reportError(errorDetails);
156
172
  }
157
- buildErrorDetails(error, errorMessage, isCrash) {
173
+ buildErrorDetails(error, errorMessage, source) {
158
174
  return {
159
175
  error_type: (error == null ? void 0 : error.name) || 'CONSOLE',
160
176
  error_message: errorMessage || '',
161
177
  stack_trace: error ? parseErrorStack(error) : [],
162
- is_crash: isCrash != null ? isCrash : false
178
+ is_crash: source === EventSource.CRASH,
179
+ source
163
180
  };
164
181
  }
165
182
  getPossibleEventMessage(event) {
@@ -180,18 +197,26 @@ class CoralogixErrorInstrumentation extends InstrumentationBase {
180
197
  enable() {
181
198
  const defaultHandler = ErrorUtils.getGlobalHandler();
182
199
  ErrorUtils.setGlobalHandler((error, isFatal) => {
183
- this.report(error, isFatal);
200
+ this.report(error, isFatal ? EventSource.CRASH : EventSource.CODE);
184
201
  if (!defaultHandler) {
185
202
  return;
186
203
  }
204
+ const forward = () => {
205
+ forwardingToDefaultHandler = true;
206
+ try {
207
+ defaultHandler(error, isFatal);
208
+ } finally {
209
+ forwardingToDefaultHandler = false;
210
+ }
211
+ };
187
212
  if (isFatal) {
188
213
  // In release builds the default handler terminates the app (RCTFatal),
189
214
  // killing any crash event still queued in the native batch processor —
190
215
  // flush it out first. waitForFatalErrorFlush never rejects and is
191
216
  // time-capped, so the handover is guaranteed.
192
- waitForFatalErrorFlush().catch(() => undefined).finally(() => defaultHandler(error, isFatal));
217
+ waitForFatalErrorFlush().catch(() => undefined).finally(forward);
193
218
  } else {
194
- defaultHandler(error, isFatal);
219
+ forward();
195
220
  }
196
221
  });
197
222
  this.listenToConsoleError();
@@ -1102,7 +1127,7 @@ function stopJsRefreshRateSampler() {
1102
1127
  appStateSub = null;
1103
1128
  }
1104
1129
 
1105
- var version = "0.18.0";
1130
+ var version = "0.19.1";
1106
1131
  var pkg = {
1107
1132
  version: version};
1108
1133
 
@@ -1724,6 +1749,26 @@ function headersToRecord(headers) {
1724
1749
  return result;
1725
1750
  }
1726
1751
 
1752
+ /** What `urlMasking` looks like on the bridge: a RegExp cannot cross it, so patterns travel as strings. */
1753
+
1754
+ /**
1755
+ * Converts `urlMasking` to a form that can cross the JS→native bridge: names and
1756
+ * RegExps go in separate lists, each RegExp as its `source` and `flags` strings.
1757
+ * Entries of any other type are dropped.
1758
+ */
1759
+ function serializeUrlMasking(options) {
1760
+ if (!options) return undefined;
1761
+ const entries = Array.isArray(options.params) ? options.params : [];
1762
+ return {
1763
+ params: entries.filter(p => typeof p === 'string'),
1764
+ paramPatterns: entries.filter(p => p instanceof RegExp).map(p => ({
1765
+ source: p.source,
1766
+ flags: p.flags.replace(/[gy]/g, '')
1767
+ })),
1768
+ mode: options.mode
1769
+ };
1770
+ }
1771
+
1727
1772
  function isSessionReplayOptionsValid(options) {
1728
1773
  const scaleValid = options.captureScale > 0 && options.captureScale <= 1;
1729
1774
  const sampleRateValid = options.sessionRecordingSampleRate >= 0 && options.sessionRecordingSampleRate <= 100;
@@ -2088,6 +2133,7 @@ progress) {
2088
2133
  frameworkVersion: pkg.version,
2089
2134
  networkExtraConfig: finalOptions.networkExtraConfig ? serializeNetworkCaptureRules(finalOptions.networkExtraConfig) : undefined,
2090
2135
  traceParentInHeader: serializeTraceParentInHeader(finalOptions.traceParentInHeader),
2136
+ urlMasking: serializeUrlMasking(finalOptions.urlMasking),
2091
2137
  hasBeforeSend: !!finalOptions.beforeSend,
2092
2138
  hasTracesExporter: !!finalOptions.tracesExporter,
2093
2139
  reportHybridColdStart: ((_finalOptions$instrum = finalOptions.instrumentations) == null ? void 0 : _finalOptions$instrum.mobile_vitals) !== false && ((_finalOptions$mobileV = finalOptions.mobileVitals) == null ? void 0 : _finalOptions$mobileV.cold) !== false
@@ -2330,7 +2376,8 @@ const CoralogixRum = {
2330
2376
  error_type: error.name,
2331
2377
  error_message: error.message,
2332
2378
  stack_trace: parseErrorStack(error),
2333
- is_crash: isCrash
2379
+ is_crash: isCrash,
2380
+ source: EventSource.CAPTURED
2334
2381
  };
2335
2382
  if (data && Object.keys(data).length > 0) {
2336
2383
  errorDetails.data = data;
package/ios/CxSdk.swift CHANGED
@@ -378,7 +378,9 @@ class CxSdk: RCTEventEmitter {
378
378
  errorType: errorType,
379
379
  isCrash: isCrash,
380
380
  customAttributes: customAttributes,
381
- labels: labels)
381
+ labels: labels,
382
+ // How JS caught the error; the native SDK falls back to `captured` when nil.
383
+ source: dictionary[Keys.source.rawValue] as? String)
382
384
  resolve("reportError success")
383
385
  }
384
386
 
@@ -681,6 +683,7 @@ class CxSdk: RCTEventEmitter {
681
683
  traceParentInHeader: mapTraceParentInHeader(parameter["traceParentInHeader"] as? [String: Any]),
682
684
  mobileVitals: mobileVitalsDict,
683
685
  networkExtraConfig: networkExtraConfig,
686
+ urlMasking: toUrlMasking(parameter["urlMasking"] as? [String: Any]),
684
687
  debug: parameter["debug"] as? Bool ?? true)
685
688
 
686
689
  return options
@@ -788,6 +791,36 @@ class CxSdk: RCTEventEmitter {
788
791
  }
789
792
  }
790
793
 
794
+ /// Builds the native options from the JS `serializeUrlMasking` output. Bad entries are
795
+ /// dropped with a warning: they must not fail init, since masking runs either way.
796
+ private func toUrlMasking(_ raw: [String: Any]?) -> UrlMaskingOptions {
797
+ guard let raw = raw else { return UrlMaskingOptions() }
798
+ var params: [UrlMaskingOptions.Param] = ((raw["params"] as? [Any]) ?? []).compactMap {
799
+ ($0 as? String).map { .name($0) }
800
+ }
801
+ for entry in (raw["paramPatterns"] as? [Any]) ?? [] {
802
+ guard let entry = entry as? [String: Any], let source = entry["source"] as? String else { continue }
803
+ let flags = entry["flags"] as? String ?? ""
804
+ guard let regex = try? NSRegularExpression(pattern: source, options: flags.contains("i") ? [.caseInsensitive] : []) else {
805
+ NSLog("[CxSdk] urlMasking: ignoring a pattern that does not compile: %@", source)
806
+ continue
807
+ }
808
+ params.append(.regex(regex))
809
+ }
810
+ let mode: UrlMaskingOptions.Mode
811
+ switch raw["mode"] as? String {
812
+ case "maskAll": mode = .maskAll
813
+ case "dropQuery": mode = .dropQuery
814
+ case "mask": mode = .mask
815
+ default:
816
+ if let other = raw["mode"], !(other is NSNull) {
817
+ NSLog("[CxSdk] urlMasking: unknown mode %@, using mask", String(describing: other))
818
+ }
819
+ mode = .mask
820
+ }
821
+ return UrlMaskingOptions(params: params, mode: mode)
822
+ }
823
+
791
824
  /// Maps the JS `excludeFromSampling` strings, warning once about any the native enum does not know.
792
825
  private func toExcludeFromSampling(_ raw: [Any]?) -> Set<ExcludableInstrumentation> {
793
826
  guard let raw = raw else { return [] }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/react-native-plugin",
3
- "version": "0.18.0",
3
+ "version": "0.19.1",
4
4
  "description": "Official Coralogix React Native plugin",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
package/src/consts.d.ts CHANGED
@@ -8,7 +8,6 @@ export declare const CoralogixAttributes: {
8
8
  SEVERITY: string;
9
9
  APPLICATION_CONTEXT: string;
10
10
  USER_CONTEXT: string;
11
- SOURCE: string;
12
11
  ERROR: {
13
12
  TYPE: string;
14
13
  STACK: string;
package/src/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import type { CoralogixBrowserSdkConfig, CoralogixStackFrame, CxSpan, HybridMetr
5
5
  import { CoralogixLogSeverity } from './model/Types';
6
6
  import type { NetworkRequestDetails } from './model/NetworkRequestDetails';
7
7
  import type { CustomMeasurement } from './model/CustomMeasurement';
8
+ import { UrlMaskingBridgeOptions } from './urlMasking';
8
9
  import { SessionReplayOptions, SessionReplayType } from './model/SessionReplayType';
9
10
  /**
10
11
  * The bridge contract, and the source of truth for it: every method here must
@@ -13,7 +14,8 @@ import { SessionReplayOptions, SessionReplayType } from './model/SessionReplayTy
13
14
  * without the declaration leaving this file.
14
15
  */
15
16
  export interface CxSdkClient {
16
- initialize(options: CoralogixBrowserSdkConfig & {
17
+ initialize(options: Omit<CoralogixBrowserSdkConfig, 'urlMasking'> & {
18
+ urlMasking?: UrlMaskingBridgeOptions;
17
19
  frameworkVersion?: string;
18
20
  hasBeforeSend?: boolean;
19
21
  hasTracesExporter?: boolean;
@@ -93,7 +95,7 @@ export { type ApplicationContextConfig } from './model/ApplicationContextConfig'
93
95
  export { type ViewContextConfig } from './model/ViewContextConfig';
94
96
  export { CoralogixDomain } from './model/CoralogixDomain';
95
97
  export { type UserContextConfig } from './model/UserContextConfig';
96
- export { type CoralogixBrowserSdkConfig, type CoralogixIgnoredInstrument, type ExcludableInstrumentation, type NetworkCaptureRule, type TraceExporterData, type EditableCxRumEvent, type BeforeSendResult, type InteractionEventContext, CoralogixEventType, CoralogixLogSeverity, } from './model/Types';
98
+ export { type CoralogixBrowserSdkConfig, type CoralogixIgnoredInstrument, type ExcludableInstrumentation, type NetworkCaptureRule, type UrlMaskingOptions, type UrlMaskingMode, type TraceExporterData, type EditableCxRumEvent, type BeforeSendResult, type InteractionEventContext, CoralogixEventType, CoralogixLogSeverity, } from './model/Types';
97
99
  export { type CoralogixOtelWebOptionsInstrumentations } from './model/CoralogixOtelWebOptionsInstrumentations';
98
100
  export { type CustomMeasurement } from './model/CustomMeasurement';
99
101
  export { type NetworkRequestDetails } from './model/NetworkRequestDetails';
@@ -1,4 +1,5 @@
1
1
  import { InstrumentationBase, InstrumentationConfig } from '@opentelemetry/instrumentation';
2
+ import { EventSource } from '../../model/Types';
2
3
  export declare const getCircularReplacer: () => ((key: any, value: any) => undefined | any);
3
4
  export interface CoralogixErrorInstrumentationConfig extends InstrumentationConfig {
4
5
  ignoreErrors?: Array<string | RegExp>;
@@ -7,10 +8,10 @@ export declare class CoralogixErrorInstrumentation extends InstrumentationBase {
7
8
  constructor(config: CoralogixErrorInstrumentationConfig);
8
9
  init(): void;
9
10
  private listenToConsoleError;
10
- protected report(arg: string | Error | Event | Array<any>, isFatal?: boolean): void;
11
+ protected report(arg: string | Error | Event | Array<any>, source: EventSource): void;
11
12
  parseErrorObject: (obj: any) => string;
12
- protected reportError(error: Error, isFatal?: boolean): void;
13
- protected reportString(message: string, isFatal?: boolean, firstError?: Error): void;
13
+ protected reportError(error: Error, source: EventSource): void;
14
+ protected reportString(message: string, source: EventSource, firstError?: Error): void;
14
15
  private buildErrorDetails;
15
16
  protected getPossibleEventMessage(event: any): string;
16
17
  enable(): void;
@@ -78,10 +78,12 @@ export declare enum CoralogixEventType {
78
78
  NAVIGATION = "navigation"
79
79
  }
80
80
  export declare enum EventSource {
81
+ CAPTURED = "captured",
81
82
  CONSOLE = "console",
82
- FETCH = "fetch",
83
83
  CODE = "code",
84
- UNHANDLED_REJECTION = "unhandledrejection"
84
+ CRASH = "crash",
85
+ ANR = "anr",
86
+ FETCH = "fetch"
85
87
  }
86
88
  export declare enum CoralogixLogSeverity {
87
89
  Debug = 1,
@@ -93,6 +95,11 @@ export declare enum CoralogixLogSeverity {
93
95
  }
94
96
  export interface EventContext {
95
97
  type: CoralogixEventType;
98
+ /**
99
+ * Set only on `error`, `log` and `network-request` events; absent on every
100
+ * other type. Typed as required to match the browser SDK and keep existing
101
+ * `beforeSend` code compiling, so check it before use.
102
+ */
96
103
  source: EventSource;
97
104
  severity: CoralogixLogSeverity;
98
105
  }
@@ -261,6 +268,20 @@ export interface EditableCxRumEvent extends Omit<CxRumEvent, 'session_context' |
261
268
  session_context: Pick<SessionContext, keyof UserMetadata | 'isSessionSampledIn'>;
262
269
  }
263
270
  export type BeforeSendResult = EditableCxRumEvent | null;
271
+ export type UrlMaskingMode = 'mask' | 'maskAll' | 'dropQuery';
272
+ export interface UrlMaskingOptions {
273
+ /**
274
+ * More parameter names to mask. A string matches the whole name, ignoring case and
275
+ * any non-alphanumeric character (`tenant_id` matches `tenantId`); a RegExp is tested
276
+ * against the decoded name.
277
+ */
278
+ params?: Array<string | RegExp>;
279
+ /**
280
+ * `'mask'` (default) masks the sensitive parameters, `'maskAll'` masks every parameter
281
+ * value, `'dropQuery'` drops the query and the fragment.
282
+ */
283
+ mode?: UrlMaskingMode;
284
+ }
264
285
  export interface NetworkCaptureRule {
265
286
  /** Exact-string URL match. One of `url` or `urlPattern` is required. */
266
287
  url?: string;
@@ -350,6 +371,13 @@ export interface CoralogixBrowserSdkConfig {
350
371
  proxyUrl?: string;
351
372
  /** Rules for capturing request/response headers and payloads per URL. */
352
373
  networkExtraConfig?: NetworkCaptureRule[];
374
+ /**
375
+ * Sensitive URL parameters (`code`, `state`, anything containing `token`, `secret`,
376
+ * `password`, `session` and so on) are always masked as `[REDACTED]` in every reported
377
+ * URL. Use this to mask more parameters or the whole query. It can't turn masking off
378
+ * or remove a default.
379
+ */
380
+ urlMasking?: UrlMaskingOptions;
353
381
  /**
354
382
  * JS refresh rate metric collection configuration.
355
383
  */
@@ -0,0 +1,16 @@
1
+ import { UrlMaskingMode, UrlMaskingOptions } from './model/Types';
2
+ /** What `urlMasking` looks like on the bridge: a RegExp cannot cross it, so patterns travel as strings. */
3
+ export interface UrlMaskingBridgeOptions {
4
+ params: string[];
5
+ paramPatterns: Array<{
6
+ source: string;
7
+ flags: string;
8
+ }>;
9
+ mode?: UrlMaskingMode;
10
+ }
11
+ /**
12
+ * Converts `urlMasking` to a form that can cross the JS→native bridge: names and
13
+ * RegExps go in separate lists, each RegExp as its `source` and `flags` strings.
14
+ * Entries of any other type are dropped.
15
+ */
16
+ export declare function serializeUrlMasking(options: UrlMaskingOptions | undefined): UrlMaskingBridgeOptions | undefined;
@@ -1,4 +0,0 @@
1
- export declare enum ErrorSource {
2
- CONSOLE = "console",
3
- GLOBAL = "global"
4
- }