---
title: "OpenTelemetry OTLP"
description: "Using OpenTelemetry OTLP export with Sentry."
url: https://docs.sentry.io/platforms/java/guides/log4j2/opentelemetry/setup/otlp/
---

# OpenTelemetry OTLP | Sentry for Log4j 2.x

Use the `sentry-opentelemetry-otlp` module when you want OpenTelemetry to handle tracing (with spans exported via OTLP to Sentry) while Sentry handles errors, logs, and metrics. Sentry reads trace and span IDs from the OpenTelemetry `Context` so that all Sentry events are correlated with your OpenTelemetry traces.

Unlike the [Agent](https://docs.sentry.io/platforms/java/guides/log4j2/opentelemetry/setup/agent.md) and [Agentless](https://docs.sentry.io/platforms/java/guides/log4j2/opentelemetry/setup/agentless.md) integrations, this module does not use OpenTelemetry for scope storage or span creation within the Sentry SDK.

## [Install](https://docs.sentry.io/platforms/java/guides/log4j2/opentelemetry/setup/otlp.md#install)

```groovy
implementation 'io.sentry:sentry-opentelemetry-otlp:8.37.1'
```

This includes the OpenTelemetry SDK autoconfiguration and OTLP exporter as transitive dependencies. If you configure the OpenTelemetry SDK manually without autoconfiguration, you can exclude `opentelemetry-sdk-extension-autoconfigure` to prevent it from discovering and activating components via SPI.

## [Setup](https://docs.sentry.io/platforms/java/guides/log4j2/opentelemetry/setup/otlp.md#setup)

You need to configure both OpenTelemetry (to export spans via OTLP to Sentry) and Sentry (to read trace/span IDs from OpenTelemetry).

The OTLP endpoint and authentication details are shown in the code examples below. You can also find the **OTLP Traces Endpoint** and **OTLP Traces Endpoint Headers** in your Sentry project under **Settings > Projects > \[Project] > Client Keys (DSN)**.

Initialize OpenTelemetry using `AutoConfiguredOpenTelemetrySdk`, then initialize Sentry with the `OpenTelemetryOtlpEventProcessor`:

```java
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.sentry.Sentry;
import io.sentry.opentelemetry.otlp.OpenTelemetryOtlpEventProcessor;

// 1. Configure OpenTelemetry
AutoConfiguredOpenTelemetrySdk.builder()
    .setResultAsGlobal()
    .addPropertiesSupplier(() -> {
        Map<String, String> properties = new HashMap<>();
        properties.put("otel.traces.exporter", "otlp");
        properties.put("otel.exporter.otlp.traces.endpoint", "___OTLP_TRACES_URL___");
        properties.put("otel.exporter.otlp.traces.protocol", "http/protobuf");
        properties.put("otel.exporter.otlp.traces.headers", "x-sentry-auth=sentry sentry_key=___PUBLIC_KEY___");
        properties.put("otel.propagators", "sentry");
        properties.put("otel.logs.exporter", "none");
        properties.put("otel.metrics.exporter", "none");
        return properties;
    })
    .build();

// 2. Initialize Sentry
Sentry.init(options -> {
    options.setDsn("___PUBLIC_DSN___");
    // Link Sentry events to OpenTelemetry traces
    options.addEventProcessor(new OpenTelemetryOtlpEventProcessor());
});
```

## [Sampling](https://docs.sentry.io/platforms/java/guides/log4j2/opentelemetry/setup/otlp.md#sampling)

The Sentry propagator inherits the sampling decision from the incoming `sentry-trace` header. When no sampling flag is present (deferred decision), it defaults to sampled.

##### Deferred Sampling

If you need to control sampling for deferred traces, you have to implement a custom OpenTelemetry `Sampler`.
