expo-observe 58.0.18 → 58.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +11 -0
  3. package/android/build.gradle +1 -0
  4. package/android/src/main/java/expo/modules/observe/Constants.kt +3 -0
  5. package/android/src/main/java/expo/modules/observe/EventDispatcher.kt +13 -4
  6. package/android/src/main/java/expo/modules/observe/ObservabilityBackgroundWorker.kt +10 -1
  7. package/android/src/main/java/expo/modules/observe/ObservabilityManager.kt +32 -6
  8. package/android/src/main/java/expo/modules/observe/ObserveModule.kt +80 -1
  9. package/android/src/main/java/expo/modules/observe/ObservePreferences.kt +18 -24
  10. package/android/src/main/java/expo/modules/observe/OpenTelemetry.kt +21 -21
  11. package/app.plugin.js +1 -0
  12. package/build/index.d.ts +2 -2
  13. package/build/index.js.map +1 -1
  14. package/build/integrations/expo-router/init.js +22 -4
  15. package/build/integrations/expo-router/init.js.map +1 -1
  16. package/build/integrations/navigationConfig.d.ts +1 -0
  17. package/build/integrations/navigationConfig.js +3 -0
  18. package/build/integrations/navigationConfig.js.map +1 -1
  19. package/build/integrations/react-navigation/ObserveNavigationProvider.js +8 -3
  20. package/build/integrations/react-navigation/ObserveNavigationProvider.js.map +1 -1
  21. package/build/integrations/react-navigation/actionListener.d.ts +2 -1
  22. package/build/integrations/react-navigation/actionListener.js +5 -2
  23. package/build/integrations/react-navigation/actionListener.js.map +1 -1
  24. package/build/integrations/react-navigation/handleStateChange.d.ts +2 -1
  25. package/build/integrations/react-navigation/handleStateChange.js +14 -1
  26. package/build/integrations/react-navigation/handleStateChange.js.map +1 -1
  27. package/build/integrations/shared/navigation/blockingTime.d.ts +9 -0
  28. package/build/integrations/shared/navigation/blockingTime.js +76 -0
  29. package/build/integrations/shared/navigation/blockingTime.js.map +1 -0
  30. package/build/module.js +14 -0
  31. package/build/module.js.map +1 -1
  32. package/build/module.web.d.ts +3 -1
  33. package/build/module.web.js +5 -0
  34. package/build/module.web.js.map +1 -1
  35. package/build/privacyManifestWarning.d.ts +2 -0
  36. package/build/privacyManifestWarning.ios.d.ts +2 -0
  37. package/build/privacyManifestWarning.ios.js +13 -0
  38. package/build/privacyManifestWarning.ios.js.map +1 -0
  39. package/build/privacyManifestWarning.js +4 -0
  40. package/build/privacyManifestWarning.js.map +1 -0
  41. package/build/reportFeedback.d.ts +6 -0
  42. package/build/reportFeedback.js +78 -0
  43. package/build/reportFeedback.js.map +1 -0
  44. package/build/types.d.ts +133 -4
  45. package/build/types.js.map +1 -1
  46. package/ios/DispatchUtils.swift +6 -0
  47. package/ios/Observability.swift +49 -10
  48. package/ios/ObserveModule.swift +52 -1
  49. package/ios/ObserveUserDefaults.swift +14 -5
  50. package/ios/OpenTelemetry.swift +20 -6
  51. package/ios/Tests/DispatchLoopTests.swift +84 -0
  52. package/ios/Tests/ObservabilityTests.swift +94 -2
  53. package/ios/Tests/ObserveUserDefaultsTests.swift +64 -0
  54. package/ios/Tests/OpenTelemetryTests.swift +62 -0
  55. package/ios/Tests/PrivacyManifestTests.swift +36 -0
  56. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0-sources.jar +0 -0
  57. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0-sources.jar.md5 +1 -0
  58. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0-sources.jar.sha1 +1 -0
  59. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0-sources.jar.sha256 +1 -0
  60. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0-sources.jar.sha512 +1 -0
  61. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.aar +0 -0
  62. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.aar.md5 +1 -0
  63. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.aar.sha1 +1 -0
  64. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.aar.sha256 +1 -0
  65. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.aar.sha512 +1 -0
  66. package/local-maven-repo/expo/modules/observe/expo.modules.observe/{58.0.18/expo.modules.observe-58.0.18.module → 58.1.0/expo.modules.observe-58.1.0.module} +23 -23
  67. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.module.md5 +1 -0
  68. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.module.sha1 +1 -0
  69. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.module.sha256 +1 -0
  70. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.module.sha512 +1 -0
  71. package/local-maven-repo/expo/modules/observe/expo.modules.observe/{58.0.18/expo.modules.observe-58.0.18.pom → 58.1.0/expo.modules.observe-58.1.0.pom} +2 -2
  72. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.pom.md5 +1 -0
  73. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.pom.sha1 +1 -0
  74. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.pom.sha256 +1 -0
  75. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.1.0/expo.modules.observe-58.1.0.pom.sha512 +1 -0
  76. package/package.json +8 -5
  77. package/plugin/build/withObserve.d.ts +11 -0
  78. package/plugin/build/withObserve.js +45 -0
  79. package/plugin/build/withObserve.js.map +1 -0
  80. package/plugin/src/withObserve.ts +50 -0
  81. package/src/index.ts +10 -0
  82. package/src/integrations/expo-router/init.ts +27 -8
  83. package/src/integrations/navigationConfig.ts +4 -0
  84. package/src/integrations/react-navigation/ObserveNavigationProvider.tsx +15 -3
  85. package/src/integrations/react-navigation/actionListener.ts +7 -5
  86. package/src/integrations/react-navigation/handleStateChange.ts +19 -2
  87. package/src/integrations/shared/navigation/blockingTime.ts +101 -0
  88. package/src/module.ts +23 -1
  89. package/src/module.web.ts +7 -0
  90. package/src/privacyManifestWarning.ios.ts +19 -0
  91. package/src/privacyManifestWarning.ts +4 -0
  92. package/src/reportFeedback.ts +75 -0
  93. package/src/types.ts +150 -4
  94. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18-sources.jar +0 -0
  95. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18-sources.jar.md5 +0 -1
  96. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18-sources.jar.sha1 +0 -1
  97. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18-sources.jar.sha256 +0 -1
  98. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18-sources.jar.sha512 +0 -1
  99. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.aar +0 -0
  100. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.aar.md5 +0 -1
  101. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.aar.sha1 +0 -1
  102. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.aar.sha256 +0 -1
  103. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.aar.sha512 +0 -1
  104. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.module.md5 +0 -1
  105. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.module.sha1 +0 -1
  106. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.module.sha256 +0 -1
  107. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.module.sha512 +0 -1
  108. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.pom.md5 +0 -1
  109. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.pom.sha1 +0 -1
  110. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.pom.sha256 +0 -1
  111. package/local-maven-repo/expo/modules/observe/expo.modules.observe/58.0.18/expo.modules.observe-58.0.18.pom.sha512 +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 58.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Keep Observe inactive when the config plugin sets the `consent` option to `'not-granted'`. Observe then sends no data. ([#53709](https://github.com/expo/expo/pull/53709) by [@Ubax](https://github.com/Ubax))
8
+ - Add a config plugin with a `consent` option. Prebuild writes the consent value to `AndroidManifest.xml` and `Info.plist`. ([#53878](https://github.com/expo/expo/pull/53878) by [@Ubax](https://github.com/Ubax))
9
+ - Add `Observe.reportFeedback` to send user feedback. ([#53261](https://github.com/expo/expo/pull/53261) by [@Ubax](https://github.com/Ubax))
10
+ - Add `Observe.setConsent` to change the consent value at runtime. A grant starts collection, and a revoke stops collection and deletes the Observe data stored on the device. ([#53710](https://github.com/expo/expo/pull/53710) by [@Ubax](https://github.com/Ubax))
11
+
12
+ ### Patch Changes
13
+
14
+ - Add experimental navigation total blocking time (`tbt`) metric, enabled with `experimental_totalBlockingTime`. ([#51505](https://github.com/expo/expo/pull/51505) by [@Ubax](https://github.com/Ubax))
15
+ - Warn in development on iOS when the app privacy manifest has no user content entry for `Observe.reportFeedback`. ([#53284](https://github.com/expo/expo/pull/53284) by [@Ubax](https://github.com/Ubax))
16
+ - Add `ignoredMetrics` and `ignoredEvents` configure options to skip selected metrics and events during dispatch. ([#52524](https://github.com/expo/expo/pull/52524) by [@Ubax](https://github.com/Ubax))
17
+ - Send at most 128 attributes for each log event, and keep the `expo.*` attributes first, so the server does not drop them. ([#53615](https://github.com/expo/expo/pull/53615) by [@Ubax](https://github.com/Ubax))
18
+ - Updated dependencies. ([#51003](https://github.com/expo/expo/pull/51003), [#53973](https://github.com/expo/expo/pull/53973), [#54066](https://github.com/expo/expo/pull/54066), [#53709](https://github.com/expo/expo/pull/53709), [#53710](https://github.com/expo/expo/pull/53710), [#53688](https://github.com/expo/expo/pull/53688), [#53261](https://github.com/expo/expo/pull/53261))
19
+ - expo-app-metrics@58.1.0
20
+
21
+ ## 58.0.19
22
+
23
+ ### Patch Changes
24
+
25
+ - [Android] Send events as compact JSON instead of pretty-printed JSON, and write request bodies to logcat only in debug builds. ([#53170](https://github.com/expo/expo/pull/53170) by [@tsapeta](https://github.com/tsapeta))
26
+ - Export the `Span`, `SpanStatus`, `StartSpanOptions`, `SpanEventOptions`, `SpanEndOptions`, and `RecordSpanOptions` types, so apps can type the spans they pass as `parent` without importing `expo-app-metrics`. ([#52893](https://github.com/expo/expo/pull/52893) by [@tsapeta](https://github.com/tsapeta))
27
+
3
28
  ## 58.0.18
4
29
 
5
30
  ### Patch Changes
package/README.md CHANGED
@@ -120,6 +120,17 @@ See [Custom endpoint](https://docs.expo.dev/eas/observe/configuration/#custom-en
120
120
 
121
121
  `Observe.configure()` sets the environment label, the sampling rate, dispatching behavior and integrations at runtime. `Observe.dispatchEvents()` flushes pending events manually.
122
122
 
123
+ Use `ignoredMetrics` to skip exported metric names and `ignoredEvents` to skip event names, including custom names passed to `Observe.logEvent`:
124
+
125
+ ```ts
126
+ Observe.configure({
127
+ ignoredMetrics: ['expo.app_startup.tti'],
128
+ ignoredEvents: ['reanimated.warning', 'checkout.completed'],
129
+ });
130
+ ```
131
+
132
+ The lists apply at dispatch time. They do nothing on web and do not affect network traces.
133
+
123
134
  See [Configuration](https://docs.expo.dev/eas/observe/configuration/).
124
135
 
125
136
  ## Command line and agents
@@ -57,4 +57,5 @@ dependencies {
57
57
  testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.2'
58
58
  testImplementation 'io.mockk:mockk:1.13.8'
59
59
  testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
60
+ testImplementation 'androidx.work:work-testing:2.10.5'
60
61
  }
@@ -8,5 +8,8 @@ internal const val OBSERVE_DEFAULT_BASE_URL = "https://o.expo.dev/"
8
8
 
9
9
  internal const val DISPATCH_CHUNK_SIZE = 200
10
10
 
11
+ // The database of the telemetry queues that app metrics storage replaced.
12
+ internal const val LEGACY_DATABASE_NAME = "eas_observe"
13
+
11
14
  // Log names that `errorSampleRate` applies to.
12
15
  internal val ERROR_LOG_NAMES = setOf(JS_EXCEPTION_LOG_NAME, NATIVE_EXCEPTION_LOG_NAME)
@@ -2,6 +2,7 @@ package expo.modules.observe
2
2
 
3
3
  import android.content.Context
4
4
  import android.util.Log
5
+ import expo.modules.appmetrics.ObserveConsent
5
6
  import expo.modules.easclient.EASClientID
6
7
  import kotlinx.coroutines.suspendCancellableCoroutine
7
8
  import okhttp3.MediaType.Companion.toMediaType
@@ -45,7 +46,7 @@ class EventDispatcher(
45
46
  val body = try {
46
47
  OTRequestBody(
47
48
  resourceMetrics = events.map { it.toOTEvent(easId) }
48
- ).toJson(prettyPrint = true)
49
+ ).toJson()
49
50
  } catch (e: Exception) {
50
51
  Log.w(OBSERVE_TAG, "Encoding metrics request body failed: ${e.message}")
51
52
  continuation.resume(DispatchResult.NonRetryableFailure("encoding error: ${e.message}"))
@@ -69,7 +70,7 @@ class EventDispatcher(
69
70
  return@suspendCancellableCoroutine Unit
70
71
  }
71
72
  val body = try {
72
- OTLogsRequestBody(resourceLogs = resourceLogs).toJson(prettyPrint = true)
73
+ OTLogsRequestBody(resourceLogs = resourceLogs).toJson()
73
74
  } catch (e: Exception) {
74
75
  Log.w(OBSERVE_TAG, "Encoding logs request body failed: ${e.message}")
75
76
  continuation.resume(DispatchResult.NonRetryableFailure("encoding error: ${e.message}"))
@@ -93,7 +94,7 @@ class EventDispatcher(
93
94
  val body = try {
94
95
  OTTracesRequestBody(
95
96
  resourceSpans = batches.map { it.event.toOTResourceSpans(easId, it.spans) }
96
- ).toJson(prettyPrint = true)
97
+ ).toJson()
97
98
  } catch (e: Exception) {
98
99
  Log.w(OBSERVE_TAG, "Encoding traces request body failed: ${e.message}")
99
100
  continuation.resume(DispatchResult.NonRetryableFailure("encoding error: ${e.message}"))
@@ -122,7 +123,9 @@ class EventDispatcher(
122
123
  .post(body.toRequestBody("application/json".toMediaType()))
123
124
  .build()
124
125
 
125
- Log.d(OBSERVE_TAG, body)
126
+ if (BuildConfig.DEBUG) {
127
+ Log.d(OBSERVE_TAG, body)
128
+ }
126
129
 
127
130
  val call = httpClient.newCall(request)
128
131
 
@@ -130,6 +133,12 @@ class EventDispatcher(
130
133
  call.cancel()
131
134
  }
132
135
 
136
+ // Checked right before the request starts, so a revoke during the preparation stops it. The
137
+ // retryable result ends the dispatch loop without moving the cursors.
138
+ if (!ObserveConsent.isGranted) {
139
+ continuation.resume(DispatchResult.RetryableFailure(retryAfterMs = null))
140
+ return
141
+ }
133
142
  val response = try {
134
143
  call.execute()
135
144
  } catch (e: Exception) {
@@ -14,7 +14,9 @@ import androidx.work.NetworkType
14
14
  import androidx.work.OneTimeWorkRequestBuilder
15
15
  import androidx.work.WorkManager
16
16
  import androidx.work.WorkerParameters
17
+ import androidx.work.await
17
18
  import androidx.work.workDataOf
19
+ import expo.modules.appmetrics.ObserveConsent
18
20
  import expo.modules.appmetrics.storage.SessionManager
19
21
 
20
22
  /**
@@ -61,6 +63,9 @@ class ObservabilityBackgroundWorker(
61
63
  }
62
64
 
63
65
  override suspend fun doWork(): Result {
66
+ if (!ObserveConsent.isGranted) {
67
+ return Result.success()
68
+ }
64
69
  return try {
65
70
  if (observabilityManager == null) {
66
71
  Log.e(OBSERVE_TAG, "ObservabilityManager is null - missing projectId or baseUrl")
@@ -83,7 +88,11 @@ class ObservabilityBackgroundWorker(
83
88
  }
84
89
 
85
90
  companion object {
86
- private const val WORK_NAME = "eas-observe-dispatch"
91
+ internal const val WORK_NAME = "eas-observe-dispatch"
92
+
93
+ suspend fun cancelBackgroundDispatch(context: Context) {
94
+ WorkManager.getInstance(context).cancelUniqueWork(WORK_NAME).await()
95
+ }
87
96
 
88
97
  fun scheduleBackgroundDispatch(
89
98
  context: Context,
@@ -2,7 +2,9 @@ package expo.modules.observe
2
2
 
3
3
  import android.content.Context
4
4
  import android.util.Log
5
+ import expo.modules.appmetrics.ObserveConsent
5
6
  import expo.modules.easclient.EASClientID
7
+ import expo.modules.appmetrics.logevents.FEEDBACK_LOG_NAME
6
8
  import expo.modules.appmetrics.storage.SessionManager
7
9
  import expo.modules.appmetrics.storage.Span
8
10
  import expo.modules.appmetrics.utils.TimeUtils
@@ -55,6 +57,9 @@ class ObservabilityManager(
55
57
  }
56
58
 
57
59
  fun scheduleBackgroundDispatch() {
60
+ if (!ObserveConsent.isGranted) {
61
+ return
62
+ }
58
63
  ObservabilityBackgroundWorker.scheduleBackgroundDispatch(
59
64
  context = context,
60
65
  projectId = baseManager.projectId,
@@ -130,12 +135,16 @@ class BaseObservabilityManager(
130
135
  )
131
136
 
132
137
  suspend fun dispatchUnsentMetrics(): Unit = metricsDispatchMutex.withLock {
138
+ if (!ObserveConsent.isGranted) {
139
+ return
140
+ }
133
141
  if (retryGateBlocks(metricsRetryGate, "metrics")) {
134
142
  return
135
143
  }
136
144
 
137
145
  repairMetricCursorIfStale(context, sessionManager)
138
146
  val config = ObservePreferences.getConfig(context)
147
+ val ignoredMetrics = config?.ignoredMetrics?.toSet() ?: emptySet()
139
148
  if (!shouldDispatch(config, config?.sampleRate)) {
140
149
  val maxId = sessionManager.getMaxMetricId() ?: -1
141
150
  if (ObservePreferences.getLastDispatchedMetricId(context) != maxId) {
@@ -154,7 +163,9 @@ class BaseObservabilityManager(
154
163
  }
155
164
 
156
165
  val highestId = metrics.last().id
157
- val metricsBySessionId = metrics.groupBy { it.sessionId }
166
+ val metricsBySessionId = metrics
167
+ .filterNot { exportedMetricName(it.category, it.name) in ignoredMetrics }
168
+ .groupBy { it.sessionId }
158
169
  val sessions = sessionManager.getSessions(metricsBySessionId.keys).associateBy { it.id }
159
170
  val events = metricsBySessionId.mapNotNull { (sessionId, sessionMetrics) ->
160
171
  sessions[sessionId]?.let { session ->
@@ -210,16 +221,22 @@ class BaseObservabilityManager(
210
221
  * a logs failure doesn't affect the metrics cursor and vice versa.
211
222
  */
212
223
  suspend fun dispatchUnsentLogs(): Unit = logsDispatchMutex.withLock {
224
+ if (!ObserveConsent.isGranted) {
225
+ return
226
+ }
213
227
  if (retryGateBlocks(logsRetryGate, "logs")) {
214
228
  return
215
229
  }
216
230
 
217
231
  repairLogCursorIfStale(context, sessionManager)
218
232
  val config = ObservePreferences.getConfig(context)
233
+ val ignoredEvents = config?.ignoredEvents?.toSet() ?: emptySet()
219
234
  // Installations in-sample for `sampleRate` send all logs. Errors use the higher of the two rates.
235
+ // Feedback uses no rate, so it is sent whenever this installation can send any logs.
220
236
  val dispatchLogsAndErrors = shouldDispatch(config, config?.sampleRate)
221
237
  val dispatchErrors = shouldDispatch(config, config?.errorSampleRate ?: config?.sampleRate)
222
- if (!dispatchLogsAndErrors && !dispatchErrors) {
238
+ val dispatchAnyLogs = shouldDispatch(config, null)
239
+ if (!dispatchAnyLogs) {
223
240
  val maxId = sessionManager.getMaxLogId() ?: -1
224
241
  if (ObservePreferences.getLastDispatchedLogId(context) != maxId) {
225
242
  ObservePreferences.setLastDispatchedLogId(context, maxId)
@@ -240,8 +257,15 @@ class BaseObservabilityManager(
240
257
  val sampledLogs = if (dispatchLogsAndErrors) {
241
258
  logs
242
259
  } else {
243
- logs.filter { it.name in ERROR_LOG_NAMES }
244
- }
260
+ val supportedLogNames = (
261
+ if (dispatchErrors) {
262
+ ERROR_LOG_NAMES
263
+ } else {
264
+ emptySet()
265
+ }
266
+ ) + FEEDBACK_LOG_NAME
267
+ logs.filter { it.name in supportedLogNames }
268
+ }.filterNot { it.name in ignoredEvents }
245
269
  val logsBySessionId = sampledLogs.groupBy { it.sessionId }
246
270
  val sessions = sessionManager.getSessions(logsBySessionId.keys).associateBy { it.id }
247
271
  val events = logsBySessionId.mapNotNull { (sessionId, sessionLogs) ->
@@ -303,6 +327,9 @@ class BaseObservabilityManager(
303
327
  * server's per-request span limit.
304
328
  */
305
329
  suspend fun dispatchUnsentSpans(): Unit = spansDispatchMutex.withLock {
330
+ if (!ObserveConsent.isGranted) {
331
+ return
332
+ }
306
333
  if (retryGateBlocks(spansRetryGate, "spans")) {
307
334
  return
308
335
  }
@@ -399,8 +426,7 @@ class BaseObservabilityManager(
399
426
  suspend fun cleanup() {
400
427
  // TODO(@ubax): Move sessionManager.cleanupOldSessions out of eas observe
401
428
  sessionManager.cleanupOldSessions()
402
- // Remove the database used by the old pending telemetry queues.
403
- context.deleteDatabase("eas_observe")
429
+ context.deleteDatabase(LEGACY_DATABASE_NAME)
404
430
  sessionManager.cleanupOldLogs()
405
431
  }
406
432
 
@@ -3,6 +3,7 @@ package expo.modules.observe
3
3
  import android.content.Context
4
4
  import android.util.Log
5
5
  import expo.modules.appmetrics.AppMetricsModule
6
+ import expo.modules.appmetrics.ObserveConsent
6
7
  import expo.modules.easclient.EASClientID
7
8
  import expo.modules.interfaces.constants.ConstantsInterface
8
9
  import expo.modules.kotlin.exception.Exceptions
@@ -11,7 +12,9 @@ import expo.modules.kotlin.modules.Module
11
12
  import expo.modules.kotlin.modules.ModuleDefinition
12
13
  import expo.modules.kotlin.records.Field
13
14
  import expo.modules.kotlin.records.Record
15
+ import expo.modules.kotlin.types.Enumerable
14
16
  import expo.modules.kotlin.types.OptimizedRecord
17
+ import kotlinx.coroutines.CancellationException
15
18
 
16
19
  @OptimizedRecord
17
20
  class Config(
@@ -20,6 +23,8 @@ class Config(
20
23
  @Field val dispatchInDebug: Boolean? = null,
21
24
  @Field val sampleRate: Double? = null,
22
25
  @Field val errorSampleRate: Double? = null,
26
+ @Field val ignoredMetrics: List<String> = emptyList(),
27
+ @Field val ignoredEvents: List<String> = emptyList(),
23
28
  @Field val integrations: Map<String, Any?>? = null
24
29
  ) : Record
25
30
 
@@ -29,6 +34,11 @@ class BundleDefaults(
29
34
  @Field val isJsDev: Boolean = false
30
35
  ) : Record
31
36
 
37
+ internal enum class ConsentValue(val value: String) : Enumerable {
38
+ GRANTED("granted"),
39
+ NOT_GRANTED("not-granted")
40
+ }
41
+
32
42
  class ObserveModule : Module() {
33
43
  private val context: Context
34
44
  get() = appContext.reactContext ?: throw Exceptions.ReactContextLost()
@@ -45,6 +55,12 @@ class ObserveModule : Module() {
45
55
  Events("configure")
46
56
 
47
57
  OnCreate {
58
+ // Deletes what a build with consent stored. Module start is late enough, because nothing is
59
+ // sent without consent.
60
+ if (!ObserveConsent.isGranted) {
61
+ context.deleteDatabase(LEGACY_DATABASE_NAME)
62
+ ObservePreferences.deleteStoredSettings(context)
63
+ }
48
64
  appMetricsModule = checkNotNull(appContext.registry.getModule<AppMetricsModule>()) {
49
65
  "AppMetricsModule is required by ObserveModule. Make sure expo-app-metrics is installed."
50
66
  }
@@ -64,6 +80,10 @@ class ObserveModule : Module() {
64
80
  EASClientID(context).uuid.toString().lowercase()
65
81
  }
66
82
 
83
+ AsyncFunction("setConsent") Coroutine { consent: ConsentValue ->
84
+ applyConsent(context, consent, appMetricsModule::setConsent)
85
+ }
86
+
67
87
  AsyncFunction("dispatchEvents") Coroutine { ->
68
88
  observabilityManager.dispatchUnsentMetrics()
69
89
  observabilityManager.dispatchUnsentLogs()
@@ -77,7 +97,9 @@ class ObserveModule : Module() {
77
97
  dispatchingEnabled = config.dispatchingEnabled,
78
98
  dispatchInDebug = config.dispatchInDebug,
79
99
  sampleRate = config.sampleRate,
80
- errorSampleRate = config.errorSampleRate
100
+ errorSampleRate = config.errorSampleRate,
101
+ ignoredMetrics = config.ignoredMetrics,
102
+ ignoredEvents = config.ignoredEvents
81
103
  )
82
104
  )
83
105
  // Environment falls back to the bundle default (set on JS package import) so an
@@ -115,3 +137,60 @@ class ObserveModule : Module() {
115
137
  }
116
138
  }
117
139
  }
140
+
141
+ /**
142
+ * Applies `Observe.setConsent`. A revoke deletes the Observe data under the app metrics consent
143
+ * lock, after the gate closes, also when the consent save failed. A failed consent save is reported
144
+ * before a failed delete.
145
+ */
146
+ internal suspend fun applyConsent(
147
+ context: Context,
148
+ consent: ConsentValue,
149
+ setAppMetricsConsent: suspend (Boolean, suspend () -> Unit) -> Unit
150
+ ) {
151
+ var deleteError: Exception? = null
152
+ try {
153
+ setAppMetricsConsent(consent == ConsentValue.GRANTED) {
154
+ try {
155
+ deleteObserveData(context)
156
+ } catch (e: CancellationException) {
157
+ throw e
158
+ } catch (e: Exception) {
159
+ deleteError = e
160
+ }
161
+ }
162
+ } catch (e: CancellationException) {
163
+ throw e
164
+ } catch (e: Exception) {
165
+ deleteError?.let(e::addSuppressed)
166
+ throw e
167
+ }
168
+ deleteError?.let { throw it }
169
+ }
170
+
171
+ /**
172
+ * Deletes the Observe settings, the dispatch cursors among them, and the scheduled dispatch. Each
173
+ * step runs also when an earlier step fails. The first error is thrown, with the others attached.
174
+ */
175
+ internal suspend fun deleteObserveData(context: Context) {
176
+ var error: Exception? = null
177
+ // The local deletes first, because they do not suspend. So a canceled dispatch cancel cannot
178
+ // skip them.
179
+ val localDeletes = listOf({ context.deleteDatabase(LEGACY_DATABASE_NAME) }, { ObservePreferences.deleteStoredSettings(context) })
180
+ for (delete in localDeletes) {
181
+ try {
182
+ delete()
183
+ } catch (e: Exception) {
184
+ error?.addSuppressed(e) ?: run { error = e }
185
+ }
186
+ }
187
+ try {
188
+ ObservabilityBackgroundWorker.cancelBackgroundDispatch(context)
189
+ } catch (e: CancellationException) {
190
+ error?.let(e::addSuppressed)
191
+ throw e
192
+ } catch (e: Exception) {
193
+ error?.addSuppressed(e) ?: run { error = e }
194
+ }
195
+ error?.let { throw it }
196
+ }
@@ -1,7 +1,7 @@
1
1
  package expo.modules.observe
2
2
 
3
3
  import android.content.Context
4
- import androidx.core.content.edit
4
+ import expo.modules.appmetrics.ConsentGatedPreferences
5
5
  import kotlinx.serialization.Serializable
6
6
  import kotlinx.serialization.json.Json
7
7
 
@@ -19,7 +19,9 @@ data class PersistedConfig(
19
19
  val dispatchingEnabled: Boolean? = null,
20
20
  val dispatchInDebug: Boolean? = null,
21
21
  val sampleRate: Double? = null,
22
- val errorSampleRate: Double? = null
22
+ val errorSampleRate: Double? = null,
23
+ val ignoredMetrics: List<String> = emptyList(),
24
+ val ignoredEvents: List<String> = emptyList()
23
25
  )
24
26
 
25
27
  /**
@@ -32,49 +34,41 @@ data class PersistedBundleDefaults(
32
34
  )
33
35
 
34
36
  object ObservePreferences {
37
+ private val preferences = ConsentGatedPreferences(PREFS_NAME)
38
+
35
39
  fun getConfig(context: Context): PersistedConfig? {
36
- val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
37
- val json = prefs.getString(KEY_CONFIG, null) ?: return null
40
+ val json = preferences.getString(context, KEY_CONFIG) ?: return null
38
41
  return runCatching { Json.decodeFromString<PersistedConfig>(json) }.getOrNull()
39
42
  }
40
43
 
41
44
  fun setConfig(context: Context, config: PersistedConfig) {
42
- val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
43
- prefs.edit(commit = true) {
44
- putString(KEY_CONFIG, Json.encodeToString(config))
45
- }
45
+ preferences.putString(context, KEY_CONFIG, Json.encodeToString(config))
46
46
  }
47
47
 
48
48
  fun getBundleDefaults(context: Context): PersistedBundleDefaults? {
49
- val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
50
- val json = prefs.getString(KEY_BUNDLE_DEFAULTS, null) ?: return null
49
+ val json = preferences.getString(context, KEY_BUNDLE_DEFAULTS) ?: return null
51
50
  return runCatching { Json.decodeFromString<PersistedBundleDefaults>(json) }.getOrNull()
52
51
  }
53
52
 
54
53
  fun setBundleDefaults(context: Context, defaults: PersistedBundleDefaults) {
55
- val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
56
- prefs.edit {
57
- putString(KEY_BUNDLE_DEFAULTS, Json.encodeToString(defaults))
58
- }
54
+ preferences.putString(context, KEY_BUNDLE_DEFAULTS, Json.encodeToString(defaults), commit = false)
59
55
  }
60
56
 
61
57
  fun getLastDispatchedMetricId(context: Context): Long =
62
- context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
63
- .getLong(KEY_LAST_DISPATCHED_METRIC_ID, -1)
58
+ preferences.getLong(context, KEY_LAST_DISPATCHED_METRIC_ID, -1)
64
59
 
65
60
  fun setLastDispatchedMetricId(context: Context, id: Long) {
66
- context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit(commit = true) {
67
- putLong(KEY_LAST_DISPATCHED_METRIC_ID, id)
68
- }
61
+ preferences.putLong(context, KEY_LAST_DISPATCHED_METRIC_ID, id)
69
62
  }
70
63
 
71
64
  fun getLastDispatchedLogId(context: Context): Long =
72
- context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
73
- .getLong(KEY_LAST_DISPATCHED_LOG_ID, -1)
65
+ preferences.getLong(context, KEY_LAST_DISPATCHED_LOG_ID, -1)
74
66
 
75
67
  fun setLastDispatchedLogId(context: Context, id: Long) {
76
- context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit(commit = true) {
77
- putLong(KEY_LAST_DISPATCHED_LOG_ID, id)
78
- }
68
+ preferences.putLong(context, KEY_LAST_DISPATCHED_LOG_ID, id)
69
+ }
70
+
71
+ internal fun deleteStoredSettings(context: Context) {
72
+ preferences.delete(context)
79
73
  }
80
74
  }
@@ -194,11 +194,8 @@ data class OTResourceSpans(
194
194
  data class OTRequestBody(
195
195
  val resourceMetrics: List<OTEvent>
196
196
  ) {
197
- fun toJson(prettyPrint: Boolean = false): String {
198
- val json = Json {
199
- this.prettyPrint = prettyPrint
200
- }
201
- return json.encodeToString(serializer(), this)
197
+ fun toJson(): String {
198
+ return Json.encodeToString(serializer(), this)
202
199
  }
203
200
  }
204
201
 
@@ -206,11 +203,8 @@ data class OTRequestBody(
206
203
  data class OTLogsRequestBody(
207
204
  val resourceLogs: List<OTResourceLogs>
208
205
  ) {
209
- fun toJson(prettyPrint: Boolean = false): String {
210
- val json = Json {
211
- this.prettyPrint = prettyPrint
212
- }
213
- return json.encodeToString(serializer(), this)
206
+ fun toJson(): String {
207
+ return Json.encodeToString(serializer(), this)
214
208
  }
215
209
  }
216
210
 
@@ -218,11 +212,8 @@ data class OTLogsRequestBody(
218
212
  data class OTTracesRequestBody(
219
213
  val resourceSpans: List<OTResourceSpans>
220
214
  ) {
221
- fun toJson(prettyPrint: Boolean = false): String {
222
- val json = Json {
223
- this.prettyPrint = prettyPrint
224
- }
225
- return json.encodeToString(serializer(), this)
215
+ fun toJson(): String {
216
+ return Json.encodeToString(serializer(), this)
226
217
  }
227
218
  }
228
219
 
@@ -267,7 +258,7 @@ data class OTServiceResponse(
267
258
  */
268
259
  internal const val SEMCONV_SCHEMA_URL = "https://opentelemetry.io/schemas/1.27.0"
269
260
 
270
- // This must be kept in sync with the INTERNAL_TO_OTEL map in universe
261
+ // Keep in sync with INTERNAL_TO_OTEL in universe and `ObserveMetricName` in `src/types.ts`:
271
262
  // https://github.com/expo/universe/blob/main/server/www/src/middleware/easObserveRoutes.ts#L209
272
263
  private val metricNameMap = mapOf(
273
264
  // App startup
@@ -288,9 +279,13 @@ private val metricNameMap = mapOf(
288
279
  // Navigation
289
280
  (MetricCategory.Navigation.categoryName to "cold_ttr") to "expo.navigation.cold_ttr",
290
281
  (MetricCategory.Navigation.categoryName to "warm_ttr") to "expo.navigation.warm_ttr",
291
- (MetricCategory.Navigation.categoryName to "tti") to "expo.navigation.tti"
282
+ (MetricCategory.Navigation.categoryName to "tti") to "expo.navigation.tti",
283
+ (MetricCategory.Navigation.categoryName to "tbt") to "expo.navigation.tbt"
292
284
  )
293
285
 
286
+ internal fun exportedMetricName(category: String, name: String): String =
287
+ metricNameMap[category to name] ?: "expo.unknown.$name"
288
+
294
289
  fun EASMetric.toOTMetric(): OTMetric {
295
290
  val attributes = mutableListOf(
296
291
  OTAttribute.of(key = "session.id", rawValue = sessionId)
@@ -307,7 +302,7 @@ fun EASMetric.toOTMetric(): OTMetric {
307
302
 
308
303
  return OTMetric(
309
304
  unit = "s",
310
- name = metricNameMap[category to name] ?: "expo.unknown.$name",
305
+ name = exportedMetricName(category, name),
311
306
  gauge = OTGauge(
312
307
  dataPoints = listOf(
313
308
  OTDataPoint(
@@ -431,11 +426,13 @@ fun LogEvent.toOTLogRecord(): OTLogRecord {
431
426
  var encodeTimeDrops = 0
432
427
  this.attributes?.let { attrs ->
433
428
  val (typed, dropped) = otAttributesFromJsonObject(attrs)
434
- attributes.addAll(typed)
429
+ // The ingest keeps only the first `MAX_LOG_ATTRIBUTE_COUNT` attributes, so SDK `expo.*` keys go first.
430
+ attributes.addAll(typed.sortedWith(compareBy({ !it.key.startsWith("expo.") }, { it.key })))
435
431
  encodeTimeDrops = dropped
436
432
  }
433
+ val limitDrops = maxOf(attributes.size - MAX_LOG_ATTRIBUTE_COUNT, 0)
437
434
 
438
- val totalDrops = droppedAttributesCount + encodeTimeDrops
435
+ val totalDrops = droppedAttributesCount + encodeTimeDrops + limitDrops
439
436
  val timeNs = timestampToDateNS(timestamp)
440
437
  // Both `severityNumber` and `severityText` come off the same enum case so
441
438
  // they can't disagree. Unknown raw values (e.g. a future case shipped on JS
@@ -448,7 +445,7 @@ fun LogEvent.toOTLogRecord(): OTLogRecord {
448
445
  severityNumber = resolvedSeverity.severityNumber,
449
446
  severityText = resolvedSeverity.severityText,
450
447
  body = OTStringValue(stringValue = body ?: ""),
451
- attributes = attributes,
448
+ attributes = attributes.take(MAX_LOG_ATTRIBUTE_COUNT),
452
449
  droppedAttributesCount = if (totalDrops > 0) {
453
450
  totalDrops
454
451
  } else {
@@ -495,6 +492,9 @@ fun Event.toOTResourceSpans(easClientId: String, spans: List<OTSpan>): OTResourc
495
492
  */
496
493
  private const val MAX_SPAN_EVENT_COUNT = 32
497
494
 
495
+ // Maximum attributes the ingestion endpoint keeps per log record.
496
+ private const val MAX_LOG_ATTRIBUTE_COUNT = 128
497
+
498
498
  /**
499
499
  * Converts a persisted unix-epoch millisecond timestamp to nanoseconds, saturating instead of
500
500
  * overflowing: a corrupt row or a device clock set far into the future must never wrap into a
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./plugin/build/withObserve');
package/build/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import Observe from './module';
3
3
  * @deprecated Use `Observe` instead. `AppMetrics` is the legacy name of this API from SDK 55.
4
4
  */
5
5
  export { default as AppMetrics } from 'expo-app-metrics';
6
- export type { AppMetricsErrorBoundaryFallbackProps, AppMetricsErrorBoundaryProps, AppMetricsRootProps, ExpoAppMetricsModuleType, LogAttributeValue, LogEventOptions, LogSeverity, MetricAttributes, } from 'expo-app-metrics';
6
+ export type { AppMetricsErrorBoundaryFallbackProps, AppMetricsErrorBoundaryProps, AppMetricsRootProps, ExpoAppMetricsModuleType, LogAttributeValue, LogEventOptions, LogSeverity, MetricAttributes, RecordSpanOptions, Span, SpanEndOptions, SpanEventOptions, SpanStatus, StartSpanOptions, } from 'expo-app-metrics';
7
7
  export { ObserveErrorBoundary } from './ObserveErrorBoundary';
8
8
  export type { ObserveErrorBoundaryProps, ObserveErrorBoundaryFallbackProps, } from './ObserveErrorBoundary';
9
9
  export { ObserveInteractiveMarker } from './ObserveInteractiveMarker';
@@ -12,5 +12,5 @@ export { ObserveRoot } from './ObserveRoot';
12
12
  export { Observe };
13
13
  /** @deprecated Import the named `Observe` export instead. */
14
14
  export default Observe;
15
- export type { ObserveAttribute, ObserveAttributes, ObserveConfig, ObserveIntegrationsConfig, ObserveModule, ObserveModuleEvents, ObserveNavigationIntegrationConfig, ObserveNetworkTracesConfig, ObserveReanimatedIntegrationConfig, } from './types';
15
+ export type { ObserveAttribute, ObserveAttributes, ObserveConfig, ObserveConsent, ObserveEventName, ObserveFeedback, ObserveIntegrationsConfig, ObserveModule, ObserveModuleEvents, ObserveMetricName, ObserveNavigationIntegrationConfig, ObserveNetworkTracesConfig, ObserveReanimatedIntegrationConfig, } from './types';
16
16
  export { useObserve } from './useObserve';
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":[null],"names":["Observe","default","AppMetrics","ObserveErrorBoundary","ObserveInteractiveMarker","ObserveRoot","setBundleDefaults","environment","process","env","NODE_ENV","isJsDev","__DEV__","useObserve"],"mappings":"AAAA,OAAOA,aAAa,WAAW;AAE/B;;CAEC,GACD,SAASC,WAAWC,UAAU,QAAQ,mBAAmB;AAWzD,SAASC,oBAAoB,QAAQ,yBAAyB;AAK9D,SAASC,wBAAwB,QAAQ,6BAA6B;AAEtE,SAASC,WAAW,QAAQ,gBAAgB;AAE5CL,QAAQM,iBAAiB,CAAC;IACxBC,aAAaC,QAAQC,GAAG,CAACC,QAAQ,IAAI;IACrCC,SAAS,CAAC,CAACC;AACb;AAEA,SAASZ,OAAO,GAAG;AAEnB,2DAA2D,GAC3D,eAAeA,QAAQ;AAavB,SAASa,UAAU,QAAQ,eAAe"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":[null],"names":["Observe","default","AppMetrics","ObserveErrorBoundary","ObserveInteractiveMarker","ObserveRoot","setBundleDefaults","environment","process","env","NODE_ENV","isJsDev","__DEV__","useObserve"],"mappings":"AAAA,OAAOA,aAAa,WAAW;AAE/B;;CAEC,GACD,SAASC,WAAWC,UAAU,QAAQ,mBAAmB;AAiBzD,SAASC,oBAAoB,QAAQ,yBAAyB;AAK9D,SAASC,wBAAwB,QAAQ,6BAA6B;AAEtE,SAASC,WAAW,QAAQ,gBAAgB;AAE5CL,QAAQM,iBAAiB,CAAC;IACxBC,aAAaC,QAAQC,GAAG,CAACC,QAAQ,IAAI;IACrCC,SAAS,CAAC,CAACC;AACb;AAEA,SAASZ,OAAO,GAAG;AAEnB,2DAA2D,GAC3D,eAAeA,QAAQ;AAiBvB,SAASa,UAAU,QAAQ,eAAe"}