Versions tested. Spring Boot 4.2.0 (GA 19 November 2026), which manages Micrometer 1.18.0, Micrometer Tracing 1.8.0 and OpenTelemetry SDK 1.68.0; OpenTelemetry Java agent 2.34.0 (on Maven Central since 18 November 2026); JDK Temurin 25.0.5.1 (the current LTS); Maven 3.9.11. One scenario also uses the third-partyThis post builds on two earlier ones: Micrometer to OpenTelemetry: The Spring Boot 4 Observability Guide explains the Micrometer side in depth, and Spring Boot 4.2 OpenTelemetry: Semantic Conventions, Shared OTLP Settings and MDC Keys covers the 4.2 settings (that one was tested on RC1; this one ran on GA). Here the question is different: not how to configure one approach, but how the two compare when the application is identical.datasource-micrometer-spring-boot2.3.1. Versions were read frommaven-metadata.xmland the Boot BOM, not from blog posts.
Two ways to get the same trace out of a JVM
A span is one timed operation: “handle GET /orders/1”, “run this SQL”, “call the inventory service”. A trace is the tree of spans one request caused. A metric is a number aggregated over many requests, such as a latency histogram. Something has to notice that an operation started and ended, and record it. That something is called instrumentation, and the two approaches differ in who writes it. With the agent, the instrumentation lives outside your application. You start the JVM with-javaagent:opentelemetry-javaagent.jar, and as classes load the agent rewrites the bytecode of libraries it recognises (Tomcat, JDBC drivers, HTTP clients, Kafka clients and many more) so they emit spans. Your jar has no tracing dependency and your code does not know. With Micrometer Tracing, the instrumentation lives inside the frameworks you already use: Spring MVC and Spring’s RestClient publish observations (“an HTTP request started”, “it ended”) through Micrometer’s Observation API, and a tracing handler on the classpath turns each observation into a span and a timer. The OpenTelemetry SDK that exports them is an ordinary library inside your application.
Going deeper
- OpenTelemetry: Java zero-code instrumentation (the agent)
- Micrometer: Observation API
- Spring Boot reference: Tracing
- The Micrometer side in depth: Micrometer to OpenTelemetry: The Spring Boot 4 Observability Guide
One application, built twice
The test subject is a small “orders” service.GET /orders/{id} reads one row with JdbcClient, calls an inventory endpoint (served by the same JVM, so one request produces both an outgoing client span and a second server span) and runs a business method. GET /orders/{id}/audited does the same and then hands a database write to another thread. The controller is in OrdersController.java:
/** One SQL query, one outgoing HTTP call, one business computation. */
@GetMapping("/orders/{id}")
public Map<String, Object> order(@PathVariable long id) {
var order = orders.find(id);
int stock = inventory.stock(order.sku());
return Map.of("id", order.id(), "sku", order.sku(), "totalCents", pricing.price(order), "stock", stock);
}
/** Same, plus a hand-off to another thread that also writes to the database. */
@GetMapping("/orders/{id}/audited")
public Map<String, Object> audited(@PathVariable long id) throws Exception {
var body = order(id);
audit.auditAndWait(id);
return body;
}
The outgoing call goes through Spring’s RestClient. One Spring Boot 4 detail cost a failed startup while writing this: spring-boot-starter-webmvc no longer brings the RestClient.Builder bean, you need spring-boot-starter-restclient (the failure is quoted in the accordion below, from 10-restclient-starter-missing.txt).
The application is built into two jars from one source tree. The “plain” jar has no tracing dependency at all. The “micrometer” jar adds exactly one dependency through a Maven profile in app/pom.xml:
<profile>
<id>micrometer</id>
<properties>
<variant>micrometer</variant>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-opentelemetry</artifactId>
</dependency>
</dependencies>
</profile>
The agent is run against the plain jar, Micrometer against the other. The JVM flags for each are in scripts/lib.sh and the scenarios in scripts/run-all.sh. Both export OTLP over HTTP to a receiver in the repo (OtlpSink.java) that decodes the protobuf and prints span trees, so there is no backend to install and nothing to take on trust:
MICROMETER_PROPS=(
-Dmanagement.opentelemetry.otlp.endpoint=http://localhost:$SINK_PORT
-Dmanagement.tracing.sampling.probability=1.0
-Dmanagement.otlp.metrics.export.step=2s
)
AGENT_PROPS=(
-javaagent:"$DIST/agent.jar"
-Dotel.service.name=orders
-Dotel.exporter.otlp.endpoint=http://localhost:$SINK_PORT
-Dotel.exporter.otlp.protocol=http/protobuf
-Dotel.logs.exporter=none
-Dotel.metric.export.interval=2000
-Dotel.bsp.schedule.delay=200
)
These export intervals are not defaults. The metric interval (2 s) and the agent’s span batch delay (200 ms) are shortened so a transcript finishes in seconds. Leave the real defaults alone in production.
Why a custom receiver, and how the numbers were collected
A real backend (Jaeger, Tempo, Grafana LGTM) would show the same spans in a UI, but a UI cannot be quoted line by line. OtlpSink is a 180-line JDK HttpServer that decodes OTLP/HTTP protobuf with the opentelemetry-proto classes and serves plain-text views: /spans (the tree), /span-attrs (attribute keys per span name), /metrics (names, types, units per instrumentation scope), /resource and /span-values (the values of one attribute). Every transcript below is one of those views fetched after a fixed set of requests: one warm-up request, a pause so the exporters drain, a reset, then exactly GET /orders/1 and GET /orders/1/audited.
Ports 18480 (app) and 14418 (sink) are used so the scripts do not collide with anything on 8080 or 4318. The full code: sink/src/main/java/com/ankurm/otelcmp/sink/OtlpSink.java, scripts/run-all.sh.
Boot 4 trap: no RestClient.Builder without spring-boot-starter-restclient
Built from a throwaway copy of the app with only that one starter removed (scripts/restclient-missing.sh), started on Spring Boot 4.2.0. Output from output/10-restclient-starter-missing.txt:
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.ankurm.otelcmp.InventoryClient required a bean of type 'org.springframework.web.client.RestClient$Builder' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.web.client.RestClient$Builder' in your configuration.If a RestClient.Builder injection fails at startup on Boot 4, check for this starter first.
Going deeper
- The source of every class: app/src/main/java/com/ankurm/otelcmp
- Run everything yourself: README.md
What the agent sees without being asked
First the unmodified plain jar with the agent attached. Two requests were sent after warm-up. Each line below is one span: its name, its kind, and the instrumentation scope that produced it. Indentation is the parent–child relationship. From output/01-agent-spans.txt:trace 1 (5 spans)
GET /orders/{id} [SERVER, scope=io.opentelemetry.tomcat-10.0]
SELECT orders.orders [CLIENT, scope=io.opentelemetry.jdbc]
GET [CLIENT, scope=io.opentelemetry.java-http-client]
GET /inventory/{sku} [SERVER, scope=io.opentelemetry.tomcat-10.0]
PricingService.price [INTERNAL, scope=io.opentelemetry.methods]
trace 2 (7 spans)
GET /orders/{id}/audited [SERVER, scope=io.opentelemetry.tomcat-10.0]
SELECT orders.orders [CLIENT, scope=io.opentelemetry.jdbc]
GET [CLIENT, scope=io.opentelemetry.java-http-client]
GET /inventory/{sku} [SERVER, scope=io.opentelemetry.tomcat-10.0]
PricingService.price [INTERNAL, scope=io.opentelemetry.methods]
AuditService.write [INTERNAL, scope=io.opentelemetry.methods]
INSERT orders.audit_log [CLIENT, scope=io.opentelemetry.jdbc]
Read the scopes: io.opentelemetry.tomcat-10.0 made the server spans, io.opentelemetry.jdbc made the database spans, io.opentelemetry.java-http-client made the outgoing call. I did not write or configure any of that. The tree also contains something Micrometer will not give by default, which is the SQL: SELECT orders.orders and INSERT orders.audit_log, with the statement itself in the db.statement attribute.
Two spans look different. PricingService.price and AuditService.write have scope io.opentelemetry.methods. The agent does not know those are interesting, so I told it with a flag that names the methods, which is the zero-code way to add a custom span (see the custom-spans section below). Without that flag they would not exist.
The outgoing span is called just “GET”. The agent’s HTTP-client span name is the bare method; the URL goes inurl.full. The server-side span carries the route template (GET /inventory/{sku}). That is a deliberate low-cardinality naming rule, but it surprises people searching a backend for the client call by name.
Going deeper
- Full attribute keys of every agent span: accordion in the section on attribute names, and output/01-agent-spans.txt
- The list of libraries the agent instruments out of the box
What Micrometer sees, and what it does not
Now the same two requests against the micrometer jar, which differs only by the one starter. From output/02-micrometer-spans.txt:trace 1 (4 spans)
http get /orders/{id} [SERVER, scope=org.springframework.boot]
http get [CLIENT, scope=org.springframework.boot]
http get /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
trace 2 (4 spans)
http get /orders/{id}/audited [SERVER, scope=org.springframework.boot]
http get [CLIENT, scope=org.springframework.boot]
http get /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
trace 3 (1 spans)
audit.write [INTERNAL, scope=org.springframework.boot]
Three differences are visible at a glance, and each is a real design difference rather than a bug.
There is no database span. Spring Boot published no JDBC observations in this run, so nothing became a span. The agent finds JDBC because it instruments the driver; Micrometer finds only what somebody publishes. There is a third-party library for it, and the section on closing the JDBC gap shows what it produces.
The span names are different. Micrometer names an HTTP server span http get /orders/{id}, lower case with the route template, and the client span http get. The agent says GET /orders/{id} and GET. Same requests, same templates, different strings, which matters the first time someone writes a dashboard query or an alert against a span name.
The span from the other thread is not in the tree. Look at the last line: the audit.write span is in a third trace of its own. Section “The trap: work on another thread” explains why. The agent’s tree above shows it where it belongs.
The scope isorg.springframework.bootfor everything. Micrometer tells the exporter one instrumentation scope for all spans, so you cannot filter “only the HTTP client spans” by scope the way you can with the agent (io.opentelemetry.java-http-client). You filter by span name or attribute instead.
Going deeper
- output/02-micrometer-spans.txt for the attribute keys of every span
- InventoryClient.java: the auto-configured
RestClient.Builderis the instrumented one;RestClient.create()would bypass the observation
Same request, different attribute names
Span names are the visible difference. The attributes inside the spans differ more, and they are what queries and alerts actually filter on. Here are the attribute keys on the server span forGET /orders/{id}, first from the agent and then from Micrometer (keys only, from 01-agent-spans.txt and 02-micrometer-spans.txt):
GET /orders/{id} [SERVER]
client.address, http.request.method, http.response.status_code, http.route, network.peer.address, network.peer.port, network.protocol.version, server.address, server.port, thread.id, thread.name, url.path, url.scheme, user_agent.original
http get /orders/{id} [SERVER]
exception, http.url, method, outcome, status, uri
The agent emits the current OpenTelemetry HTTP semantic conventions (http.request.method, http.response.status_code, http.route, url.path). Micrometer by default emits its own long-standing key names (method, status, uri, outcome) because those are the names Micrometer’s metrics always used and the span reuses the observation’s tags. A backend that understands HTTP semantic conventions (a service map, a RED dashboard, a built-in alert template) will recognise the agent’s spans and may not recognise Micrometer’s.
Spring Boot 4.2 added a switch for this, management.observations.conventions. I re-ran the Micrometer build with it set to opentelemetry (output/03-micrometer-otel-conventions.txt):
trace 1 (4 spans)
GET /orders/{id} [SERVER, scope=org.springframework.boot]
http get [CLIENT, scope=org.springframework.boot]
GET /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
trace 2 (4 spans)
GET /orders/{id}/audited [SERVER, scope=org.springframework.boot]
http get [CLIENT, scope=org.springframework.boot]
GET /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
trace 3 (1 spans)
audit.write [INTERNAL, scope=org.springframework.boot]
GET /orders/{id} [SERVER]
error.type, http.request.method, http.request.method_original, http.response.status_code, http.route, outcome, url.path, url.scheme
Two things to notice in this run on 4.2.0 GA. The server spans changed: the name is now GET /orders/{id} and the keys are the semantic-convention ones, with a few leftovers (outcome, and http.request.method_original). But the client span http get still has the old keys in this run (client.name, http.url, method, status, uri). I did not find out why, and I did not test other client types, so treat the switch as covering the server side only until you have checked your own client spans.
The HTTP metrics from that same run, from output/03-micrometer-otel-conventions.txt:
-- HTTP metrics exported
scope (no scope name) (77 metrics)
http.client.requests histogram unit=milliseconds
http.client.requests.max gauge unit=milliseconds
http.server.request.duration histogram unit=milliseconds
http.server.request.duration.max gauge unit=milliseconds
Same metric name, different unit. With the convention switch on, Micrometer exports an HTTP server histogram namedhttp.server.request.duration, which is the OpenTelemetry name. Its unit in this run ismilliseconds. The agent’s metric of the same name has units(seconds), which is what the semantic convention specifies. Both lines are in the transcripts (03 and 04). If you mix the two in one dashboard, the same name will be off by a factor of 1,000.
Every attribute key on every span, both approaches (verbatim)
From output/01-agent-spans.txt (agent):
AuditService.write [INTERNAL]
code.function, code.namespace, thread.id, thread.name
GET /inventory/{sku} [SERVER]
client.address, http.request.method, http.response.status_code, http.route, network.peer.address, network.peer.port, network.protocol.version, server.address, server.port, thread.id, thread.name, url.path, url.scheme, user_agent.original
GET /orders/{id} [SERVER]
client.address, http.request.method, http.response.status_code, http.route, network.peer.address, network.peer.port, network.protocol.version, server.address, server.port, thread.id, thread.name, url.path, url.scheme, user_agent.original
GET /orders/{id}/audited [SERVER]
client.address, http.request.method, http.response.status_code, http.route, network.peer.address, network.peer.port, network.protocol.version, server.address, server.port, thread.id, thread.name, url.path, url.scheme, user_agent.original
GET [CLIENT]
http.request.method, http.response.status_code, network.protocol.version, server.address, server.port, thread.id, thread.name, url.full
INSERT orders.audit_log [CLIENT]
db.connection_string, db.name, db.operation, db.sql.table, db.statement, db.system, db.user, thread.id, thread.name
PricingService.price [INTERNAL]
code.function, code.namespace, thread.id, thread.name
SELECT orders.orders [CLIENT]
db.connection_string, db.name, db.operation, db.sql.table, db.statement, db.system, db.user, thread.id, thread.nameFrom output/02-micrometer-spans.txt (Micrometer, default conventions):
audit.write [INTERNAL]
http get /inventory/{sku} [SERVER]
exception, http.url, method, outcome, status, uri
http get /orders/{id} [SERVER]
exception, http.url, method, outcome, status, uri
http get /orders/{id}/audited [SERVER]
exception, http.url, method, outcome, status, uri
http get [CLIENT]
client.name, exception, http.url, method, outcome, status, uri
pricing.compute [INTERNAL]
pricing.sku
Going deeper
- The 4.2 convention switch and the other 4.2 OpenTelemetry settings: Spring Boot 4.2 OpenTelemetry: Semantic Conventions, Shared OTLP Settings and MDC Keys
- output/03-micrometer-otel-conventions.txt
Metrics: one is a firehose, one is a menu
Traces were half the question. Both approaches also exported metrics over OTLP, and they come from very different places. Grouped by instrumentation scope (the line shows how many metrics each scope sent), from output/04-metrics.txt:######## agent
scope io.opentelemetry.exporters.otlp-http (2 metrics)
scope io.opentelemetry.hikaricp-3.0 (7 metrics)
scope io.opentelemetry.java-http-client (1 metrics)
scope io.opentelemetry.runtime-telemetry-java8 (12 metrics)
scope io.opentelemetry.sdk.trace (2 metrics)
scope io.opentelemetry.tomcat-10.0 (1 metrics)
######## micrometer (default conventions)
scope (no scope name) (77 metrics)
The agent exported 25 metrics across six scopes: JVM runtime metrics, the Hikari connection pool, the HTTP client and server duration histograms, and the SDK’s own bookkeeping. Micrometer exported 77 under no scope name at all: everything Spring Boot Actuator’s meter registry knows (JVM, process, disk, Tomcat sessions, Logback event counts, executors, Hikari) plus the timers from observations. The counts are not a quality score. They reflect that Micrometer has been collecting that menu of metrics for years, and the agent’s runtime-metrics set is smaller and follows OpenTelemetry names (jvm.memory.used, jvm.cpu.recent_utilization).
What is worth noticing is how Micrometer gets a custom metric. The pricing.compute and audit.write observations in my code produced both a span and a timer (pricing.compute histogram and pricing.compute.max gauge appear in the full list). One piece of code, two signals. The agent gives a span for a method you name, and the agent’s metrics do not include a timer for it. If you want a per-method latency histogram from the agent you need to derive it from spans in the backend.
Do not point two dashboards at both and expect them to line up. Names, units and label sets differ for the same thing (HTTP server latency ishttp.server.requestsin milliseconds from Micrometer by default,http.server.request.durationin seconds from the agent). Choose one source per service and build the dashboards for that.
Every metric each approach exported (verbatim, 114 lines)
From output/04-metrics.txt:
# 04 Metrics received over OTLP, grouped by the instrumentation scope that produced them
######## agent
scope io.opentelemetry.exporters.otlp-http (2 metrics)
otlp.exporter.exported sum
otlp.exporter.seen sum
scope io.opentelemetry.hikaricp-3.0 (7 metrics)
db.client.connections.create_time histogram unit=ms
db.client.connections.idle.min sum unit={connections}
db.client.connections.max sum unit={connections}
db.client.connections.pending_requests sum unit={requests}
db.client.connections.usage sum unit={connections}
db.client.connections.use_time histogram unit=ms
db.client.connections.wait_time histogram unit=ms
scope io.opentelemetry.java-http-client (1 metrics)
http.client.request.duration histogram unit=s
scope io.opentelemetry.runtime-telemetry-java8 (12 metrics)
jvm.class.count sum unit={class}
jvm.class.loaded sum unit={class}
jvm.class.unloaded sum unit={class}
jvm.cpu.count sum unit={cpu}
jvm.cpu.recent_utilization gauge unit=1
jvm.cpu.time sum unit=s
jvm.gc.duration histogram unit=s
jvm.memory.committed sum unit=By
jvm.memory.limit sum unit=By
jvm.memory.used sum unit=By
jvm.memory.used_after_last_gc sum unit=By
jvm.thread.count sum unit={thread}
scope io.opentelemetry.sdk.trace (2 metrics)
processedSpans sum unit=1
queueSize gauge unit=1
scope io.opentelemetry.tomcat-10.0 (1 metrics)
http.server.request.duration histogram unit=s
######## micrometer (default conventions)
scope (no scope name) (77 metrics)
application.ready.time gauge unit=milliseconds
application.started.time gauge unit=milliseconds
audit.write histogram unit=milliseconds
audit.write.max gauge unit=milliseconds
disk.free gauge unit=bytes
disk.total gauge unit=bytes
executor.active gauge unit=threads
executor.completed sum unit=tasks
executor.pool.core gauge unit=threads
executor.pool.max gauge unit=threads
executor.pool.size gauge unit=threads
executor.queue.remaining gauge unit=tasks
executor.queued gauge unit=tasks
hikaricp.connections gauge
hikaricp.connections.acquire histogram unit=milliseconds
hikaricp.connections.acquire.max gauge unit=milliseconds
hikaricp.connections.active gauge
hikaricp.connections.creation histogram unit=milliseconds
hikaricp.connections.creation.max gauge unit=milliseconds
hikaricp.connections.idle gauge
hikaricp.connections.max gauge
hikaricp.connections.min gauge
hikaricp.connections.pending gauge
hikaricp.connections.timeout sum
hikaricp.connections.usage histogram unit=milliseconds
hikaricp.connections.usage.max gauge unit=milliseconds
http.client.requests histogram unit=milliseconds
http.client.requests.max gauge unit=milliseconds
http.server.requests histogram unit=milliseconds
http.server.requests.max gauge unit=milliseconds
jdbc.connections.active gauge
jdbc.connections.idle gauge
jdbc.connections.max gauge
jdbc.connections.min gauge
jvm.buffer.count gauge unit=buffers
jvm.buffer.memory.used gauge unit=bytes
jvm.buffer.total.capacity gauge unit=bytes
jvm.classes.loaded gauge unit=classes
jvm.classes.loaded.count sum unit=classes
jvm.classes.unloaded sum unit=classes
jvm.compilation.time sum unit=ms
jvm.gc.live.data.size gauge unit=bytes
jvm.gc.max.data.size gauge unit=bytes
jvm.gc.memory.allocated sum unit=bytes
jvm.gc.memory.promoted sum unit=bytes
jvm.gc.overhead gauge
jvm.gc.pause histogram unit=milliseconds
jvm.gc.pause.max gauge unit=milliseconds
jvm.info gauge
jvm.memory.committed gauge unit=bytes
jvm.memory.max gauge unit=bytes
jvm.memory.usage.after.gc gauge
jvm.memory.used gauge unit=bytes
jvm.memory.used_after_last_gc gauge unit=bytes
jvm.threads.daemon gauge unit=threads
jvm.threads.live gauge unit=threads
jvm.threads.peak gauge unit=threads
jvm.threads.started sum unit=threads
jvm.threads.states gauge unit=threads
logback.events sum unit=events
pricing.compute histogram unit=milliseconds
pricing.compute.max gauge unit=milliseconds
process.cpu.time sum unit=ns
process.cpu.usage gauge
process.files.max gauge unit=files
process.files.open gauge unit=files
process.start.time gauge unit=milliseconds
process.uptime gauge unit=milliseconds
system.cpu.count gauge
system.cpu.usage gauge
system.load.average.1m gauge
tomcat.sessions.active.current gauge unit=sessions
tomcat.sessions.active.max gauge unit=sessions
tomcat.sessions.alive.max gauge unit=milliseconds
tomcat.sessions.created sum unit=sessions
tomcat.sessions.expired sum unit=sessions
tomcat.sessions.rejected sum unit=sessions
Going deeper
Who is this service? The resource attributes
Every OTLP export carries a resource: attributes describing the process that produced the data. A backend uses them to group services and tell instances apart. They are small and easy to forget, and they differ. From output/09-resource.txt (machine-specific entries such as host name and PID are left out of the file):# Machine-specific attributes are left out: host.name, os.*, process.pid, process.executable.path,
# process.command_args and service.instance.id.
== agent
host.arch = amd64
process.runtime.description = Eclipse Adoptium OpenJDK 64-Bit Server VM 25.0.5.1+2-LTS
process.runtime.name = OpenJDK Runtime Environment
process.runtime.version = 25.0.5.1+2-LTS
service.name = orders
service.version = 1.0.0
telemetry.distro.name = opentelemetry-java-instrumentation
telemetry.distro.version = 2.34.0
telemetry.sdk.language = java
telemetry.sdk.name = opentelemetry
telemetry.sdk.version = 1.68.0
== micrometer
service.name = orders
telemetry.sdk.language = java
telemetry.sdk.name = opentelemetry
telemetry.sdk.version = 1.68.0
The agent fills in the JVM description, the CPU architecture, the service version (1.0.0, which matches this project’s version) and who produced the telemetry. The Micrometer build sent service.name and the SDK identity only. That is fixable (Spring Boot has a management.opentelemetry.resource-attributes property, listed in the spring-boot-opentelemetry 4.2.0 configuration metadata), but it is another thing the agent does without being asked and the in-code route leaves to you.
Going deeper
The trap: work on another thread
Tracing needs to know which request a piece of work belongs to. Inside one thread that is easy: the current span lives in a thread-local. When you hand work to a different thread, the new thread has an empty thread-local, so unless something copies the context across, the work starts a brand-new trace. The span exists and is exported, but it is detached from the request that caused it. In a backend you see a request that is missing its database write, and a stray one-span trace with no parent./audited endpoint three times. In the first run the agent traced a plain java.util.concurrent pool and kept the child span under the request. In the second, Micrometer with the same plain pool lost it. In the third, the pool was a Spring ThreadPoolTaskExecutor with ContextPropagatingTaskDecorator, and the span came back. The real transcript:
== agent, audit.executor=raw
trace 1 (7 spans)
GET /orders/{id}/audited [SERVER, scope=io.opentelemetry.tomcat-10.0]
SELECT orders.orders [CLIENT, scope=io.opentelemetry.jdbc]
GET [CLIENT, scope=io.opentelemetry.java-http-client]
GET /inventory/{sku} [SERVER, scope=io.opentelemetry.tomcat-10.0]
PricingService.price [INTERNAL, scope=io.opentelemetry.methods]
AuditService.write [INTERNAL, scope=io.opentelemetry.methods]
INSERT orders.audit_log [CLIENT, scope=io.opentelemetry.jdbc]
== micrometer, audit.executor=raw
trace 1 (4 spans)
http get /orders/{id}/audited [SERVER, scope=org.springframework.boot]
http get [CLIENT, scope=org.springframework.boot]
http get /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
trace 2 (1 spans)
audit.write [INTERNAL, scope=org.springframework.boot]
== micrometer, audit.executor=spring
trace 1 (5 spans)
http get /orders/{id}/audited [SERVER, scope=org.springframework.boot]
http get [CLIENT, scope=org.springframework.boot]
http get /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
audit.write [INTERNAL, scope=org.springframework.boot]
The code that switches between the second and third runs is the part of AuditService.java that builds the executor:
if (mode.equals("spring")) {
ThreadPoolTaskExecutor t = new ThreadPoolTaskExecutor();
t.setCorePoolSize(2);
t.setThreadNamePrefix("audit-");
t.setTaskDecorator(new ContextPropagatingTaskDecorator());
t.initialize();
this.executor = t;
} else {
ExecutorService e = Executors.newFixedThreadPool(2, r -> {
Thread th = new Thread(r, "audit-raw");
th.setDaemon(true);
return th;
});
this.executor = e;
}
The agent kept the context across a plain java.util.concurrent pool with no help from the code (it ships instrumentation for executors; the transcript shows the effect, and I did not read that part of its source). With Micrometer, context propagation is something your application opts into per executor. Spring Boot’s auto-configuration references the same ContextPropagatingTaskDecorator for its own executors (I found the class name in spring-boot-autoconfigure 4.2.0 and did not run that path), but a pool you create yourself with Executors, a library’s private pool, or a reactive scheduler is on you. This is the most common reason a Micrometer-instrumented service shows “broken” traces.
The fingerprint. A trace whose root span is not an HTTP request (here audit.write as a root with no parent), or a request trace that is oddly short, is almost always lost context at a thread hop. Count traces per request in a test like scripts/run-all.sh before you trust a tracing rollout.
Going deeper
Adding your own span: a method annotation or a line of config
The business method I wanted a span for is PricingService.java: public long price(OrderRepository.Order order) {
return Observation.createNotStarted("pricing.compute", registry)
.lowCardinalityKeyValue("pricing.sku", order.sku())
.observe(() -> order.quantity() * order.unitPriceCents());
}
That is the in-code way: you create an Observation, give it a name and a low-cardinality tag, and run the work inside it. With Micrometer Tracing present it becomes a span and a timer, as the earlier sections showed (pricing.compute with the key pricing.sku). It is plain Java, it can be unit-tested with a test registry, and it moves with the code when you refactor.
The agent way needs no code. The same class is in the plain jar, and the Observation inside it does nothing there, because there is no handler registered. The spans in the agent tree came from one JVM option, whose value is this list of methods:
From scripts/run-all.sh (the AGENT_METHODS variable):
AGENT_METHODS='com.ankurm.otelcmp.PricingService[price];com.ankurm.otelcmp.AuditService[write]'
The script passes that string as -Dotel.instrumentation.methods.include="$AGENT_METHODS": class name, method in brackets, several entries separated by semicolons.
That option is documented on the agent’s annotations page, alongside the @WithSpan annotation, which is the in-code alternative if you do want the source to declare it. The trade is the usual one. Configuration keeps your code clean and lets an operator add spans without a release, but it names methods as strings, so a rename silently removes the span, and nothing fails to compile. The Observation is checked by the compiler and travels with the code, but it needs the dependency and a developer.
The observation under the agent is wasted, not harmful. In the agent run the Observation calls in this code are no-ops, and in the Micrometer run the agent option is not present, so the two mechanisms never overlap here. But if you run both (see the section after next) your custom code is traced by Micrometer while the agent traces the same method from the outside.
Going deeper
- app/src/main/java/com/ankurm/otelcmp/PricingService.java and app/src/main/java/com/ankurm/otelcmp/AuditService.java
- Agent: annotations and methods.include
Closing the JDBC gap on the Micrometer side
The earlier Micrometer tree had no database span. The Micrometer ecosystem has a third-party answer,net.ttddyy.observation:datasource-micrometer-spring-boot, which wraps the DataSource and publishes observations. I added version 2.3.1 behind a third Maven profile (-Pmicrometer,jdbc) and reran. From output/06-micrometer-jdbc.txt:
trace 1 (7 spans)
http get /orders/{id} [SERVER, scope=org.springframework.boot]
connection [CLIENT, scope=org.springframework.boot]
query [CLIENT, scope=org.springframework.boot]
result-set [CLIENT, scope=org.springframework.boot]
http get [CLIENT, scope=org.springframework.boot]
http get /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
trace 2 (7 spans)
http get /orders/{id}/audited [SERVER, scope=org.springframework.boot]
connection [CLIENT, scope=org.springframework.boot]
query [CLIENT, scope=org.springframework.boot]
result-set [CLIENT, scope=org.springframework.boot]
http get [CLIENT, scope=org.springframework.boot]
http get /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
trace 3 (3 spans)
audit.write [INTERNAL, scope=org.springframework.boot]
connection [CLIENT, scope=org.springframework.boot]
query [CLIENT, scope=org.springframework.boot]
It works on Spring Boot 4.2.0, with one line of dependency and no code. But look at what it produces: spans named connection, query and result-set, with attributes such as jdbc.query[0] and jdbc.row-count. The agent’s database spans are named SELECT orders.orders and carry db.statement, db.system and friends. There are three spans (connection, query, result-set) where the agent has one, the names say nothing about the table, and the attribute keys are the library’s own rather than OpenTelemetry’s. Also note that the audit.write span that is a root in this run now has its own database children, because the lost-context problem from the previous section is independent of what instruments the call.
Attribute keys of the JDBC spans (verbatim)
From output/06-micrometer-jdbc.txt:
connection [CLIENT]
jdbc.datasource.driver, jdbc.datasource.name, jdbc.datasource.pool
--
query [CLIENT]
jdbc.datasource.driver, jdbc.datasource.name, jdbc.datasource.pool, jdbc.query[0], jdbc.row-affected, peer.service
result-set [CLIENT]
jdbc.datasource.driver, jdbc.datasource.name, jdbc.datasource.pool, jdbc.row-count, peer.service
Going deeper
- output/06-micrometer-jdbc.txt
- The profile in app/pom.xml
Running both at once
Someone will ask, so I ran it: the micrometer jar and the agent in the same JVM, both exporting to the same receiver (output/07-both-at-once.txt). The result is not “the best of both”:trace 1 (8 spans)
GET /orders/{id} [SERVER, scope=io.opentelemetry.tomcat-10.0]
http get /orders/{id} [SERVER, scope=org.springframework.boot]
SELECT orders.orders [CLIENT, scope=io.opentelemetry.jdbc]
http get [CLIENT, scope=org.springframework.boot]
GET [CLIENT, scope=io.opentelemetry.java-http-client]
GET /inventory/{sku} [SERVER, scope=io.opentelemetry.tomcat-10.0]
http get /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
trace 2 (10 spans)
GET /orders/{id}/audited [SERVER, scope=io.opentelemetry.tomcat-10.0]
http get /orders/{id}/audited [SERVER, scope=org.springframework.boot]
SELECT orders.orders [CLIENT, scope=io.opentelemetry.jdbc]
http get [CLIENT, scope=org.springframework.boot]
GET [CLIENT, scope=io.opentelemetry.java-http-client]
GET /inventory/{sku} [SERVER, scope=io.opentelemetry.tomcat-10.0]
http get /inventory/{sku} [SERVER, scope=org.springframework.boot]
pricing.compute [INTERNAL, scope=org.springframework.boot]
audit.write [INTERNAL, scope=org.springframework.boot]
INSERT orders.audit_log [CLIENT, scope=io.opentelemetry.jdbc]
trace 3 (1 spans)
POST [CLIENT, scope=io.opentelemetry.java-http-client]
trace 4 (1 spans)
POST [CLIENT, scope=io.opentelemetry.java-http-client]
Every request is traced twice. The agent’s server span GET /orders/{id} sits above Micrometer’s http get /orders/{id}, the HTTP client call has an agent span and a Micrometer span side by side, and the inventory server span exists in both flavours. You pay for two instrumentations and get a trace with duplicated levels. It also produced two HTTP server latency metrics with different names and units. And at the bottom of the transcript (07-both-at-once.txt) is a small surprise:
-- url.full of the lone POST client spans
http://localhost:14418/v1/metrics
-- HTTP server metrics received (scope, name)
scope (no scope name) (79 metrics)
http.server.requests histogram unit=milliseconds
http.server.requests.max gauge unit=milliseconds
scope io.opentelemetry.tomcat-10.0 (1 metrics)
http.server.request.duration histogram unit=s
The agent traced Micrometer’s own metric exporter: a lone POST client span to /v1/metrics on the receiver, one per export. In a real deployment those would be spans about your telemetry pipeline, in their own one-span traces, adding noise and volume. Pick one approach per service. If you are migrating from one to the other, do it in a deployment, not by running both.
Going deeper
What each approach costs
Overhead is the first question anyone asks, so I measured it, with a loud caveat first: this ran on a 2-vCPU sandbox that was shared with other work, with the app, the receiver and the load generator all competing for the same two cores. Wall-clock throughput was too noisy to trust (an earlier run of the same script while the machine was busier, which I did not keep, showed the baseline using 15–27% more CPU per request than the committed run). So the table leads with CPU time, read from the app JVM’s own process counters, which is far less affected by what else is running. The load was 4 client threads, 5,000 warm-up requests then 3 rounds of 8,000 requests per endpoint./ping does nothing; /orders/1 does the SQL, the outgoing call and the business method. From output/08-overhead.txt (generated by scripts/overhead.sh):
| Configuration | CPU until ready (ms) | Spring “Started in” (s) | JVM “running for” (s) | CPU per request, /ping (µs) | CPU per request, /orders/1 (µs) | RSS (MiB) |
|---|---|---|---|---|---|---|
| baseline: plain jar, no instrumentation | 6,090 | 2.639 | 2.971 | 206 | 791 | 310 |
| agent, all spans sampled | 13,920 | 3.393 | 7.212 | 365 | 1253 | 422 |
| micrometer starter, all spans sampled | 8,760 | 3.765 | 4.238 | 368 | 937 | 467 |
| agent, 10% sampling | 13,900 | 3.557 | 6.947 | 345 | 1267 | 415 |
| micrometer starter, 10% sampling | 7,850 | 3.336 | 3.694 | 326 | 1076 | 334 |
| micrometer starter + JDBC observation, all spans sampled | 9,380 | 3.959 | 4.405 | 317 | 1190 | 462 |
/ping, 1267 against 1253 on /orders/1), and Micrometer moved only a little. I did not investigate why. A plausible reading is that with a head sampler the instrumentation still runs and creates non-recording spans, so only the export is saved, but I have not verified that. RSS after each run (310 MiB for the baseline, 422 for the agent, 467 for Micrometer, but 334 for Micrometer at 10% sampling) is mostly decided by how the JVM sized its heap during that run, and a single sample cannot separate that from instrumentation, so I do not draw a memory conclusion from this table.
Treat these as relative, single-run figures. One run per configuration on a shared 2-vCPU machine, a local receiver instead of a real network, an in-memory H2 database, and a trivial controller. Real services spend most of their time in the database and the network, which dilutes any per-request instrumentation cost, and your numbers will differ. Measure your own service under your own load before you decide.
The full overhead transcript, including throughput and latency per round
Verbatim from output/08-overhead.txt. The req/s and latency figures are the noisy ones; the first round of each endpoint tends to be the slowest, so look at the later rounds.
# 08 Overhead: same jar family, same endpoints, 4 client threads, 5000 warm-up + 8000 measured requests x 3 rounds
# JDK 25.0.5.1, 2 vCPU shared by app, OTLP sink and load driver. Indicative only.
== baseline: plain jar, no instrumentation
CPU consumed by the JVM from process start to ready (+4 s idle): 6090 ms
Started OrdersApplication in 2.639 seconds (process running for 2.971)
-- GET /ping
round 1: 2240 req/s p50 872 us p99 9240 us
round 2: 4647 req/s p50 467 us p99 6024 us
round 3: 7602 req/s p50 313 us p99 4336 us
app CPU per request: 206 us (utime+stime of the app JVM only, 24000 requests)
-- GET /orders/1
round 1: 1025 req/s p50 3117 us p99 12533 us
round 2: 1627 req/s p50 1824 us p99 9003 us
round 3: 2864 req/s p50 1220 us p99 5087 us
app CPU per request: 791 us (utime+stime of the app JVM only, 24000 requests)
-- RSS after the run: 310 MiB
== agent, all spans sampled
CPU consumed by the JVM from process start to ready (+4 s idle): 13920 ms
Started OrdersApplication in 3.393 seconds (process running for 7.212)
-- GET /ping
round 1: 1539 req/s p50 1589 us p99 11298 us
round 2: 2502 req/s p50 861 us p99 8897 us
round 3: 5087 req/s p50 393 us p99 5911 us
app CPU per request: 365 us (utime+stime of the app JVM only, 24000 requests)
-- GET /orders/1
round 1: 710 req/s p50 4562 us p99 18314 us
round 2: 953 req/s p50 3059 us p99 14901 us
round 3: 1217 req/s p50 2038 us p99 15006 us
app CPU per request: 1253 us (utime+stime of the app JVM only, 24000 requests)
-- RSS after the run: 422 MiB
== micrometer starter, all spans sampled
CPU consumed by the JVM from process start to ready (+4 s idle): 8760 ms
Started OrdersApplication in 3.765 seconds (process running for 4.238)
-- GET /ping
round 1: 1800 req/s p50 1300 us p99 10657 us
round 2: 2775 req/s p50 766 us p99 9238 us
round 3: 4193 req/s p50 426 us p99 7682 us
app CPU per request: 368 us (utime+stime of the app JVM only, 24000 requests)
-- GET /orders/1
round 1: 898 req/s p50 2886 us p99 18366 us
round 2: 1075 req/s p50 2155 us p99 17843 us
round 3: 1660 req/s p50 1369 us p99 13317 us
app CPU per request: 937 us (utime+stime of the app JVM only, 24000 requests)
-- RSS after the run: 467 MiB
== agent, 10% sampling
CPU consumed by the JVM from process start to ready (+4 s idle): 13900 ms
Started OrdersApplication in 3.557 seconds (process running for 6.947)
-- GET /ping
round 1: 1903 req/s p50 1261 us p99 8751 us
round 2: 3080 req/s p50 815 us p99 6476 us
round 3: 4395 req/s p50 506 us p99 5679 us
app CPU per request: 345 us (utime+stime of the app JVM only, 24000 requests)
-- GET /orders/1
round 1: 730 req/s p50 4706 us p99 15682 us
round 2: 1337 req/s p50 2297 us p99 10480 us
round 3: 1978 req/s p50 1539 us p99 8297 us
app CPU per request: 1267 us (utime+stime of the app JVM only, 24000 requests)
-- RSS after the run: 415 MiB
== micrometer starter, 10% sampling
CPU consumed by the JVM from process start to ready (+4 s idle): 7850 ms
Started OrdersApplication in 3.336 seconds (process running for 3.694)
-- GET /ping
round 1: 1607 req/s p50 1635 us p99 10174 us
round 2: 3176 req/s p50 736 us p99 7275 us
round 3: 4997 req/s p50 413 us p99 5595 us
app CPU per request: 326 us (utime+stime of the app JVM only, 24000 requests)
-- GET /orders/1
round 1: 856 req/s p50 3859 us p99 16063 us
round 2: 1451 req/s p50 2154 us p99 9741 us
round 3: 1770 req/s p50 1809 us p99 8160 us
app CPU per request: 1076 us (utime+stime of the app JVM only, 24000 requests)
-- RSS after the run: 334 MiB
== micrometer starter + JDBC observation, all spans sampled
CPU consumed by the JVM from process start to ready (+4 s idle): 9380 ms
Started OrdersApplication in 3.959 seconds (process running for 4.405)
-- GET /ping
round 1: 2018 req/s p50 1117 us p99 9328 us
round 2: 3270 req/s p50 586 us p99 9113 us
round 3: 5052 req/s p50 323 us p99 7483 us
app CPU per request: 317 us (utime+stime of the app JVM only, 24000 requests)
-- GET /orders/1
round 1: 646 req/s p50 5076 us p99 20246 us
round 2: 1054 req/s p50 2731 us p99 15085 us
round 3: 1467 req/s p50 1636 us p99 14121 us
app CPU per request: 1190 us (utime+stime of the app JVM only, 24000 requests)
-- RSS after the run: 462 MiB
Going deeper
- scripts/overhead.sh and LoadDriver.java
- Next step if this matters to you: repeat it with the load generator and receiver on another machine, and with JMH-style discipline; see JMH Tutorial: Writing Java Microbenchmarks That Don’t Lie
Which one should you use?
There is no universal winner, but the evidence above gives a fairly clean decision. Start from what you control.| Your situation | Lean towards | Why (from the runs above) |
|---|---|---|
| You want traces on a service you cannot or will not change, or on many services at once | Agent | No dependency, no code; it found JDBC, the HTTP client and the thread hand-off with no help |
| You need database spans with SQL and standard attribute names | Agent | Micrometer has no JDBC spans by default; the third-party option works but names and attributes are its own |
| Your app hops threads through pools you create yourself | Agent, or Micrometer plus deliberate context propagation | The orphaned audit.write trace |
| Startup time or per-instance CPU is tight (short-lived jobs, aggressive autoscaling) | Micrometer | The agent added roughly three times the startup CPU that the Micrometer build did |
| You want one API for custom spans and metrics, testable in unit tests | Micrometer | pricing.compute gave a span and a timer from one Observation |
| You already run Actuator dashboards on Micrometer metric names | Micrometer | 77 Micrometer metrics against 25 agent ones, with different names and units |
| You want the agent’s coverage and Micrometer metrics | One of them per service | Running both traced every request twice and added exporter spans |
Should you do either? Only if you have somewhere to send OTLP and someone who will look at it. A trace nobody opens costs CPU and money. If all you need today is request counts and latencies, Actuator metrics with no tracing at all are the cheaper answer; add tracing when a question appears that metrics cannot answer, which is usually “where did this one slow request spend its time?”. Also not tested here: native-image builds (the agent works by rewriting bytecode in a running JVM, so check your build target before assuming it applies), other agent versions, other web servers than Tomcat, and any real tracing backend.
How to reproduce every transcript
You need JDK 25, Maven 3.9, curl and network access to Maven Central (the script downloads the agent jar once). See README.md and scripts/run-all.sh.
git clone https://ankurm.com/git.app/asmhatre/spring-boot-demo.git
cd spring-boot-demo/otel-agent-vs-micrometer
scripts/run-all.sh # builds three jars, runs every scenario, rewrites output/
SKIP_OVERHEAD=1 scripts/run-all.sh # skip the slow measurementFiles 01–07, 09 and 10 are deterministic apart from ordering inside a trace. File 08 will differ on your machine.
Further reading
- Companion code: spring-boot-demo/otel-agent-vs-micrometer
- Micrometer to OpenTelemetry: The Spring Boot 4 Observability Guide (Beginner to Advanced)
- Spring Boot 4.2 OpenTelemetry: Semantic Conventions, Shared OTLP Settings and MDC Keys
- OpenTelemetry Java agent documentation
- Agent: annotations and methods.include
- Spring Boot reference: Tracing
- Micrometer Observation API
No Comments yet!