Skip to content

Commit 5869e9f

Browse files
committed
chore: updated quick-start guide for interop-otel package
1 parent 727ccab commit 5869e9f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

docs/docs/docs/interop-otel/quick-start.mdx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,80 @@ The global C++ Tracer and Meter Providers are registered - respectively - from `
3131
> [!WARNING]
3232
> Invoking the aforementioned install methods more than once will discard all previously registered C++ tracer/meter exporters. It is important to first register all the tracer/meter exporters in JS, and then call the `register()` methods of `OttreliteTracerProvider` and `OttreliteMeterProvider` in JS.
3333
34+
```typescript
35+
import { resourceFromAttributes } from '@opentelemetry/resources';
36+
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
37+
import {
38+
ATTR_SERVICE_NAME,
39+
ATTR_SERVICE_VERSION,
40+
} from '@opentelemetry/semantic-conventions';
41+
import {
42+
DevSpanProcessorInterceptor,
43+
OttreliteExporterOTLP,
44+
OttreliteMeterProvider,
45+
OttreliteTracerProvider,
46+
} from '@ottrelite/interop-otel';
47+
48+
// optional step: resource attributes; below: example options, this can be customized as needed
49+
const resource = resourceFromAttributes({
50+
[ATTR_SERVICE_NAME]: appName,
51+
[ATTR_SERVICE_VERSION]: getVersion(),
52+
'device.id': getDeviceId(),
53+
'os.name': Platform.OS,
54+
'os.version': getSystemVersion(),
55+
});
56+
57+
const tracerProvider = new OttreliteTracerProvider({
58+
spanProcessors: [
59+
// optional step: configure Ottrelite's span processor (required for live tracing in dev)
60+
new DevSpanProcessorInterceptor(),
61+
62+
// optional step: configure Ottrelite's actual exporter using a preferred processor of choice
63+
new SimpleSpanProcessor(
64+
new OttreliteExporterOTLP({
65+
endpoint: 'http://localhost:4318/v1/',
66+
})
67+
),
68+
],
69+
resource,
70+
});
71+
72+
// register the React Native tracer provider
73+
tracerProvider.register();
74+
75+
// configure the OpenTelemetry MeterProvider to use Ottrelite's capabilities
76+
const meterProvider = new OttreliteMeterProvider({
77+
resource,
78+
});
79+
80+
meterProvider.register();
81+
```
82+
83+
##### OTEL Instrumentations
84+
85+
Optionally, configure automatic instrumentation of various JS APIs using OpenTelemetry community instrumentations.
86+
87+
```typescript
88+
import { registerInstrumentations } from '@opentelemetry/instrumentation';
89+
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';
90+
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request';
91+
92+
// optional step: register instrumentations; Ottrelite integrates with the OTEL JS API, therefore allowing to
93+
// use the same instrumentations as you would with OpenTelemetry JS
94+
// the below example shows a few common instrumentations, but you can add more as needed, inspired by https://opentelemetry.io/docs/demo/services/react-native-app/
95+
registerInstrumentations({
96+
instrumentations: [
97+
new FetchInstrumentation({
98+
clearTimingResources: false,
99+
propagateTraceHeaderCorsUrls: /.*/,
100+
}),
101+
new XMLHttpRequestInstrumentation({
102+
ignoreUrls: [/\/fetch-urls\/.*/],
103+
}),
104+
],
105+
});
106+
```
107+
34108
#### Configuration
35109

36110
The `Ottrelite.install` method accepts 3 C++ OTEL SDK - specific configuration options:

0 commit comments

Comments
 (0)