0

I am implementing Open Telemetry for Spring Boot 4.0 (spring-boot-starter-opentelemetry) trying to follow https://spring.io/blog/2025/11/18/opentelemetry-with-spring-boot. I have a simple controller:

@RestController
@RequestMapping("/api")
public class Controller {

    @GetMapping("/{id}")
    public ResponseEntity<?> getById(@PathVariable String id) {
        if ("1".equals(id)) {throw new RuntimeException("erro!!!!!");}
        if ("2".equals(id)) {return ResponseEntity.notFound().build();}
        if ("3".equals(id)) {return ResponseEntity.internalServerError().build();}
        String message = "ID: " + id;
        return ResponseEntity.ok(message);
    }
}

The traces are being exported and I am able to view them in Grafana. When my controller throw a not handled error, like to id=1 I get a useful trace on Grafana, including a "Events" field with stack trace, exception type, etc: Complete trace when the exception is not handled by controller

However, when the exception is handled by controller, like for id=2 or id=3, the error info is not registered in the trace, and I get only: Trace without error information when excpetion is handled by controller and a error ResponseEntity is returned

I can´t get what is missing so I get the full trace with Events and error information when the error is being "treated"

My application.properties is

spring.application.name=demo

management.otlp.metrics.export.url=http://localhost:4318/v1/metrics
management.opentelemetry.tracing.export.otlp.endpoint=http://localhost:4318/v1/traces
management.opentelemetry.logging.export.otlp.endpoint=http://localhost:4318/v1/logs
management.observations.annotations.enabled=true
management.tracing.sampling.probability=1.0

and in my pom.xml I have:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-opentelemetry</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry.instrumentation</groupId>
            <artifactId>opentelemetry-logback-appender-1.0</artifactId>
            <version>2.21.0-alpha</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-opentelemetry-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webmvc-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

I also have an OpenTelemetryConfiguration, InstallOpenTelemetryAppender and TraceIdFilter as in the post https://spring.io/blog/2025/11/18/opentelemetry-with-spring-boot.

1
  • Those situations don't have a stacktrace, so there is nothing to log. Should it make up a stracktrace when there is none? Commented Nov 25 at 10:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.