react-native-otel 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/README.md +13 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -581,18 +581,8 @@ class MySampler implements Sampler {
|
|
|
581
581
|
Span processors run synchronously at span start and end. Use them to enrich spans with extra attributes, filter spans, or forward to a custom exporter without going through the SDK exporter chain.
|
|
582
582
|
|
|
583
583
|
```ts
|
|
584
|
-
import {
|
|
585
|
-
|
|
586
|
-
NoopSpanProcessor,
|
|
587
|
-
} from 'react-native-otel';
|
|
588
|
-
import type { SpanProcessor, ReadonlySpan } from 'react-native-otel';
|
|
589
|
-
import type { Span } from 'react-native-otel';
|
|
590
|
-
|
|
591
|
-
// SimpleSpanProcessor: wraps an exporter — calls export() immediately on end().
|
|
592
|
-
otel.init({
|
|
593
|
-
serviceName: 'my-app',
|
|
594
|
-
processors: [new SimpleSpanProcessor(myCustomExporter)],
|
|
595
|
-
});
|
|
584
|
+
import { SimpleSpanProcessor } from 'react-native-otel';
|
|
585
|
+
import type { SpanProcessor, ReadonlySpan, Span } from 'react-native-otel';
|
|
596
586
|
|
|
597
587
|
// Custom processor: enrich every span with a 'session.id' attribute.
|
|
598
588
|
class SessionProcessor implements SpanProcessor {
|
|
@@ -605,7 +595,10 @@ class SessionProcessor implements SpanProcessor {
|
|
|
605
595
|
otel.init({
|
|
606
596
|
serviceName: 'my-app',
|
|
607
597
|
exporter: new OtlpHttpExporter({ endpoint: '...' }),
|
|
608
|
-
processors: [
|
|
598
|
+
processors: [
|
|
599
|
+
new SessionProcessor(), // enrich spans
|
|
600
|
+
new SimpleSpanProcessor(myExporter), // also forward to a second exporter
|
|
601
|
+
],
|
|
609
602
|
});
|
|
610
603
|
```
|
|
611
604
|
|
|
@@ -911,8 +904,6 @@ otel.init({
|
|
|
911
904
|
});
|
|
912
905
|
```
|
|
913
906
|
|
|
914
|
-
> `AsyncStorage` is not compatible — the adapter must be synchronous.
|
|
915
|
-
|
|
916
907
|
---
|
|
917
908
|
|
|
918
909
|
## Connectivity-Aware Flushing
|
|
@@ -973,12 +964,17 @@ navigation.reset({ routes: [{ name: 'Login' }] });
|
|
|
973
964
|
|
|
974
965
|
### otel.shutdown()
|
|
975
966
|
|
|
976
|
-
Ends the active screen span, flushes all buffers, clears flush timers, and removes the network listener.
|
|
967
|
+
Ends the active screen span, flushes all buffers, clears flush timers, and removes the network listener. Call it once when the application is truly done — for example, during a logout flow or before a controlled restart. It is a one-way teardown; do not call it on every background transition.
|
|
977
968
|
|
|
978
969
|
```ts
|
|
970
|
+
// Flush buffered data when the app moves to the background.
|
|
979
971
|
AppState.addEventListener('change', (state) => {
|
|
980
|
-
if (state === 'background') otel.
|
|
972
|
+
if (state === 'background') otel.flush();
|
|
981
973
|
});
|
|
974
|
+
|
|
975
|
+
// Full teardown on logout (optional).
|
|
976
|
+
await api.logout();
|
|
977
|
+
await otel.shutdown();
|
|
982
978
|
```
|
|
983
979
|
|
|
984
980
|
---
|