Skip to content
telemioDeveloper Docs
Open console
DOCUMENTATIONQuickstart · OpenTelemetryBrowse integrations ↗
Docs/Implementation guides/Backend services/Java and Spring Boot
IMPLEMENTATION GUIDE

Java and Spring Boot

Auto-instrument a Java service and add useful business spans.

What you will build

Auto-instrument a Java service and add useful business spans.

← All implementation paths

Attach the OpenTelemetry Java agent

The Java agent automatically instruments Spring Boot HTTP requests, clients, JDBC, and popular JVM libraries without changing Java source.

Before you begin: Create a Telemio workspace and a scoped ingest credential in the console. Keep server keys in deployment secrets. Set service.name and an environment on every service, and verify signals in the console after starting the process.
Shell
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-service"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production,service.version=1.0.0"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_ENDPOINT="https://your-collector.example.com"
java -javaagent:./opentelemetry-javaagent.jar -jar app.jar

Set the OTLP endpoint to a trusted Collector or your provisioned Telemio OTLP endpoint. When exporting directly, configure the collector/exporter authentication header according to your ingest setup. Do not mistake the read-only Developer Connect API for an OTLP receiver.

Add a business span in Spring

Use the standard OpenTelemetry API when you need domain context beyond automatic instrumentation.

Java
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.StatusCode;
import org.springframework.stereotype.Service;

@Service
public class OrderService {
    private final Tracer tracer;

    public OrderService(Tracer tracer) {
        this.tracer = tracer;
    }

    public void fulfill(String orderId) {
        Span span = tracer.spanBuilder("order.fulfill").startSpan();
        try (var scope = span.makeCurrent()) {
            span.setAttribute("order.id", orderId);
            performFulfillment(orderId);
        } catch (RuntimeException exception) {
            span.recordException(exception);
            span.setStatus(StatusCode.ERROR);
            throw exception;
        } finally {
            span.end();
        }
    }

    private void performFulfillment(String orderId) {
        throw new UnsupportedOperationException("Implement fulfillment")
    }
}

Add the opentelemetry-api dependency and configure a Tracer bean from your application’s OpenTelemetry instance, or obtain one from GlobalOpenTelemetry. Avoid introducing a second SDK instance when you already use the Java agent.

Production validation

Run an HTTP request through the service, then confirm the inbound server span and the child fulfillment span share a trace ID.

Check OTLP connectivity, service attributes, trace sampling and whether the Java agent is actually on the JVM command line. See the JVM guide for deployment considerations.