Modern applications rarely work in isolation. A Spring Boot application may communicate with databases, REST APIs, message brokers, authentication services, and other microservices. When something goes wrong, developers need to understand where the problem occurred, how long each operation took, and which services were involved.
Observability provides this information through metrics, traces, and logs. However, collecting telemetry is only part of the challenge. Different applications may use different names for the same operation, making it difficult to compare data across services.
For example, one application may record an HTTP request method as method, while another uses http.method. A monitoring platform must understand these differences before it can provide consistent dashboards and queries.
OpenTelemetry Semantic Conventions solve this problem by defining standard names and attributes for common operations. Spring Boot supports these conventions through Micrometer Observation and its OpenTelemetry integration.
This article explains how semantic conventions work, how to enable them in Spring Boot, how to create custom observations, and how to use consistent telemetry across distributed applications.
Understanding OpenTelemetry Semantic Conventions
OpenTelemetry is an open-source observability framework that provides APIs, SDKs, and instrumentation for collecting and exporting telemetry.
Semantic conventions define standard names and attributes for telemetry data. They help different frameworks and services describe similar operations in a consistent way.
For example, an HTTP server request can include attributes describing:
- HTTP request method.
- HTTP response status code.
- Server address.
- Request URL or route.
- Error information.
- Network protocol.
Instead of creating custom attribute names for every application, developers can follow the OpenTelemetry conventions.
Consider two services that handle HTTP requests.
Without standard conventions, one service might report:
method = GET
status = 200
path = /customers
Another service might report:
http.method = GET
http.status_code = 200
http.route = /customers
Although the information is similar, the different attribute names make centralized monitoring more complicated.
With semantic conventions, services can use standardized attribute names such as http.request.method and http.response.status_code, subject to the applicable convention version and instrumentation.
This makes telemetry easier to search, compare, aggregate, and analyze.
Why Semantic Conventions Matter in Spring Boot
Spring Boot applications commonly use Micrometer for metrics and tracing.
Micrometer provides an Observation API that allows Spring components and application code to record operations. These observations can produce metrics and trace spans depending on the configured observation handlers.
Spring Boot automatically instruments several framework operations, including HTTP server requests, HTTP client exchanges, and scheduled task execution.
However, the default conventions used by Micrometer and Spring are not necessarily identical to OpenTelemetry semantic conventions.
Spring Boot provides a configuration property to select OpenTelemetry conventions for supported observations.
management:
observations:
conventions: open-telemetry
This tells Spring Boot to use OpenTelemetry's stable semantic conventions where supported.
There are several benefits:
- Consistent attribute names across services.
- Easier integration with OpenTelemetry-compatible monitoring platforms.
- Better compatibility with distributed tracing systems.
- More consistent dashboards and alerting rules.
- Less custom mapping between different telemetry formats.
An important detail is that Spring Boot's native Micrometer integration and the OpenTelemetry Java agent are different instrumentation approaches. They may produce telemetry through different libraries and configuration mechanisms. Choose one approach deliberately to avoid duplicate spans and metrics.
Adding OpenTelemetry Dependencies to Spring Boot
The required dependencies depend on the instrumentation approach.
For a Spring Boot application using Micrometer Tracing with the OpenTelemetry exporter, start with Spring Boot Actuator and the OpenTelemetry tracing bridge.
A Maven configuration can look like this:
<dependencies>
<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>
</dependencies>
Use Spring Boot's dependency management to select compatible versions instead of specifying arbitrary versions for each dependency.
The responsibilities of these dependencies are different:
| Dependency | Purpose |
|---|
| Spring Boot Actuator | Provides application management and observability support |
| Micrometer Tracing Bridge | Connects Micrometer tracing with OpenTelemetry |
| OpenTelemetry OTLP Exporter | Exports telemetry using the OpenTelemetry Protocol |
The application can now configure tracing and export data to an OpenTelemetry-compatible backend or collector.
Enabling OpenTelemetry Semantic Conventions
After adding the dependencies, configure the observation conventions in application.yml.
spring:
application:
name: customer-service
management:
endpoints:
web:
exposure:
include: health,info,metrics
observations:
conventions: open-telemetry
tracing:
sampling:
probability: 0.5
otlp:
tracing:
endpoint: http://localhost:4318/v1/traces
The configuration includes several important settings.
The application name identifies the service in observability data.
The conventions property selects OpenTelemetry conventions for supported Spring observations.
The sampling probability controls how many traces are sampled. A value of 0.5 means the application aims to sample approximately 50 percent of eligible traces.
The OTLP endpoint identifies the destination for trace data. The example uses an HTTP endpoint commonly exposed by an OpenTelemetry Collector.
Make sure the exporter protocol and endpoint match the collector configuration. OTLP can use HTTP or gRPC, and the endpoint format differs depending on the selected transport.
For local development, a collector can receive telemetry and forward it to a tracing backend.
Understanding Automatic Instrumentation
One of the useful features of Spring Boot observability is that developers do not need to create spans manually for every framework operation.
Spring automatically instruments supported components when the required observation infrastructure is configured.
HTTP Server Requests
When a client sends a request to a Spring MVC controller, Spring can create an observation for the server exchange.
For example:
@RestController
@RequestMapping("/customers")
public class CustomerController {
@GetMapping("/{id}")
public Customer getCustomer(@PathVariable Long id) {
return new Customer(
id,
"John",
"[email protected]"
);
}
}
Spring records information about the request, including its method, status, and route-related details where available.
When tracing is enabled, this information can become part of a distributed trace.
A monitoring platform can then show how long the request took and whether it completed successfully.
HTTP Client Requests
Spring also supports observations for HTTP client operations.
For example, a service may call an external customer API:
@Service
public class CustomerClient {
private final RestClient restClient;
public CustomerClient(RestClient.Builder builder) {
this.restClient = builder
.baseUrl("https://api.example.com")
.build();
}
public Customer getCustomer(Long id) {
return restClient.get()
.uri("/customers/{id}", id)
.retrieve()
.body(Customer.class);
}
}
Spring's HTTP client instrumentation can record the time spent making the request.
When context propagation is configured correctly, the client span can become a child of the incoming server span. This helps developers follow a request across service boundaries.
Automatic instrumentation depends on the HTTP client implementation and the observation infrastructure being used. Verify the supported client and framework versions in the relevant Spring documentation.
Creating Custom Observations
Automatic instrumentation covers many framework operations, but business-specific operations may need additional telemetry.
For example, an order service may need to measure how long payment processing takes.
Spring Boot provides Micrometer's Observation API for this purpose.
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
import org.springframework.stereotype.Service;
@Service
public class PaymentService {
private final ObservationRegistry observationRegistry;
public PaymentService(
ObservationRegistry observationRegistry) {
this.observationRegistry = observationRegistry;
}
public void processPayment(Long orderId) {
Observation.createNotStarted(
"payment.process",
observationRegistry
)
.lowCardinalityKeyValue(
"payment.provider",
"example"
)
.observe(() -> {
// Execute payment processing logic
System.out.println(
"Processing payment for order " + orderId
);
});
}
}
The example creates a custom observation named payment.process.
The lowCardinalityKeyValue() method adds a bounded attribute that can be used in both metrics and traces.
The observe() method executes the business operation within the observation's lifecycle.
When the configured handlers support metrics and tracing, the observation can contribute to both signals.
Choosing Low-Cardinality and High-Cardinality Attributes
Cardinality is an important consideration when adding custom attributes.
Low-cardinality attributes have a limited number of possible values. Examples include payment provider, operation type, and payment status.
High-cardinality attributes can have many unique values. Examples include customer IDs, order IDs, and request identifiers.
Micrometer distinguishes these attributes because metrics systems can become expensive or difficult to operate when they contain too many unique time series.
For example:
Observation.createNotStarted(
"payment.process",
observationRegistry
)
.lowCardinalityKeyValue(
"payment.provider",
"example"
)
.lowCardinalityKeyValue(
"payment.status",
"success"
)
.highCardinalityKeyValue(
"order.id",
orderId.toString()
)
.observe(() -> {
// Payment operation
});
The provider and status are suitable for metrics because their values are limited.
The order ID is more suitable for trace context because it can be different for every operation.
Avoid placing sensitive information, such as passwords, payment card numbers, or personal data, in telemetry attributes.
Adding Custom Semantic Conventions
Sometimes an application needs additional information that is not included in the default observation.
Spring allows developers to customize observations through convention classes.
For example, a Spring MVC application can extend DefaultServerRequestObservationConvention to add a custom low-cardinality attribute.
import io.micrometer.common.KeyValue;
import io.micrometer.common.KeyValues;
import org.springframework.http.server.observation
.DefaultServerRequestObservationConvention;
import org.springframework.http.server.observation
.ServerRequestObservationContext;
public class CustomServerObservationConvention
extends DefaultServerRequestObservationConvention {
@Override
public KeyValues getLowCardinalityKeyValues(
ServerRequestObservationContext context) {
return super.getLowCardinalityKeyValues(context)
.and(
KeyValue.of(
"application.operation",
context.getCarrier().getMethod()
)
);
}
}
Register the convention as a bean:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ObservationConfig {
@Bean
public CustomServerObservationConvention
customServerObservationConvention() {
return new CustomServerObservationConvention();
}
}
This example retains the default attributes and adds one custom attribute.
When extending an existing convention, avoid replacing standard attributes unnecessarily. Standardized names are valuable because they allow monitoring tools and teams to understand telemetry consistently.
Also, custom attributes should not reuse OpenTelemetry standard attribute names with different meanings. If an attribute is specific to the application, use an application-specific namespace.
Choosing Between Spring Boot and OpenTelemetry Instrumentation
There are different ways to instrument a Spring Boot application with OpenTelemetry.
The main approaches are Spring Boot's Micrometer integration, the OpenTelemetry Java agent, and the OpenTelemetry Spring Boot starter.
| Approach | How it works | Suitable use case |
|---|
| Spring Boot with Micrometer | Uses Spring observations and Micrometer tracing | Applications already using Actuator and Micrometer |
| OpenTelemetry Java agent | Instruments supported libraries through bytecode instrumentation | Quick automatic instrumentation with minimal code changes |
| OpenTelemetry Spring Boot starter | Uses Spring Boot auto-configuration for OpenTelemetry instrumentation | Native images and applications needing configuration through Spring properties |
The Java agent is often the simplest starting point when an application needs broad automatic instrumentation.
The OpenTelemetry Spring Boot starter is useful when the Java agent is unsuitable, such as certain native-image deployments or environments where another monitoring agent is already installed.
Spring Boot's native Micrometer integration is a natural option when the application already relies on Actuator and Micrometer.
Avoid installing multiple instrumentation approaches without checking what each one instruments. Running overlapping agents and libraries can produce duplicate spans, duplicate metrics, and confusing trace relationships.
Context Propagation Across Services
Distributed tracing is useful only when trace context travels between application boundaries.
Consider an application with three services:
API Gateway
|
v
Order Service
|
v
Payment Service
A request enters through the API Gateway, moves to the Order Service, and then calls the Payment Service.
Without context propagation, each service may create an independent trace. Developers cannot easily determine that all three operations belong to the same request.
OpenTelemetry uses propagation formats such as W3C Trace Context to carry trace information across HTTP requests.
The commonly used headers include:
traceparent
tracestate
Supported Spring instrumentation can propagate the current trace context automatically when configured correctly.
For asynchronous and reactive operations, context propagation requires additional attention.
For example, Spring Boot provides configuration for reactive context propagation:
spring:
reactor:
context-propagation: auto
task:
execution:
propagate-context: true
The first property enables automatic propagation for Reactor pipelines.
The second opts into context propagation for the auto-configured task execution infrastructure.
If the application defines its own executor, register an appropriate ContextPropagatingTaskDecorator rather than assuming the default executor configuration will apply.
Troubleshooting OpenTelemetry Semantic Conventions
Even when the configuration appears correct, telemetry may not look as expected.
Metrics Still Use Micrometer Names
Check that the following property is configured:
management:
observations:
conventions: open-telemetry
Also remember that Spring Boot's OpenTelemetry convention support is limited to stable conventions. Not every metric or observation automatically changes to an OpenTelemetry-specific name.
Duplicate Spans Appear in Traces
This can happen when the application uses multiple instrumentation approaches simultaneously.
For example, Spring's Micrometer tracing and the OpenTelemetry Java agent may both instrument the same HTTP operation.
Review the active agents, dependencies, and auto-configuration settings. Choose one primary instrumentation path for each operation.
Trace Context Is Lost Between Services
Verify that the HTTP client and server instrumentation support context propagation.
For asynchronous code, check whether Reactor or task executor context propagation is configured.
Also confirm that outbound requests contain the expected trace headers.
Telemetry Is Not Reaching the Collector
Check the collector endpoint, protocol, network connectivity, and exporter configuration.
For an OTLP HTTP exporter, verify that the configured endpoint uses the correct traces path and that the collector accepts the selected transport.
Inspect application startup logs and collector logs for exporter connection failures.
Custom Attributes Do Not Appear
Confirm that the custom observation is actually executed and that its registry has the expected handlers.
Also check whether the attribute was added as a low-cardinality or high-cardinality value. Metrics and traces do not necessarily receive the same attributes.
Best Practices for Production Applications
- Enable OpenTelemetry conventions consistently across related services.
- Use a compatible Spring Boot, Micrometer, and OpenTelemetry dependency combination.
- Prefer automatic instrumentation for supported framework operations.
- Add custom observations for important business operations.
- Use low-cardinality attributes for metrics.
- Keep high-cardinality identifiers in traces when necessary.
- Never include credentials or sensitive personal information in telemetry.
- Configure sampling based on traffic volume and observability requirements.
- Verify context propagation across HTTP, asynchronous, and reactive boundaries.
- Avoid duplicate instrumentation from multiple agents or libraries.
- Monitor collector availability and exporter failures.
- Review telemetry changes when upgrading Spring Boot or OpenTelemetry dependencies.
Advantages and Disadvantages
Advantages
- Standardizes telemetry attribute names across applications.
- Makes distributed traces easier to understand.
- Improves compatibility with OpenTelemetry-compatible backends.
- Reduces custom attribute mapping.
- Integrates with Spring Boot's Micrometer Observation infrastructure.
- Supports automatic and manual instrumentation.
- Helps teams create consistent monitoring dashboards.
Disadvantages
- Requires compatible instrumentation and dependency configuration.
- Existing monitoring queries may need updates when conventions change.
- Running multiple instrumentation systems can create duplicate telemetry.
- High-cardinality attributes can increase monitoring costs.
- Context propagation needs additional configuration in some asynchronous environments.
- Not every Spring observation has an OpenTelemetry convention equivalent.
Conclusion
OpenTelemetry Semantic Conventions make application telemetry more consistent and easier to understand across distributed systems. For Spring Boot developers, they provide a practical way to standardize HTTP, application, and business-level observability data.
Spring Boot supports OpenTelemetry conventions through Micrometer Observation. Setting management.observations.conventions to open-telemetry enables supported stable conventions without requiring developers to rewrite every controller or service.
For production applications, combine automatic instrumentation with custom observations for important business operations. Pay particular attention to attribute cardinality, context propagation, sampling, and duplicate instrumentation.
A consistent observability strategy helps development and operations teams investigate failures faster, understand service dependencies, and make better decisions about application performance.
Join the conversation! Your thoughts help the community grow.