Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

What is the Micrometer Observation API and how does Spring Framework 6 use it for metrics and tracing?

The Micrometer Observation API lets us instrument an operation once, as an Observation with a name and key values, and then registered handlers turn that single observation into a timer metric, a trace span or log entries. Spring Framework 6 instruments server requests, RestTemplate, RestClient and WebClient this way, and Spring Boot 3 auto-configures the ObservationRegistry, with Micrometer Tracing replacing Spring Cloud Sleuth. Low-cardinality key values become metric tags, high-cardinality ones go only to traces, and ObservationConvention beans change names and key values without touching the instrumentation.

Why this question is asked

Before Spring Boot 3, a typical service had two separate kinds of instrumentation: Micrometer timers for metrics and Spring Cloud Sleuth for traces, each wrapping the same HTTP calls in its own way. That meant duplicated work, slightly different names and tags, and two places to change. The Observation API in Micrometer 1.10, adopted by Spring Framework 6, replaced that with one abstraction. Interviewers ask about it because it is now the way every Spring service produces telemetry, and because the cardinality rule behind it is a common cause of exploding metrics bills. In this answer, we will recap metrics and traces, see how an Observation works, look at what Spring instruments for us, understand low and high cardinality, and customise names with a convention.

1A Quick Recap of Metrics and Traces

A metric is a number aggregated over time, such as the count and duration of HTTP requests grouped by status. Metric systems like Prometheus store one time series for every distinct combination of tags, so a metric with tags method and status creates a handful of series. A trace records a single request as it travels through services; each step is a span with a start, an end and attributes, and spans share a trace id so we can see the whole journey.

Both kinds of telemetry describe the same thing, an operation that starts, maybe fails and ends. The Observation API builds on that observation.

2How an Observation Works

An Observation is created from an ObservationRegistry with a name, given key values, started, stopped and given any error. We rarely do those steps by hand; observe() wraps a piece of code and does them for us. The registry holds ObservationHandler instances, and each handler reacts to the lifecycle events: on start, on error and on stop.

Java
Observation.createNotStarted("orders.place", registry)
.lowCardinalityKeyValue("channel", "web") // bounded set of values: web, mobile, partner
.highCardinalityKeyValue("order.id", orderId) // unbounded: one value per order
.observe(() -> orderService.place(order));
// With Boot's default handlers:
// metric: orders.place (a timer) tagged channel=web, error=none -> count and duration
// trace: span "orders.place" with channel=web and order.id=8412 -> appears in the trace
Step throughOne observation, many outputs
  1. Application or framework codeobserve("orders.place")
  2. ObservationRegistryholds conventions, filters and handlers
  3. Meter handlerTimer orders.place with low-cardinality tags
  4. Tracing handlerspan with all key values, via Brave or OpenTelemetry
  5. ExportersPrometheus or OTLP for metrics, Zipkin or OTLP for traces

5 layers, from the top down. Step through them one at a time.

Notice that we wrote the instrumentation once. The meter handler, DefaultMeterObservationHandler, turns the observation into a Timer and a long task timer. The tracing handler from Micrometer Tracing turns it into a span. If we add a logging handler later, existing code needs no change. For methods, the @Observed annotation does the same through an aspect once ObservedAspect is registered.

3What Spring Framework 6 Instruments for Us

Spring Framework 6 creates observations at the important boundaries. On the server side, Spring MVC uses a filter, ServerHttpObservationFilter, and WebFlux has an equivalent, so every request produces an observation named http.server.requests with tags such as method, uri template, status and outcome. On the client side, RestTemplate, RestClient and WebClient produce http.client.requests observations, which also propagate the trace context to the next service in request headers. Later 6.x releases added observations for @Scheduled methods and messaging; check the release notes for your version.

With Spring Boot 3 and later, the ObservationRegistry is auto-configured and connected to the MeterRegistry. Adding a Micrometer Tracing bridge, micrometer-tracing-bridge-brave or micrometer-tracing-bridge-otel, plus an exporter turns on tracing. Spring Cloud Sleuth does not support Boot 3; Micrometer Tracing is its successor, and log correlation with traceId and spanId in the log pattern is handled by Boot.

4Low and High Cardinality Key Values

Cardinality means the number of distinct values a key can take. A low-cardinality key, such as channel or HTTP method, has a small, bounded set. A high-cardinality key, such as an order id, user id or full URL with ids in it, has a value per request.

The Observation API keeps them apart because the two backends behave differently. Metrics create a time series per combination of tag values, so low-cardinality key values become metric tags and also span attributes. High-cardinality key values go only to traces, where each span is stored individually anyway. That split is why http.server.requests uses the uri template /orders/{id} as its tag, not the real path /orders/8412.

5Customising Names and Tags With a Convention

Every built-in observation gets its name and key values from an ObservationConvention. To add a tag or rename one, we extend the default convention and expose it as a bean. Boot picks up a bean of the matching convention type for the server or client instrumentation.

Java
@Component
class RegionServerConvention extends DefaultServerRequestObservationConvention {
@Override
public KeyValues getLowCardinalityKeyValues(ServerRequestObservationContext context) {
String region = context.getCarrier().getHeader("X-Region");
return super.getLowCardinalityKeyValues(context)
.and(KeyValue.of("region", region == null ? "unknown" : region)); // a bounded value
}
}
// http.server.requests now has the tag region=eu, us or unknown

The instrumentation itself is untouched, and every team gets the same tag in the same way. Notice the fallback to unknown: a convention must also keep cardinality bounded, so we never pass a raw header through without checking it.

6Follow-up questions

Why should a user id never be a low-cardinality key value?

Because every distinct tag value creates a new time series in the metrics backend. A service with a million users would turn one timer into a million series, multiplied by every other tag combination. That uses memory in the application's MeterRegistry, slows queries and can make a hosted metrics bill grow by orders of magnitude, or crash a Prometheus server. As a high-cardinality key value it only appears on spans, which is where per-request detail belongs.

What is an ObservationFilter or ObservationPredicate for?

An ObservationPredicate decides whether an observation is created at all, for example to skip actuator health checks. An ObservationFilter can modify the context before it reaches the handlers, for example to add a common key value such as the application name to every observation. In Boot, beans of these types are registered with the registry automatically.

Does an Observation have a cost when no handler is registered?

Very little. If the registry is a no-op registry or no handler supports the context, the observation does almost nothing. That is why libraries can instrument themselves safely and let the application decide what to export.

7Conclusion

In this answer, we saw that the Observation API instruments an operation once and lets handlers turn it into metrics, traces or logs. Spring Framework 6 creates observations for server requests and for RestTemplate, RestClient and WebClient calls, and Boot 3 auto-configures the registry, with Micrometer Tracing replacing Sleuth. Low-cardinality key values become metric tags, high-cardinality ones go only to traces, and ObservationConvention beans change names and tags without rewriting the instrumentation.

What to say in the interviewAbout 80 seconds aloud

Open with

The Observation API is Micrometer's single abstraction for instrumenting an operation. We create an Observation with a name and key values and wrap the code with observe, and handlers registered on the ObservationRegistry react to its start, error and stop.

Then, if they want more

The meter handler turns it into a timer, the tracing handler turns it into a span, and we could add a logging handler without touching the code. Spring Framework 6 uses it everywhere at the boundaries: server requests in MVC and WebFlux produce http.server.requests, and RestTemplate, RestClient and WebClient produce http.client.requests and propagate trace headers.

With Boot 3 the registry is auto-configured, and adding a Micrometer Tracing bridge for Brave or OpenTelemetry gives tracing, which replaces Spring Cloud Sleuth, since Sleuth does not support Boot 3. The key detail is cardinality. Low-cardinality key values, with a small bounded set like method or status, become metric tags, because each tag combination is a time series.

High-cardinality values like an order id or user id go only to spans. That is why the uri tag is the template, not the real path. To change names or tags, I extend the default convention, for example DefaultServerRequestObservationConvention, and register it as a bean, so the instrumentation stays the same across services.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 6, Spring Boot 3
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is the Micrometer Observation API and how does Spring Framework 6 use it for...": https://scrivio-interview-library.netlify.app/spring-boot/spring-framework-evolution/58ba4f7e84/