Quick revision
The short answer
The Micrometer Observation API lets us describe an operation once, with a name, key values and a start and stop, and registered handlers turn that single observation into a timer, a trace span and log context. Creating metrics and spans separately means writing timing code and tracing code side by side and keeping them in sync by hand. To observe a business operation we write Observation.createNotStarted("order.place", registry).lowCardinalityKeyValue("type", type).observe(() -> place(order)).
What to remember
In this answer, we saw that the Observation API describes an operation once, with a name, key values and a lifecycle, and that handlers registered in the ObservationRegistry turn it into a timer, a span and log correlation. This removes the duplicated, drifting code we had when metrics and spans were written separately. Low cardinality key values become metric tags and span attributes, while high cardinality ones only go to spans. Spring uses the same API for HTTP, data and messaging, and @Observed offers an annotation alternative that needs an ObservedAspect bean and AOP.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The Micrometer Observation API lets us describe an operation once, with a name, key values and a start and stop, and registered handlers turn that single observation into a timer, a trace span and log context. Creating metrics and spans separately means writing timing code and tracing code side by side and keeping them in sync by hand. To observe a business operation we write Observation.createNotStarted("order.place", registry).lowCardinalityKeyValue("type", type).observe(() -> place(order)).
Why this question is asked
Before Spring Boot 3, instrumenting a piece of code for both metrics and tracing meant two APIs: a Micrometer timer around the code and a Sleuth or OpenTelemetry span around the same code, each with its own tags and its own error handling. They drifted apart, and teams often did only one of them. The Observation API, which Spring Framework 6 and Boot 3 adopted everywhere, fixes this by separating what we observe from what is produced from it. Interviewers ask about it because it is now how Spring itself instruments HTTP, data access and messaging, so understanding it explains where our metrics and spans come from. In this answer, we will recap the old approach, see what an observation is and how handlers work, observe a business operation in code, look at low and high cardinality key values, and finish with the @Observed annotation and what it needs.
1A Quick Recap: Metrics and Spans Written Separately
A metric, such as a timer, summarises many operations into numbers like count and duration. A span is a record of one single operation in a trace, with a start time, an end time, attributes and a parent. They describe the same work from two angles. Without a common API, we write both by hand.
This works, but notice the duplication: the name, the tag and the error handling appear twice, and a later change to one is easily forgotten in the other. Multiply that by every operation in every service and the instrumentation becomes inconsistent.
2What an Observation Is
An Observation is an object that represents one operation while it runs. It has a name, a context that carries key values and any data handlers need, and a lifecycle: start, optional events, optional error, stop. It does not know whether it will become a metric, a span or a log line.
The ObservationRegistry holds ObservationHandlers. Each handler listens to the lifecycle and produces one kind of signal. In a Spring Boot application with Actuator and Micrometer Tracing, Boot registers a meter handler that creates a timer (and a long task timer for operations still running) and a tracing handler that creates a span and puts the trace id into the logging MDC. So one observation becomes all three, and adding a new kind of output is a matter of registering another handler.
7 messages in order. Play them, or step through them one at a time.
The service describes the operation once; each handler turns it into its own signal.
3Observing a Business Operation
Here is the same operation written with the Observation API. We inject the ObservationRegistry that Spring Boot configures, create an observation that has not started yet, add key values, and let observe() handle start, scope, error and stop for us.
Notice that observe() opens a scope, so any code inside doPlace, including HTTP or database calls that Spring instruments, becomes a child of our span. If doPlace throws, observe() records the error on the observation, so the span is marked as failed and the timer gets an error tag with the exception's class name, and then the exception is rethrown. We wrote one block and got consistent signals.
4Low and High Cardinality Key Values
Cardinality means how many different values something can take. A low cardinality key value, such as an order type with five possible values, is safe as a metric tag, so the meter handler uses it as a tag and the tracing handler also adds it to the span. A high cardinality key value, such as an order id, would create a new time series per order if it became a tag, so the meter handler ignores it and only the span carries it.
This split is one of the most useful parts of the API. It puts the decision in one place, at the point where the developer knows what the value is, and it protects the metrics backend without losing detail in traces.
| Key value | Kind | Metric tag | Span attribute |
|---|---|---|---|
| type=express | low cardinality | yes | yes |
order.id=A-1093 | high cardinality | no | yes |
| error=none / class name | added by observe() | yes | span marked as error |
5Spring's Own Instrumentation and @Observed
The same mechanism is used by Spring itself. Spring MVC and WebFlux create observations for server requests, RestClient, RestTemplate and WebClient do it for client requests when built from Boot's builders, and Spring Data, Spring Kafka and other projects do it for their calls. That is why http.server.requests metrics and HTTP spans line up: they come from the same observation.
For simple cases there is an annotation. @Observed on a method creates an observation around it, but it works through an aspect, so it needs an ObservedAspect bean and AOP on the classpath (spring-boot-starter-aop in Boot 3, renamed in Boot 4, so check your version). Recent Boot versions can register the aspect for us when management.observations.annotations.enabled=true is set.
Because it is an aspect, the usual proxy rules apply: calling the method from another method of the same class skips the aspect, and the annotation can only use constant key values. When we need values from the arguments, such as the order type, the programmatic API is the better fit.
6Follow-up questions
Does the Observation API replace the Tracer and MeterRegistry APIs?
No. They remain available and sometimes we still need them, for example a gauge for a queue size is not an operation with a start and a stop, so it is registered directly with the MeterRegistry. The Observation API is for operations, things that start, may fail and finish.
How do we customise Spring's built-in observations?
Each instrumented component accepts an ObservationConvention, which decides the name and key values, and we can register our own convention as a bean. For cross-cutting changes there are ObservationFilter, which edits the context before it is stopped, and ObservationPredicate, which can switch observations off, for example for actuator endpoints.
What happens if no handlers are registered?
Then observations are effectively no-ops. The ObservationRegistry.NOOP registry, used in some tests, does nothing at all, so instrumented code costs almost nothing. That makes it safe for libraries to instrument themselves and leave the decision about outputs to the application.
7Conclusion
In this answer, we saw that the Observation API describes an operation once, with a name, key values and a lifecycle, and that handlers registered in the ObservationRegistry turn it into a timer, a span and log correlation. This removes the duplicated, drifting code we had when metrics and spans were written separately. Low cardinality key values become metric tags and span attributes, while high cardinality ones only go to spans. Spring uses the same API for HTTP, data and messaging, and @Observed offers an annotation alternative that needs an ObservedAspect bean and AOP.
Open with
The Observation API, which Spring Boot 3 adopted everywhere, lets me describe an operation once and have several signals produced from it. Before, I'd start a timer and a span separately around the same code, with the same name and tags and error handling written twice, and they'd drift apart.
Then, if they want more
Now I create an observation with a name and key values, and the ObservationRegistry's handlers decide what comes out: Boot registers a meter handler that records a timer and a tracing handler that creates a span and puts the trace id in the MDC for logs.
For a business operation, I'd write Observation.createNotStarted with order.place and the registry, add lowCardinalityKeyValue type with the order type, maybe a highCardinalityKeyValue for the order id, and then call observe with a lambda that places the order. observe handles start, scope, errors and stop, so nested HTTP or database calls become child spans and failures are tagged.
The distinction between key values matters: low cardinality ones become metric tags and span attributes, high cardinality ones go only to spans, so I don't blow up the metrics backend. Spring's HTTP, data and messaging instrumentation uses the same API.
There's also @Observed, but it's an aspect, so it needs an ObservedAspect bean and AOP, and it has the usual proxy limitations.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3, Spring Framework 6
- 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.
- Official documentation
- Spring Cloud documentation, Resilience4j documentation
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 it differ from creating metrics and...": https://scrivio-interview-library.netlify.app/spring-boot/observability/198b07ae5d/