micrometer-metrics / tracing

Provides tracing abstractions over tracers and tracing system reporters.
https://micrometer.io
Apache License 2.0
249 stars 45 forks source link

Trace-Id not being sent with http outgoing requests during Integration test (After migrating to SpringBoot3) #518

Closed ZRaboB closed 10 months ago

ZRaboB commented 10 months ago

Hi All, We are facing an issue after migrating from Spring boot 2.7 to 3.1.7 and replacing sleuth with micrometer,

The issue is we send a header traceid with name "x-b3-trace-id" or "traceid" the header is visible within Incoming request all the way wihtin our app but whenever our app make an outgoing request using Feign or any other HTTP client those headers are gone and only the X-Auth-user is preserved. The same used to work with Sboot 2.7 while using sleuth & brave. (And Wiremock for Integration test)

Kindly let us know if there are known solutions already?

Code samples: Integration test :

    @Test
    fun getConceptGenericAuth() {
        val model = RestAssured.given()
            .header(X_AUTH_USER_HEADER, StubUser.adminPlusUser2.jwt) //VISIBLE AT SERVER
            .header("x-b3-traceid", "0000000000000006") //NOT VISIBLE AT SERVER
           .header("traceid", StubUser.adminPlusUser2.traceid)  //NOT VISIBLE AT SERVER
            .header("x-b3-spanid", "0000000000000006")  //NOT VISIBLE AT SERVER
            .`when`()
            .get(conceptGenericUrl("TBID00210000010337983Z000000115054733"))
            .then()
            .assertThat()
            .statusCode(200)
            .extract().body().asString()

        JSONAssert.assertEquals(IOUtils.resourceToString("/generic/expected-concept-generic-authorizations.json", StandardCharsets.UTF_8), model, true)
    }

WIREMOCK Config

 wireMockServer = WireMockServer(
            options()
                .globalTemplating(true)
                .port(stubConfiguration.port)
                .httpsPort(stubConfiguration.httpsPort)
                .keystorePath(keyStoreFullPath)
                .trustStorePath(keyStoreFullPath)
                .keystorePassword("stubsserver")
                .trustStorePassword("stubsserver")
                .keyManagerPassword("stubsserver")
                .containerThreads(stubConfiguration.containerThreads)
                .jettyAcceptors(stubConfiguration.acceptors)
                .jettyAcceptQueueSize(stubConfiguration.acceptQueueSize)
                .jettyHeaderRequestSize(stubConfiguration.headerBufferSize)
                .asynchronousResponseEnabled(stubConfiguration.asyncResponseEnabled)
                .asynchronousResponseThreads(stubConfiguration.asyncResponseThreads)
                .usingFilesUnderClasspath("stub-data-${stubConfiguration.applicationName}")
                .recordRequestHeadersForMatching(listOf("X-B3-TraceId", "X-B3-SpanId", "X-B3-ParentSpanId", "x-b3-trace-id"))
                .stubCorsEnabled(true)
                    .preserveHostHeader(true)
                .notifier(Slf4jNotifier(true)),
        )
            .also { stubJwkUrl(it, publicKey) }

Parts of our POM FILE (We may be have too many dependencies ?)


 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency>
            <groupId>io.zipkin.brave</groupId>
            <artifactId>brave-instrumentation-grpc</artifactId>
            <version>5.17.0</version>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-brave</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator-autoconfigure</artifactId>
            <version>3.1.7</version>
        </dependency>

     <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-micrometer</artifactId>
            <version>13.1</version>
        </dependency>

     <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-features-metrics</artifactId>
            <version>4.0.3</version>
        </dependency>
        <dependency>
            <groupId>io.zipkin.brave</groupId>
            <artifactId>brave-instrumentation-httpclient</artifactId>
            <version>5.17.0</version>
        </dependency>

   <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test-autoconfigure</artifactId>
            <version>3.1.7</version>
            <scope>test</scope>
        </dependency>
marcingrzejszczak commented 10 months ago

Have you configured the propagation mechanism to be B3 multi?

ZRaboB commented 10 months ago

HI marcingrzejszczak, Thanks for your reply, I just added that and now it seems to that the trace id is being sent but on a different format like 659e9010c6c4cc29d1b5b0fc5b4a1bbd and my older format 0000000000000006 don't seem valid anymore, Do you know wether my old format 0000000000000006 will work or not?

ZRaboB commented 10 months ago

And i also noticed that it works only when using FeignClient requests but not for WebServiceTemplate requests (Soap xml requests)

marcingrzejszczak commented 10 months ago

That's because the format is 128 bit. You can modify it by creating your own Tracing bean. You can check the config in Boot.