Трассировка Istio + Jaeger с вызовами gRP C с использованием Spring Boot - PullRequest
0 голосов
/ 17 июня 2020

Я использую эту библиотеку ( grp c -spring-boot-starter ), поэтому у меня могут быть возможности gRP C в приложении Spring Boot.

Я хочу чтобы узнать, как правильно интегрировать это с трассировкой Istio + Jaeger.

Мне нужно знать, какие зависимости необходимы для этого.

У меня есть два (2) приложения, одно служит клиентом gRP C, а другое - gRP C сервер,

Ожидается, что трассировка между клиентом gRP C и сервером gRP C должна быть отражена в Jaeger. Но этого не происходит.

Я нахожусь внутри кластера Kubernetes с Istio.

На самом деле происходит HTTP-запрос -> Envoy sidecar -> gRP C Клиентская Spring Boot @RestController -> получить заголовки из HTTP-запроса -> скопировать их в вызов gRP C перед выполнением вызова -> gRP C Service.

Как мне сделать gRP C client <-> gRP C Сервисный след показан Jaeger?

Есть ли какие-либо зависимости, которые нужно импортировать?

Прямо сейчас у меня:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<!-- Used together with Sleuth to be able to trace gRPC calls. -->
<dependency>
    <groupId>io.zipkin.brave</groupId>
    <artifactId>brave-instrumentation-grpc</artifactId>
</dependency>
<!-- Add'l dependency for Istio + Jaeger gRPC tracing -->
<dependency>
    <groupId>io.jaegertracing</groupId>
    <artifactId>jaeger-client</artifactId>
</dependency>

Я также сделал что-то вроде этого, чтобы «распространить заголовки»:

private void propagateHeaders(HttpHeaders headers) {
    // TODO: adding these string values to a final / constant.
    // get these tracing headers from HTTP request, (coming from Envoy)
    String xRequestIdFromHttpHeader = headers.getFirst("x-request-id");
    String xB3TraceIdFromHttpHeader = headers.getFirst("x-b3-traceid");
    String xB3SpanIdFromHttpHeader = headers.getFirst("x-b3-spanid");
    String xB3ParentSpanIdFromHttpHeader = headers.getFirst("x-b3-parentspanid");
    String xB3SampledFromHttpHeader = headers.getFirst("x-b3-sampled");
    String xB3FlagsFromHttpHeader = headers.getFirst("x-b3-flags");
    String xOtSpanContextFromHttpHeader = headers.getFirst("x-ot-span-context");

    // create a custom gRPC header, they call it Metadata
    Metadata xRequestIdMetadata = new Metadata();
    Metadata xB3TraceIdMetadata = new Metadata();
    Metadata xB3SpanIdMetadata = new Metadata();
    Metadata xB3ParentSpanIdMetadata = new Metadata();
    Metadata xB3SampledMetadata = new Metadata();

    // TODO: refactor. putting to List<> and using foreach to attach this one.
    // assign value of the x-request-id Metadata to the value of the HTTP Header
    xRequestIdMetadata.put(Metadata.Key.of("x-request-id", Metadata.ASCII_STRING_MARSHALLER), xRequestIdFromHttpHeader);
    xB3TraceIdMetadata.put(Metadata.Key.of("x-b3-traceid", Metadata.ASCII_STRING_MARSHALLER), xB3TraceIdFromHttpHeader);
    xB3SpanIdMetadata.put(Metadata.Key.of("x-b3-spanid", Metadata.ASCII_STRING_MARSHALLER), xB3SpanIdFromHttpHeader);
    xB3ParentSpanIdMetadata.put(Metadata.Key.of("x-b3-parentspanid", Metadata.ASCII_STRING_MARSHALLER), xB3ParentSpanIdFromHttpHeader);
    xB3SampledMetadata.put(Metadata.Key.of("x-b3-sampled", Metadata.ASCII_STRING_MARSHALLER), xB3SampledFromHttpHeader);

    // TODO: refactor. putting to List<> and using foreach to attach this one.
    // use MetadataUtils to attach that new Metadata to our stub before requesting to our gRPC Server via gRPC
    greetingServiceStub = MetadataUtils.attachHeaders(greetingServiceStub, xRequestIdMetadata);
    greetingServiceStub = MetadataUtils.attachHeaders(greetingServiceStub, xB3TraceIdMetadata);
    greetingServiceStub = MetadataUtils.attachHeaders(greetingServiceStub, xB3SpanIdMetadata);
    greetingServiceStub = MetadataUtils.attachHeaders(greetingServiceStub, xB3ParentSpanIdMetadata);
    greetingServiceStub = MetadataUtils.attachHeaders(greetingServiceStub, xB3SampledMetadata);
}

Но, похоже, работа ..

...