Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Liza Mock <liza.mock@sentry.io>
  • Loading branch information
mydea and lizokm authored Jul 31, 2024
1 parent dacaa4a commit a86ebe7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Using Custom OpenTelemetry Instrumentation
description: "How to use custom OpenTelemetry instrumentation with Sentry."
title: Custom OpenTelemetry Instrumentation
description: "Learn how to use custom OpenTelemetry instrumentation with Sentry."
supported:
- javascript.nextjs
- javascript.node
Expand All @@ -20,7 +20,7 @@ notSupported:
- javascript
---

While the Sentry SDK includes some OpenTelemetry instrumentation out of the box, you may want to add additional instrumentation to your application. This can be done by registering the instrumentation through OpenTelemetry like this:
While the Sentry SDK includes some OpenTelemetry instrumentation out of the box, you may want to add additional instrumentation to your application. This can be done by registering the instrumentation through OpenTelemetry like the example below:

```javascript
const Sentry = require("@sentry/node");
Expand All @@ -39,6 +39,4 @@ Sentry.init({
Sentry.addOpenTelemetryInstrumentation(new GenericPoolInstrumentation());
```

Any instrumentation added like this will be automatically picked up by Sentry.

Alternatively, any instrumentation added via `registerInstrumentations()` from `@opentelemetry/instrumentation` will also be picked up by Sentry.
Any instrumentation added like this or via `registerInstrumentations()` from `@opentelemetry/instrumentation` will be picked up by Sentry.
28 changes: 10 additions & 18 deletions docs/platforms/javascript/common/opentelemetry/custom-setup.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Using a Custom OpenTelemetry Setup
description: "How to use use a completely custom OpenTelemetry setup with Sentry."
title: Using Your Existing OpenTelemetry Setup
description: "Learn how to use your existing custom OpenTelemetry setup with Sentry."
supported:
- javascript.nextjs
- javascript.node
Expand All @@ -21,10 +21,7 @@ notSupported:
sidebar_order: 0
---

If you already have OpenTelemetry set up yourself, you can also use your existing setup.

In this case, you need to set `skipOpenTelemetrySetup: true` in your `init({})` config, and ensure you setup all the
components that Sentry needs yourself. In this case, you need to install `@sentry/opentelemetry`, and add the following:
To use an existing OpenTelemetry setup, set `skipOpenTelemetrySetup: true` in your `init({})` config, then set up all the components that Sentry needs yourself. Finish by installing `@sentry/opentelemetry` and adding the following:

```javascript
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
Expand Down Expand Up @@ -66,28 +63,23 @@ provider.register({
Sentry.validateOpenTelemetrySetup();
```

Make sure that all <PlatformLink to="/opentelemetry/required-instrumentation/">Required OpenTelemetry Instrumentation</PlatformLink> is set up correctly - otherwise, the Sentry SDK may not work as expected!
Make sure that all <PlatformLink to="/opentelemetry/required-instrumentation/">Required OpenTelemetry Instrumentation</PlatformLink> is set up correctly. Otherwise, the Sentry SDK may not work as expected.

## Using Sentry for Error Monitoring only
## Using Sentry for Error Monitoring Only

If you have a custom OpenTelemetry setup and only want to use Sentry for error monitoring, you can skip adding the `SentrySpanProcessor`. You will still need to add the `SentryContextManager`, `SentryPropagator` and `SentrySampler` to your setup even if you don't want to send any tracing data to Sentry. See below on an explanation of why this is needed.
If you have a custom OpenTelemetry setup and only want to use Sentry for error monitoring, you can skip adding the `SentrySpanProcessor`. You'll still need to add the `SentryContextManager`, `SentryPropagator`, and `SentrySampler` to your setup even if you don't want to send any tracing data to Sentry. Read on to learn why this is needed.

## Why do I need to do this?

In order for the Sentry SDK to work as expected, and for it to be in sync with OpenTelemetry, we need a few components to be in place. These are needed even if you only use Sentry for error monitoring:

- **SentryContextManager**: Ensures that the OpenTelemetry context is in sync with Sentry, for example to correctly isolate data between simultaneous requests.
- **SentrySampler**: Ensures that the Sentry `tracesSampleRate` is respected. Even if you do not use Sentry for tracing, you still need this in order for trace propagation to work as expected. See <PlatformLink to='/opentelemetry/sampler'>Using a Custom OpenTelemetry Sampler</PlatformLink> if you want to use a custom sampler.
- **SentryPropagator**: Ensures that trace propagation works correctly.
- <PlatformLink to="/opentelemetry/required-instrumentation">Required Instrumentation</PlatformLink>: Ensures that trace propagation works correctly.
**Additional components needed to also use Sentry for tracing:**

- **SentrySpanProcessor**: Ensures that spans are correctly sent to Sentry.

<Note>
Trace propagation is needed for Sentry to automatically connect services (e.g.
frontend and backend, or different backend services) together. This makes it
possible to see related errors across services.
<PlatformLink to="/tracing/trace-propagation">Learn more about Trace Propagation.</PlatformLink>
Trace propagation is needed for Sentry to automatically connect services together. (For example, if you want to connect the frontend and backend, or different backend services.) This makes it possible to see related errors across services. <PlatformLink to="/tracing/trace-propagation">Learn more about Trace Propagation.</PlatformLink>
</Note>

In addition, the following is only needed if you also use Sentry for tracing:

- **SentrySpanProcessor**: Ensures that spans are correctly sent to Sentry.
6 changes: 3 additions & 3 deletions docs/platforms/javascript/common/opentelemetry/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: OpenTelemetry Support
description: "Using OpenTelemetry with Sentry."
description: "Learn how to use OpenTelemetry with Sentry."
sidebar_order: 7000
supported:
- javascript.nextjs
Expand All @@ -21,10 +21,10 @@ notSupported:
- javascript
---

The Sentry SDK uses [OpenTelemetry](https://opentelemetry.io/) under the hood. This means that any OpenTelemetry instrumentation that emits spans will automatically be picked up by Sentry - no further configuration needed!
The Sentry SDK uses [OpenTelemetry](https://opentelemetry.io/) under the hood. This means that any OpenTelemetry instrumentation that emits spans will automatically be picked up by Sentry without any further configuration.

To start capturing traces and spans, set up <PlatformLink to='/tracing'>Tracing and Performance Monitoring with your Sentry SDK</PlatformLink>. If you don't use tracing, Sentry still connects to OpenTelemetry under the hood to ensure that context isolation and trace propagation works correctly.

By default, Sentry will automatically set up OpenTelemetry for you. However, you can also use your own OpenTelemetry setup with Sentry. Read the guides below to learn how to use a custom OpenTelemetry setup with Sentry, or how to get the most out of the Sentry & OpenTelemetry integration.
By default, Sentry will automatically set up OpenTelemetry for you, but you can also use your own OpenTelemetry setup. Read the guides below to learn how to use a custom OpenTelemetry setup or how to get the most out of the Sentry and OpenTelemetry integration.

<PageGrid />
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Using an OpenTelemetry Tracer
description: "How to use an OpenTelemetry Tracer with Sentry."
title: OpenTelemetry Tracer
description: "Learn how to use an OpenTelemetry Tracer with Sentry."
supported:
- javascript.nextjs
- javascript.node
Expand All @@ -20,7 +20,7 @@ notSupported:
- javascript
---

We recommend using `Sentry.startSpan()` and related APIs to create spans. However, you can also use native OpenTelemetry APIs to create spans.
We recommend using `Sentry.startSpan()` and related APIs to create spans, but you can also create spans using native OpenTelemetry APIs.

You can access the tracer Sentry uses via `client.tracer` and then create spans with OpenTelemetry APIs, as shown below:

Expand All @@ -34,4 +34,4 @@ tracer.startActiveSpan("span name", () => {
});
```
You can also use any other tracer; all OpenTelemetry spans will be picked up by Sentry automatically.
You can also use any other tracer. All OpenTelemetry spans will be picked up by Sentry automatically.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Required OpenTelemetry Instrumentation
description: "Read about required OpenTelemetry instrumentation for Sentry."
description: "Learn about required OpenTelemetry instrumentation for Sentry."
supported:
- javascript.nextjs
- javascript.node
Expand All @@ -20,7 +20,7 @@ notSupported:
- javascript
---

By default, Sentry will register a series of OpenTelemetry instrumentation to automatically capture spans for things spanning incoming and outgoing HTTP requests, DB queries and more.
By default, Sentry will register OpenTelemetry instrumentation to automatically capture spans for traces spanning incoming and outgoing HTTP requests, DB queries, and more.

If tracing is not enabled (no `tracesSampleRate` is defined in the SDK configuration), only a minimal amount of OpenTelemetry instrumentation will be registered. This includes the following:

Expand Down
7 changes: 3 additions & 4 deletions docs/platforms/javascript/common/opentelemetry/sampler.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Using a Custom OpenTelemetry Sampler
description: "How to use a custom OpenTelemetry Sampler with Sentry."
title: Custom OpenTelemetry Sampler
description: "Learn how to use a custom OpenTelemetry Sampler with Sentry."
supported:
- javascript.nextjs
- javascript.node
Expand All @@ -20,8 +20,7 @@ notSupported:
- javascript
---

We recommend using `SentrySampler` as this will ensure the correct subset of traces is sent to Sentry depending on your `tracesSampleRate`, as well as that all other Sentry features like trace propagation work as expected.
If you however need to use your own sampler then make sure to wrap your `SamplingResult` with our `wrapSamplingDecision` method:
While you can use your own sampler, we recommend that you use the `SentrySampler`. This will ensure that the correct subset of traces will be sent to Sentry, based on your `tracesSampleRate`. It will also ensure that all other Sentry features like trace propagation work as expected. If you do need to use your own sampler, make sure to wrap your `SamplingResult` with our `wrapSamplingDecision` method like in the example below:

```javascript
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ notSupported:
- javascript
---

When using the default OpenTelemetry setup from Sentry, you can access the tracer provider that Sentry set up for you. This makes it easy to for example add additional span processors, if you want to send span data to another backend, or similar.
You can access the tracer provider set up by Sentry when using Sentry's default OpenTelemetry instrumentation. This makes it easy to, for example, add additional span processors if you want to send span data to another backend or similar.

```javascript
const Sentry = require("@sentry/node");
Expand Down

0 comments on commit a86ebe7

Please sign in to comment.