Does someone implement Jaeger with Spring Cloud Gateway?
Asked Answered
S

1

7

We are re-building our software platform using a microservice architecture approach.

Most of it using Spring Boot libraries, and for our entry points we are using Spring Cloud Gateway which can be easily integrated with Jaeger to have tracing in the platform.

We do that using the following Maven dependency:

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
    <version>2.0.3</version>
</dependency>

And it is working pretty well, we can see the trace on the Jaeger UI web console.

The problem now is how to send the tracking information to the next inner service in the platform to have every service correlated.

Any ideas?

We have tried to inject the tracking information as HTML Headers using a GlobalFilter but it is using the incoming request and we need to put them on the downstream request... any clue on how to override HTTPClient used underneath.

@Bean
@Order(-1)
public GlobalFilter tracingFilter() {
    return (exchange, chain) -> {
        ServerHttpRequest request = exchange.getRequest();

        Tracer tracer = TracerResolver.resolveTracer();
        Span span = tracer.buildSpan(request.getMethod().toString())
                .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
                .start();

        Tags.HTTP_URL.set(span, request.getURI().toString());
        Tags.HTTP_METHOD.set(span, request.getMethod().toString());
        if (request.getURI().getPort() != -1) {
            Tags.PEER_PORT.set(span, request.getURI().getPort());
        }

        ServerHttpRequest.Builder requestBuilder = request.mutate();

        tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new RequestBuilderCarrier(requestBuilder));

        ...

        }));
    };
}
Systemic answered 28/8, 2019 at 14:22 Comment(0)
C
0

our solution:

Upstream filter implements org.springframework.cloud.gateway.filter.headers.HttpHeadersFilter

exchange.getAttributes().put('your_key_here', value);

Downstream filter implements org.springframework.cloud.gateway.filter.headers.HttpHeadersFilter

Object storedValue = exchange.getAttribute('your_key_here'); // NOTE can be null

and register them via Spring Java configuration(@Bean)

Casie answered 31/7, 2023 at 8:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.