Frameworks 14 min read

OpenTelemetry in Spring Boot: tracing, metrics and logs

Three supported ways to get traces, metrics and logs out of a Spring Boot app over OTLP, what each one instruments, and how to fix the problems that come with them. Tested with Spring Boot 4.2 and 3.5 and OpenTelemetry Java instrumentation 2.34 (November 2026).

David Granzin By David Granzin

There are three ways to add OpenTelemetry to a Spring Boot application, and most confusion comes from mixing them. The OpenTelemetry project ships a Java agent and a Spring Boot starter. Spring Boot ships its own tracing, built on Micrometer. All three send OTLP, so any backend or Collector accepts the result.

Key takeaways

  • The Java agent needs no code changes and covers the most libraries. Use a starter for GraalVM native images or when you cannot add a JVM flag.
  • Spring Boot's own tracing samples 10% of requests by default. The agent and the OpenTelemetry starter sample 100%.
  • Spring Boot 4.1 and later read the standard OTEL_* environment variables. Spring Boot 3 and 4.0 need management.* properties.
  • Pick one. The agent next to Micrometer Tracing records every request twice.

Quick start

The shortest route to a trace needs no code change: download the Java agent, set three variables, add one JVM flag.

curl -L -o opentelemetry-javaagent.jar \
  https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

export OTEL_SERVICE_NAME="orders"
export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production"

java -javaagent:./opentelemetry-javaagent.jar -jar target/orders.jar

Send a request and the app exports traces, metrics and logs as http/protobuf to port 4318. With no Collector yet, set OTEL_TRACES_EXPORTER=console to print spans to stdout.

Three ways to instrument Spring Boot

This section helps you pick one of the three before you install anything.

Two questions settle most cases. The table below has the details behind each branch.

Java agentOpenTelemetry starterSpring Boot + Micrometer
How you add it-javaagent JVM flagopentelemetry-spring-boot-starterspring-boot-starter-opentelemetry (Boot 4)
Maintained byOpenTelemetryOpenTelemetrySpring
Code changesNoneA dependencyA dependency
Library coverageWidest: well over a hundred libraries and frameworksSpring MVC, WebFlux, HTTP clients, JDBC, R2DBC, Kafka, MongoDB, LogbackWhat Spring instruments with the Observation API. JDBC needs an extra library.
ConfigurationOTEL_* variables or -Dotel.*otel.* in application.yml, or OTEL_*management.* in application.yml; OTEL_* from Boot 4.1
Default sampling100%100%10%
Logs over OTLPAutomaticAutomaticExporter included, you add the Logback appender
GraalVM native imageNoYesYes

The agent also reaches libraries the other two do not, such as the JDK HTTP client, gRPC, Redis clients and schedulers. The OpenTelemetry starter is the pick when another agent already occupies the JVM or startup time matters.

Option 1: the OpenTelemetry Java agent

The agent is a single jar that rewrites bytecode as classes load, on Java 8 and later. In a container, set JAVA_TOOL_OPTIONS="-javaagent:/opt/opentelemetry-javaagent.jar" so the entrypoint stays unchanged.

With the console exporter, one request to the test app printed this (attributes trimmed, database name shortened):

[otel.javaagent] LoggingSpanExporter - 'SELECT shop.orders' : 4bf92f3577b34da6a3ce929d0e0e4736 888a2f7b10efa275 CLIENT [tracer: io.opentelemetry.jdbc:2.34.0-alpha] {db.system=h2, db.name=shop, db.operation=SELECT, db.sql.table=orders, db.statement=select count(*) from orders where id = ?}
[otel.javaagent] LoggingSpanExporter - 'GET' : 4bf92f3577b34da6a3ce929d0e0e4736 f2e8d0a023849575 CLIENT [tracer: io.opentelemetry.java-http-client:2.34.0-alpha] {http.request.method=GET, url.full=http://localhost:8080/inventory/42, http.response.status_code=200}
[otel.javaagent] LoggingSpanExporter - 'calculate-price' : 4bf92f3577b34da6a3ce929d0e0e4736 0e27ef4e6bfff042 INTERNAL [tracer: io.opentelemetry.opentelemetry-instrumentation-annotations-1.16:2.34.0-alpha] {order.id=42, code.function=price}
[otel.javaagent] LoggingSpanExporter - 'GET /orders/{id}' : 4bf92f3577b34da6a3ce929d0e0e4736 e4ec20f1cb9ecc2b SERVER [tracer: io.opentelemetry.tomcat-10.0:2.34.0-alpha] {http.route=/orders/{id}, http.request.method=GET, url.path=/orders/42, http.response.status_code=200}

Each line is one span: name, trace ID, span ID, kind and the instrumentation behind it. The server span is named after the route template, and SQL literals are replaced with ?.

One request, five spans, one trace ID. Span names and instrumentation names are from the agent run; bar lengths are approximate.

Option 2: the OpenTelemetry Spring Boot starter

The starter configures the same OpenTelemetry SDK from inside the application context. Import the instrumentation BOM first, before any other BOM, so every OpenTelemetry artifact resolves to one version.

pom.xml

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.opentelemetry.instrumentation</groupId>
      <artifactId>opentelemetry-instrumentation-bom</artifactId>
      <version>2.34.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-spring-boot-starter</artifactId>
  </dependency>
  <!-- Needed for @WithSpan. Named spring-boot-starter-aop on Spring Boot 3. -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aspectj</artifactId>
  </dependency>
</dependencies>

In Gradle: implementation(platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:2.34.0")) and implementation("io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter").

With no configuration it exports all three signals to http://localhost:4318 and takes service.name from spring.application.name. It reads OTEL_* variables and the same settings as otel.* properties:

application.yml

spring:
  application:
    name: orders          # becomes service.name

otel:
  exporter:
    otlp:
      endpoint: http://localhost:4318
      protocol: http/protobuf
      headers:
        Authorization: Bearer YOUR_KEY
  resource:
    attributes:
      deployment.environment.name: production
  traces:
    sampler: parentbased_traceidratio
    sampler.arg: "0.1"

On Spring Boot 4.2 this produced Spring MVC server spans, RestClient client spans, JDBC spans with sanitized SQL and log records, with no extra code.

Option 3: Spring Boot's own tracing with Micrometer and OTLP

Spring instruments its own libraries with the Micrometer Observation API: one observation becomes a timer metric and a span. The OpenTelemetry bridge creates the span in the OpenTelemetry SDK and an OTLP exporter ships it. On Spring Boot 4 this is one starter:

pom.xml

<!-- Spring Boot 4: one starter for traces, metrics and the OTLP exporters -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-opentelemetry</artifactId>
</dependency>

Traces are not exported until you set an endpoint. On Spring Boot 4.2 one base URL covers traces, metrics and logs:

application.yml

spring:
  application:
    name: orders
  task:
    execution:
      propagate-context: true      # trace context in @Async, Boot 4.1+

management:
  opentelemetry:
    otlp:
      endpoint: http://localhost:4318   # base URL for all signals, Boot 4.2+
      headers:
        Authorization: Bearer YOUR_KEY
    resource-attributes:
      deployment.environment.name: production
  tracing:
    sampling:
      probability: 1.0             # the default is 0.1
  observations:
    conventions: open-telemetry    # OTel span names and attributes, Boot 4.2+
    annotations:
      enabled: true                # turns on @Observed

The properties moved between releases, so older tutorials no longer match. As of November 2026:

Spring BootWhat changed
3.xNo starter. Trace endpoint is management.otlp.tracing.endpoint, a full URL ending in /v1/traces.
4.0spring-boot-starter-opentelemetry arrives. Endpoint moves to management.opentelemetry.tracing.export.otlp.endpoint; the old name still works but is deprecated.
4.1OTEL_* environment variables are mapped to Spring properties. Adds management.opentelemetry.tracing.sampler and spring.task.execution.propagate-context.
4.2Adds the shared management.opentelemetry.otlp.endpoint base URL and management.observations.conventions.

Each version links to its release notes. Every property is in the application properties appendix; the variable mapping is in the observability reference.

On Spring Boot 3 you assemble the same thing from three dependencies and the older property:

pom.xml

<!-- Spring Boot 3: no starter, add the pieces yourself -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
  <groupId>io.opentelemetry</groupId>
  <artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>

application.yml

# Spring Boot 3.x, and still accepted (deprecated) on 4.x
management:
  otlp:
    tracing:
      endpoint: http://localhost:4318/v1/traces   # full URL, path included
      headers:
        Authorization: Bearer YOUR_KEY
  tracing:
    sampling:
      probability: 1.0

Spring Boot manages these versions, so leave the version tags out.

application.yml vs OTEL_* environment variables

Use the standard variables for anything that differs per environment. They work with the agent, the OpenTelemetry starter and Spring Boot 4.1 or later, and they configure every other OpenTelemetry SDK you run.

export OTEL_SERVICE_NAME="orders"
export OTEL_EXPORTER_OTLP_ENDPOINT="http://otel-collector:4318"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_KEY"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production,service.version=1.4.2"
export OTEL_TRACES_SAMPLER="parentbased_traceidratio"
export OTEL_TRACES_SAMPLER_ARG="0.1"
  • OTEL_EXPORTER_OTLP_ENDPOINT is a base URL. The exporter appends /v1/traces, /v1/metrics and /v1/logs. Spring's per-signal properties, such as management.otlp.tracing.endpoint, are full URLs and need the path.
  • The agent reads one key from application.yml. It starts before Spring and ignores otel.* and management.* properties. The exception is spring.application.name: a resource detector looks for it on the command line, in the environment and in the application and bootstrap files, and uses it as service.name when you set none. Everything else goes in environment variables, -Dotel.* system properties or the file named by OTEL_JAVAAGENT_CONFIGURATION_FILE.
  • Environment variables win. With one endpoint in application.yml and another in OTEL_EXPORTER_OTLP_ENDPOINT, the Spring Boot 4.2 test app exported to the variable's. The OpenTelemetry starter does the same. management.opentelemetry.map-environment-variables=false switches Spring's mapping off.

What gets traced: routes, JDBC, RestClient and WebClient

This section compares the spans each option records for the same controller: a route with a path variable, a query and an outgoing call.

OrderController.java

@RestController
class OrderController {
    private final JdbcClient jdbc;
    private final RestClient rest;

    // Inject the builder. RestClient.create() skips the instrumentation
    // in the starter and in Spring Boot's own tracing.
    OrderController(JdbcClient jdbc, RestClient.Builder builder) {
        this.jdbc = jdbc;
        this.rest = builder.baseUrl("http://inventory:8080").build();
    }

    @GetMapping("/orders/{id}")
    Map<String, Object> order(@PathVariable long id) {
        Integer found = jdbc.sql("select count(*) from orders where id = ?")
                .param(id).query(Integer.class).single();
        String stock = rest.get().uri("/inventory/{id}", id).retrieve().body(String.class);
        return Map.of("id", id, "found", found, "stock", stock);
    }
}
Java agentOpenTelemetry starterSpring Boot + Micrometer
Server span nameGET /orders/{id}GET /orders/{id}http get /orders/{id}, or GET /orders/{id} with OpenTelemetry conventions
Route attributehttp.routehttp.routeuri, or http.route with OpenTelemetry conventions
RestClient spanYes, any instanceYes, when built from the injected builderYes, when built from the injected builder
JDBC spanSELECT shop.ordersSELECT shop.ordersNone by default
SQL textLiterals replaced with ?Literals replaced with ?n/a
  • Route naming. All three name the server span after the mapping pattern, so /orders/42 and /orders/43 group together. A request that matches no controller is named GET /**, which is where scanner traffic and 404s end up.
  • Conventions. Spring Boot's default names follow Micrometer. On 4.2, management.observations.conventions=open-telemetry gives server spans http.request.method, http.response.status_code and http.route.
  • HTTP clients. The starter and Spring Boot instrument RestClient, RestTemplate and WebClient through the builder beans. A client from RestClient.create() or WebClient.create() gets no span and sends no traceparent header, which breaks context propagation. Inject the builder. The agent instruments the HTTP library underneath, so any client works.
  • JDBC. Spring Boot creates no spans for SQL. net.ttddyy.observation:datasource-micrometer-spring-boot wraps the DataSource; version 2.3.1 on Spring Boot 4.2 produced connection, query and result-set spans per statement, with the SQL in jdbc.query[0]. That is three spans where the agent and the OpenTelemetry starter emit one.

Custom spans with @WithSpan and @Observed

Add your own spans with one annotation. With the agent or the OpenTelemetry starter that is @WithSpan from opentelemetry-instrumentation-annotations; @SpanAttribute records a parameter and Span.current() returns the active span.

PricingService.java

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.instrumentation.annotations.SpanAttribute;
import io.opentelemetry.instrumentation.annotations.WithSpan;

@Service
class PricingService {
    @WithSpan("calculate-price")
    long price(@SpanAttribute("order.id") long orderId) {
        Span.current().setAttribute("pricing.currency", "EUR");
        return orderId * 100;
    }
}

The agent weaves this into any method. The starter uses Spring AOP: the class must be a bean, the call must come from another bean, the method cannot be private, and the AspectJ starter must be on the classpath (see @WithSpan does nothing).

With Spring Boot's own tracing the equivalent is @Observed, which needs the same AspectJ starter and management.observations.annotations.enabled=true:

PricingService.java

import io.micrometer.observation.annotation.Observed;

@Service
class PricingService {
    // One annotation, a span and a timer metric
    @Observed(name = "pricing.calculate", contextualName = "calculate-price")
    long price(long orderId) {
        return orderId * 100;
    }
}

contextualName becomes the span name and name the metric name. Keep unbounded values such as user IDs off metrics; the cardinality guide explains why.

Logs with trace_id

Getting the trace ID into logs has two parts: printing it in console or file logs, and exporting log records over OTLP.

The agent and the OpenTelemetry starter add the lower path on their own. With Spring Boot's own tracing you add the appender yourself.

Printing it. All three options put the IDs in the SLF4J MDC, under different keys:

MDC keysPrinted by default
Spring Boot + MicrometertraceId, spanIdYes, since Spring Boot 3.2
Java agent, OpenTelemetry startertrace_id, span_id, trace_flagsNo, set the pattern below

application.yml

logging:
  pattern:
    correlation: "[%X{trace_id:-},%X{span_id:-}] "
INFO 80045 --- [orders] [io-8080-exec-2] [4bf92f3577b34da6a3ce929d0e0e4736,e4ec20f1cb9ecc2b] c.e.demo.OrderController : loading order 42
INFO 80045 --- [orders] [io-8080-exec-3] [4bf92f3577b34da6a3ce929d0e0e4736,2d0feb503a535ef5] c.e.demo.OrderController : checking inventory 42
INFO 80045 --- [orders] [        task-1] [4bf92f3577b34da6a3ce929d0e0e4736,e4ec20f1cb9ecc2b] c.e.demo.Mailer          : sending receipt for 42

Two requests in one trace, plus an @Async task that kept the caller's IDs. In JSON logs the same MDC keys become fields with no pattern.

Exporting it. The agent and the OpenTelemetry starter attach a Logback appender themselves. Spring Boot includes the OTLP log exporter but leaves Logback alone: add io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0 (2.34.0-alpha), declare the appender and hand it the SDK.

<!-- src/main/resources/logback-spring.xml -->
<configuration>
  <include resource="org/springframework/boot/logging/logback/base.xml"/>
  <appender name="OTEL"
      class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender"/>
  <root level="INFO">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="OTEL"/>
  </root>
</configuration>

OtelLogbackInstaller.java

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender;

// Hands Spring Boot's OpenTelemetry instance to the Logback appender.
@Component
class OtelLogbackInstaller implements InitializingBean {
    private final OpenTelemetry openTelemetry;

    OtelLogbackInstaller(OpenTelemetry openTelemetry) {
        this.openTelemetry = openTelemetry;
    }

    @Override
    public void afterPropertiesSet() {
        OpenTelemetryAppender.install(openTelemetry);
    }
}

The appender buffers lines written before the context is ready and sends them once install runs. If a Collector already tails your log files, skip OTLP log export or you pay for every line twice.

Metrics

All three options export metrics over OTLP every 60 seconds once an endpoint is set. The metric names differ:

  • Java agent. OpenTelemetry-named metrics: http.server.request.duration, http.client.request.duration, jvm.gc.duration and the other jvm.* metrics, and connection pool metrics such as db.client.connections.usage.
  • OpenTelemetry starter. http.server.request.duration and the jvm.* runtime metrics (jvm.memory.used, jvm.thread.count, jvm.cpu.time).
  • Spring Boot. Everything Micrometer records, sent by its OTLP registry under Micrometer's names: jvm.memory.used, hikaricp.connections.usage, tomcat.sessions.active.current, http.client.requests, plus a timer for each @Observed method.

With the agent and the OpenTelemetry starter, OTEL_METRIC_EXPORT_INTERVAL (milliseconds) sets the interval and OTEL_METRICS_EXPORTER=none turns metrics off. Spring Boot 4.2 sends metrics to the shared management.opentelemetry.otlp.endpoint. On earlier versions the metrics URL is a property of its own:

application.yml

# Spring Boot 3.x and 4.x: a full URL, path included
management:
  otlp:
    metrics:
      export:
        url: http://localhost:4318/v1/metrics
        step: 30s          # the default is 1m

A dashboard built on the agent's http.server.request.duration shows nothing for a Micrometer service, which reports http.server.requests. Decide per fleet, not per service.

Production settings

Six settings to check before the first deploy.

  • Resource attributes. Set service.name, service.version and deployment.environment.name on every service. Only service.name falls back to spring.application.name (with neither set, it is unknown_service:java); set service.version and deployment.environment.name explicitly.
  • Sampling. Use a parent-based sampler so a service honours the decision made upstream: OTEL_TRACES_SAMPLER=parentbased_traceidratio with OTEL_TRACES_SAMPLER_ARG=0.1, or management.tracing.sampling.probability=0.1. A ratio drops errors as readily as successes; to keep every error, sample in a Collector. The sampling guide covers both.
  • Batching. Spans are exported in batches of up to 512 every 5 seconds, from a queue of 2,048. A full queue drops spans silently. Raise OTEL_BSP_MAX_QUEUE_SIZE (management.opentelemetry.tracing.export.max-queue-size in Spring Boot 4) first.
  • Shutdown. The last batch is flushed on SIGTERM: Spring closes the SDK with the application context and the agent uses a JVM shutdown hook. A SIGKILL loses up to 5 seconds of spans.
  • Health checks. Probes to /actuator/health produce a trace every few seconds per instance. With Spring Boot's own tracing, the ObservationPredicate bean below stops them in the app. The agent has no property for excluding a path, so drop probes in the Collector with a filter on url.path. A rule-based sampler in a declarative config file (OTEL_CONFIG_FILE) also works, but its format is changing as of 2.34.
  • Agent overhead. The agent adds to startup time and memory. Turn off instrumentations you do not want with OTEL_INSTRUMENTATION_[NAME]_ENABLED=false.

TracingFilters.java

import io.micrometer.observation.ObservationPredicate;
import org.springframework.http.server.observation.ServerRequestObservationContext;

@Configuration
class TracingFilters {
    // Returning false skips the observation: no span and no timer for it.
    @Bean
    ObservationPredicate skipActuator() {
        return (name, context) -> !(context instanceof ServerRequestObservationContext server
                && server.getCarrier().getRequestURI().startsWith("/actuator"));
    }
}

With this bean, /actuator/health still answered 200 in the test app and produced no span.

GraalVM native image

The Java agent does not work in a native image: it rewrites bytecode as classes load, and a native executable loads no classes at run time. Both starters work because their instrumentation is ordinary Spring configuration compiled into the image.

Test the image itself. Anything that relies on reflection or a proxy, including @WithSpan and @Observed, depends on hints generated at build time.

Common problems and fixes

The five problems below account for most "no traces" and "wrong traces" reports, each with the fix that worked in the test app.

Duplicate spans for every request

You are running two instrumentations, usually the Java agent on an app that also has Micrometer Tracing. With the agent and spring-boot-starter-opentelemetry together, each request produced one server span from the agent's Tomcat instrumentation and a second from Spring's observation, exported by two separate SDKs.

Remove one. If the agent stays, drop spring-boot-starter-opentelemetry or micrometer-tracing-bridge-otel, or set management.tracing.export.enabled=false. The agent with the OpenTelemetry starter did not duplicate in the same test, because the agent's SDK took over, but the starter is dead weight there.

Only some requests are traced, or none

  • About one request in ten shows up. That is Spring Boot's default management.tracing.sampling.probability=0.1. Set it to 1.0 while you test.
  • Nothing arrives and nothing is logged. With Spring Boot's own tracing and no endpoint, no exporter is created and no error is logged.
  • Nothing arrives and the app logs export errors. See 4317 vs 4318.
  • Tests export nothing. Spring Boot turns trace export off in @SpringBootTest. On 4.2 set spring.test.tracing.export=true; on 3.x add @AutoConfigureObservability.
  • Outgoing calls start new traces. The client was not built from the injected builder, so no traceparent header was sent.

No trace ID or spans in @Async methods

Trace context lives in a thread-local, and @Async runs on a pool thread. The agent carries the context across executors by itself. With the starters, the async log line had empty IDs until the executor was told to copy the context.

On Spring Boot 4.1 or later with Micrometer Tracing, one property does it:

application.yml

spring:
  task:
    execution:
      propagate-context: true

On earlier versions, register a ContextPropagatingTaskDecorator bean instead. With the OpenTelemetry starter, wrap tasks in the OpenTelemetry context:

AsyncConfig.java

import io.opentelemetry.context.Context;
import org.springframework.core.task.TaskDecorator;

@Configuration
class AsyncConfig {
    // Captures the caller's context and restores it on the pool thread.
    // Spring Boot applies a TaskDecorator bean to its default executor.
    @Bean
    TaskDecorator otelTaskDecorator() {
        return runnable -> Context.current().wrap(runnable);
    }
}

For your own ExecutorService or CompletableFuture.supplyAsync, wrap the executor with Context.taskWrapping(executor).

@WithSpan or @Observed does nothing

With the OpenTelemetry starter and no AOP on the classpath, @WithSpan is ignored without a warning. The attribute set through Span.current() then lands on the server span. Adding spring-boot-starter-aspectj (spring-boot-starter-aop on Spring Boot 3) fixed it. @Observed needs the same starter plus management.observations.annotations.enabled=true.

If it still does nothing, the call bypasses the proxy: a call on this, a private method, or an object created with new.

4317 vs 4318 and export errors

Port 4317 is OTLP over gRPC and 4318 is OTLP over HTTP. All three options default to HTTP, so use 4318 unless you set the protocol to grpc. A mismatch never says "wrong port". Here is gRPC sent to an HTTP port, then a port where nothing listens:

ERROR io.opentelemetry.exporter.otlp.internal.GrpcExporter - Failed to export 2 spans. The request could not be executed.
java.io.IOException: FRAME_SIZE_ERROR: 3940676

ERROR io.opentelemetry.exporter.otlp.internal.HttpExporter - Failed to export 2 spans. The request could not be executed.
java.net.ConnectException: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4318
  • Check that OTEL_EXPORTER_OTLP_PROTOCOL and the port agree.
  • In Docker or Kubernetes, localhost is the app's own container. Use the Collector's service name.
  • A 404 usually means /v1/traces is missing from a per-signal URL or doubled on a base URL.

The OTLP guide lists each export error with its cause.

Send it to Maple

Maple accepts OTLP directly, so no Collector is required. These variables work as written with the agent, the OpenTelemetry starter and Spring Boot 4.1 or later; on older Spring Boot versions, put the same endpoint and header in the management.otlp.* properties.

export OTEL_SERVICE_NAME="orders"
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.maple.dev"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_INGEST_KEY"
A trace in Maple shown as a timeline waterfall: a POST /api/checkout request across 6 services and 15 spans, with one span marked as an error.
A checkout trace in Maple. A Spring Boot request shows up the same way, one row per span.

The Java instrumentation doc covers the rest of the setup.

Sources and further reading

FAQ

よくある質問

Does Spring Boot support OpenTelemetry?
Yes. Spring Boot 4 ships spring-boot-starter-opentelemetry, which exports traces, metrics and logs over OTLP using Micrometer and the OpenTelemetry SDK. Spring Boot 3 does the same with spring-boot-starter-actuator, micrometer-tracing-bridge-otel and opentelemetry-exporter-otlp. You can also use the OpenTelemetry Java agent or the OpenTelemetry Spring Boot starter instead.
Should I use the OpenTelemetry Java agent or the Spring Boot starter?
Use the agent when you can add a JVM flag and want the widest library coverage with no code changes. Use a starter when you cannot attach an agent, build a GraalVM native image, already run another agent, or want the configuration in application.yml. Do not combine the agent with Spring Boot's Micrometer tracing, because each request is then traced twice.
What is the difference between Micrometer Tracing and OpenTelemetry?
Micrometer Tracing is Spring's facade over a tracer. With the OpenTelemetry bridge it creates spans in the OpenTelemetry SDK and exports them over OTLP, so the data on the wire is OpenTelemetry either way. The difference is the instrumentation: Spring's own Observation API names spans and attributes its own way unless you select OpenTelemetry conventions, and it covers Spring libraries only.
Is Spring Cloud Sleuth replaced by OpenTelemetry?
Sleuth is replaced by Micrometer Tracing, not by OpenTelemetry directly. Spring Cloud Sleuth 3.1 was its last minor release and it does not support Spring Boot 3 or later. Micrometer Tracing took over its core, and with the OpenTelemetry bridge it creates spans in the OpenTelemetry SDK and exports them over OTLP.
How do I add trace_id to Spring Boot logs?
Spring Boot 3.2 and later print the trace and span ID in every log line when Micrometer Tracing is on the classpath, using the MDC keys traceId and spanId. The OpenTelemetry agent and starter put trace_id and span_id in the MDC instead, so set logging.pattern.correlation to a pattern that reads those keys.
Why does Spring Boot only trace some requests?
Spring Boot's own tracing samples 10% of requests by default (management.tracing.sampling.probability=0.1). Set it to 1.0 to trace everything. The OpenTelemetry Java agent and the OpenTelemetry starter sample every request by default.
Does the OpenTelemetry Java agent work with GraalVM native image?
No. The agent rewrites bytecode when classes load, and a native image has no class loading at run time. Use the OpenTelemetry Spring Boot starter or Spring Boot's own tracing, which are built into the image at compile time.

今日、最初のトレースを。

SDKを追加し、OTLPエクスポーターをMapleに向ければトレースが届きます。

maple.dev:OpenTelemetryの上のオブザーバビリティ