Spring boot 3 issue with micrometer tracing with handling Traceparent header
Asked Answered
U

1

9

I have below code which handle requests from other apps which pass the traceId through Traceparent header. I expect it will hydrate the parent traceId from the request, and in zipkin dashboard I should see the connection between this app and other apps. It used to work with spring-cloud-sleuth-zipkin. Now I migrated to spring boot 3 and the package is changed to micrometer-tracing-bridge-otel (See pom.xml). Now it no longer hydrate the parent traceId from the request but generate a default parent traceId which is all 0 instead, causing the app to disconnect from other apps in the zipkin dashboard

I tested with a simple curl request with the header Traceparent: curl --location --request GET 'http://localhost:8080/test' --header 'Traceparent: 00-63cf0173620c57b0aed605ee94255089-1444ca74c3d2133a-01' but this code does not extract the parent context from the header. Any idea how to make this work?

@RestController
public class Test {

    @Autowired
    private Tracer tracer;

    @GetMapping(path="/test")
    public ResponseEntity<?> handleTest() {
        ScopedSpan span = tracer.startScopedSpan("test span");
        return ResponseEntity.ok();
    }
}

pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.2</version>
    </parent>

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-otel</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>io.zipkin.reporter2</groupId>
            <artifactId>zipkin-sender-urlconnection</artifactId>
        </dependency>

Ubiety answered 24/1, 2023 at 18:55 Comment(0)
J
0

I think the simplest migration path from Sleuth (uses Brave by default) is through Brave:

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-tracing-bridge-brave'
implementation 'io.zipkin.reporter2:zipkin-reporter-brave'

Also, the name of the traceparent header should be lowercase, see in the docs on the other hand, any casing must work:

In order to increase interoperability across multiple protocols and encourage successful integration, by default vendors SHOULD keep the header name lowercase. The header name is a single word without any delimiters, for example, a hyphen (-).

Vendors MUST expect the header name in any case (upper, lower, mixed), and SHOULD send the header name in lowercase.

Could you please try with lowercase name and open an issue if it only works in that case?

I'm not sure what you are trying to do in the controller but it is not the right way to record a span (see the docs of Micrometer Tracing).

Also, we have a bunch of samples where this works: https://github.com/micrometer-metrics/micrometer-samples

We have

Jocundity answered 21/2, 2023 at 23:8 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.