@coralogix/react-native-plugin 0.1.7 → 0.1.9

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,9 @@
1
+ ## 0.1.8 (2025-11-04)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - the log can now get any type for the data and labels map parameters
6
+
1
7
  ## 0.1.7 (2025-11-02)
2
8
 
3
9
  ### 🚀 Features
package/CxSdk.podspec CHANGED
@@ -16,8 +16,8 @@ Pod::Spec.new do |s|
16
16
 
17
17
  s.source_files = "ios/**/*.{h,m,mm,swift}"
18
18
 
19
- s.dependency 'Coralogix','1.3.0'
20
- s.dependency 'CoralogixInternal','1.3.0'
19
+ s.dependency 'Coralogix','1.4.0'
20
+ s.dependency 'CoralogixInternal','1.4.0'
21
21
 
22
22
 
23
23
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
package/README.md CHANGED
@@ -67,6 +67,31 @@ CoralogixRum.log(CoralogixLogSeverity.Error, 'this is a log', { key: 'value' });
67
67
  CoralogixRum.error('this is a log with error severity', { key: 'value' });
68
68
  ```
69
69
 
70
+ ### Custom Logs
71
+
72
+ Send structured logs with optional data and labels.
73
+ ```javascript
74
+ CoralogixRum.log(CoralogixLogSeverity.Error, 'this is a log', { key: 'value' });
75
+ ```
76
+
77
+ Shorthand signatures exists for all log severities:
78
+ ```javascript
79
+ CoralogixRum.debug('this is a debug log', {key: 'value', pi: 3.14});
80
+ CoralogixRum.error('this is an error log', {error: 'yes', is_bad: 'no'});
81
+ ```
82
+
83
+ > **Note:** Due to ReactNative limitations, not all value types are supported for the log data values,
84
+ > our testing shows that ReactNative can't pass some types to the coralogix native layer, types we have identified as problematic are `Map`, `Set`, `Date` and `Function`
85
+ > please note that there could be more, so for example:
86
+ > ```javascript
87
+ > // this would pass as an empty object to the coralogix native layer, same for Set and Date:
88
+ > CoralogixRum.debug('this will be a problem', {key: new Map().set(1, 2)});
89
+ >
90
+ > // this would pass as null to the coralogix native layer
91
+ > CoralogixRum.debug('this will be a problem too', {key: () => {}});
92
+ > ```
93
+ > in the event that you need to use any of these types please stringify them before you pass it to the `log` method
94
+
70
95
  ### View Tracking
71
96
 
72
97
  To track views, set the view context whenever a view changes.
@@ -29,6 +29,8 @@ import com.facebook.react.bridge.ReadableType
29
29
  import com.facebook.react.bridge.WritableArray
30
30
  import com.facebook.react.bridge.WritableMap
31
31
  import com.facebook.react.modules.core.DeviceEventManagerModule
32
+ import org.json.JSONArray
33
+ import org.json.JSONObject
32
34
  import java.lang.Long.getLong
33
35
 
34
36
  class CxSdkModule(reactContext: ReactApplicationContext) :
@@ -425,13 +427,65 @@ class CxSdkModule(reactContext: ReactApplicationContext) :
425
427
  }
426
428
 
427
429
  private fun ReadableMap.toStringMap(): Map<String, String> {
428
- val map = mutableMapOf<String, String>()
430
+ val result = mutableMapOf<String, String>()
429
431
  val iterator = keySetIterator()
430
432
  while (iterator.hasNextKey()) {
431
433
  val key = iterator.nextKey()
432
- getString(key)?.let { map[key] = it }
434
+ val jsonValue = when (getType(key)) {
435
+ ReadableType.Null -> JSONObject.NULL
436
+ ReadableType.Boolean -> getBoolean(key)
437
+ ReadableType.Number -> getDouble(key)
438
+ ReadableType.String -> getString(key)
439
+ ReadableType.Map -> getMap(key)?.toJsonObject()
440
+ ReadableType.Array -> getArray(key)?.toJsonArray()
441
+ else -> JSONObject.NULL
442
+ }
443
+
444
+ // Always serialize as JSON string
445
+ result[key] = when (jsonValue) {
446
+ is JSONObject, is JSONArray -> jsonValue.toString()
447
+ JSONObject.NULL -> "null"
448
+ else -> JSONObject.wrap(jsonValue)?.toString() ?: "null"
449
+ }
433
450
  }
434
- return map
451
+
452
+ return result
453
+ }
454
+
455
+ private fun ReadableMap.toJsonObject(): JSONObject {
456
+ val obj = JSONObject()
457
+ val iterator = keySetIterator()
458
+ while (iterator.hasNextKey()) {
459
+ val key = iterator.nextKey()
460
+ val value = when (getType(key)) {
461
+ ReadableType.Null -> JSONObject.NULL
462
+ ReadableType.Boolean -> getBoolean(key)
463
+ ReadableType.Number -> getDouble(key)
464
+ ReadableType.String -> getString(key)
465
+ ReadableType.Map -> getMap(key)?.toJsonObject()
466
+ ReadableType.Array -> getArray(key)?.toJsonArray()
467
+ else -> JSONObject.NULL
468
+ }
469
+ obj.put(key, value)
470
+ }
471
+ return obj
472
+ }
473
+
474
+ private fun ReadableArray.toJsonArray(): JSONArray {
475
+ val arr = JSONArray()
476
+ for (i in 0 until size()) {
477
+ val value = when (getType(i)) {
478
+ ReadableType.Null -> JSONObject.NULL
479
+ ReadableType.Boolean -> getBoolean(i)
480
+ ReadableType.Number -> getDouble(i)
481
+ ReadableType.String -> getString(i)
482
+ ReadableType.Map -> getMap(i)?.toJsonObject()
483
+ ReadableType.Array -> getArray(i)?.toJsonArray()
484
+ else -> JSONObject.NULL
485
+ }
486
+ arr.put(value)
487
+ }
488
+ return arr
435
489
  }
436
490
 
437
491
  private fun Map<String, String>.toWritableMap(): WritableMap {
package/index.cjs.js CHANGED
@@ -219,7 +219,7 @@ function stopJsRefreshRateSampler() {
219
219
  appStateSub = null;
220
220
  }
221
221
 
222
- var version = "0.1.7";
222
+ var version = "0.1.9";
223
223
  var pkg = {
224
224
  version: version};
225
225
 
package/index.esm.js CHANGED
@@ -217,7 +217,7 @@ function stopJsRefreshRateSampler() {
217
217
  appStateSub = null;
218
218
  }
219
219
 
220
- var version = "0.1.7";
220
+ var version = "0.1.9";
221
221
  var pkg = {
222
222
  version: version};
223
223
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/react-native-plugin",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Official Coralogix React Native plugin",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",