|
10 | 10 | [](https://www.npmjs.com/package/@sentry/opentelemetry) |
11 | 11 | [](https://www.npmjs.com/package/@sentry/opentelemetry) |
12 | 12 |
|
13 | | -This package allows you to send your OpenTelemetry trace data to Sentry via OpenTelemetry SpanProcessors. |
| 13 | +OpenTelemetry support for Sentry’s JavaScript SDKs. |
14 | 14 |
|
15 | | -If you are using `@sentry/node`, OpenTelemetry support is included out of the box. This package is only necessary if you |
16 | | -are setting up OpenTelemetry support for Sentry yourself. |
| 15 | +## Documentation |
17 | 16 |
|
18 | | -## Installation |
| 17 | +- [OpenTelemetry documentation](https://docs.sentry.io/platforms/javascript/guides/node/opentelemetry/) |
| 18 | +- [Capture spans from OpenTelemetry APIs](https://docs.sentry.io/platforms/javascript/guides/node/opentelemetry/using-opentelemetry-apis/) |
| 19 | +- [Use your own OpenTelemetry pipeline](https://docs.sentry.io/platforms/javascript/guides/node/opentelemetry/custom-setup/) |
19 | 20 |
|
20 | | -```bash |
21 | | -npm install @sentry/opentelemetry |
| 21 | +## Support |
22 | 22 |
|
23 | | -# Or yarn |
24 | | -yarn add @sentry/opentelemetry |
25 | | -``` |
26 | | - |
27 | | -Note that `@sentry/opentelemetry` depends on the following peer dependencies: |
28 | | - |
29 | | -- `@opentelemetry/api` version `1.0.0` or greater |
30 | | - |
31 | | -## Usage |
32 | | - |
33 | | -This package exposes a few building blocks you can add to your OpenTelemetry setup in order to capture OpenTelemetry |
34 | | -traces to Sentry. |
35 | | - |
36 | | -This is how you can use this in your app: |
37 | | - |
38 | | -1. Initialize Sentry, e.g. `@sentry/node`! |
39 | | -2. Call `setupEventContextTrace(client)` |
40 | | -3. Add `SentrySampler` as sampler |
41 | | -4. Add `SentrySpanProcessor` as span processor |
42 | | -5. Register the Sentry context manager (`SentryAsyncLocalStorageContextManager`, or `wrapContextManagerClass` for a custom base) |
43 | | -6. Add `SentryPropagator` as propagator |
44 | | -7. Setup OTEL-powered async context strategy for Sentry via `setOpenTelemetryContextAsyncContextStrategy()` |
45 | | - |
46 | | -For example, you could set this up as follows: |
47 | | - |
48 | | -```js |
49 | | -import * as Sentry from '@sentry/node'; |
50 | | -import { |
51 | | - SentryAsyncLocalStorageContextManager, |
52 | | - SentryPropagator, |
53 | | - SentrySampler, |
54 | | - SentrySpanProcessor, |
55 | | - setupEventContextTrace, |
56 | | - setOpenTelemetryContextAsyncContextStrategy, |
57 | | -} from '@sentry/opentelemetry'; |
58 | | -import { context, propagation, trace } from '@opentelemetry/api'; |
59 | | - |
60 | | -function setupSentry() { |
61 | | - Sentry.init({ |
62 | | - dsn: 'xxx', |
63 | | - }); |
64 | | - |
65 | | - const client = Sentry.getClient(); |
66 | | - setupEventContextTrace(client); |
67 | | - |
68 | | - const provider = new BasicTracerProvider({ |
69 | | - sampler: new SentrySampler(client), |
70 | | - }); |
71 | | - provider.addSpanProcessor(new SentrySpanProcessor()); |
72 | | - |
73 | | - // Initialize the provider |
74 | | - trace.setGlobalTracerProvider(provider); |
75 | | - context.setGlobalContextManager(new SentryAsyncLocalStorageContextManager()); |
76 | | - |
77 | | - setOpenTelemetryContextAsyncContextStrategy(); |
78 | | -} |
79 | | -``` |
80 | | - |
81 | | -A full setup example can be found in |
82 | | -[node-experimental](https://github.com/getsentry/sentry-javascript/blob/develop/packages/node-experimental). |
83 | | - |
84 | | -## Sentry Tracer Provider |
85 | | - |
86 | | -`SentryTracerProvider` is a minimal OpenTelemetry tracer provider which creates native Sentry spans directly. |
87 | | -It is useful when code uses the global OpenTelemetry API and you do not need the full OpenTelemetry SDK span processor |
88 | | -and exporter pipeline. |
89 | | - |
90 | | -```js |
91 | | -import { trace } from '@opentelemetry/api'; |
92 | | -import { SentryTracerProvider } from '@sentry/opentelemetry'; |
93 | | - |
94 | | -trace.setGlobalTracerProvider(new SentryTracerProvider()); |
95 | | - |
96 | | -const span = trace.getTracer('example').startSpan('work'); |
97 | | -span.end(); |
98 | | -``` |
99 | | - |
100 | | -In `@sentry/node`, this is the default tracer provider. |
101 | | - |
102 | | -The `SentryTracerProvider` does not handle OpenTelemetry logs and metrics. |
103 | | - |
104 | | -## Links |
105 | | - |
106 | | -- [Official SDK Docs](https://docs.sentry.io/quickstart/) |
| 23 | +- [Report a bug](https://github.com/getsentry/sentry-javascript/issues/new/choose) |
| 24 | +- [Contributing](https://github.com/getsentry/sentry-javascript/blob/develop/CONTRIBUTING.md) |
0 commit comments