• Overview
    • Trace context propagation
    • Trace sampling
    • 相关内容

    Overview

    Distributed tracing enables users to track a request through mesh that is distributed across multiple services.This allows a deeper understanding about request latency, serialization and parallelism via visualization.

    Istio leverages Envoy’s distributed tracing featureto provide tracing integration out of the box. Specifically, Istio provides options to install various tracing backendand configure proxies to send trace spans to them automatically.See Zipkin, Jaeger and LightStep task docs about how Istio works with those tracing systems.

    Trace context propagation

    Although Istio proxies are able to automatically send spans, they need some hints to tie together the entire trace.Applications need to propagate the appropriate HTTP headers so that when the proxies send span information,the spans can be correlated correctly into a single trace.

    To do this, an application needs to collect and propagate the following headers from the incoming request to any outgoing requests:

    • x-request-id
    • x-b3-traceid
    • x-b3-spanid
    • x-b3-parentspanid
    • x-b3-sampled
    • x-b3-flags
    • x-ot-span-contextIf you look at the sample Python productpage service, for example,you see that the application extracts the required headers from an HTTP requestusing OpenTracing libraries:
    1. def getForwardHeaders(request):
    2. headers = {}
    3. # x-b3-*** headers can be populated using the opentracing span
    4. span = get_current_span()
    5. carrier = {}
    6. tracer.inject(
    7. span_context=span.context,
    8. format=Format.HTTP_HEADERS,
    9. carrier=carrier)
    10. headers.update(carrier)
    11. # ...
    12. incoming_headers = ['x-request-id']
    13. # ...
    14. for ihdr in incoming_headers:
    15. val = request.headers.get(ihdr)
    16. if val is not None:
    17. headers[ihdr] = val
    18. return headers

    The reviews application (Java) does something similar:

    1. @GET
    2. @Path("/reviews/{productId}")
    3. public Response bookReviewsById(@PathParam("productId") int productId,
    4. @HeaderParam("end-user") String user,
    5. @HeaderParam("x-request-id") String xreq,
    6. @HeaderParam("x-b3-traceid") String xtraceid,
    7. @HeaderParam("x-b3-spanid") String xspanid,
    8. @HeaderParam("x-b3-parentspanid") String xparentspanid,
    9. @HeaderParam("x-b3-sampled") String xsampled,
    10. @HeaderParam("x-b3-flags") String xflags,
    11. @HeaderParam("x-ot-span-context") String xotspan) {
    12. if (ratings_enabled) {
    13. JsonObject ratingsResponse = getRatings(Integer.toString(productId), user, xreq, xtraceid, xspanid, xparentspanid, xsampled, xflags, xotspan);

    When you make downstream calls in your applications, make sure to include these headers.

    Trace sampling

    Istio captures a trace for all requests by default when installing with the demo profile.For example, when using the Bookinfo sample application above, every time you access/productpage you see a corresponding trace in thedashboard. This sampling rate is suitable for a test or low trafficmesh. For a high traffic mesh you can lower the trace samplingpercentage in one of two ways:

    • During the mesh setup, use the option values.pilot.traceSampling toset the percentage of trace sampling. See theInstalling with istioctl documentation fordetails on setting options.
    • In a running mesh, edit the istio-pilot deployment andchange the environment variable with the following steps:

      • To open your text editor with the deployment configuration fileloaded, run the following command:
    1. $ kubectl -n istio-system edit deploy istio-pilot
    • Find the PILOT_TRACE_SAMPLING environment variable, and changethe value: to your desired percentage.

    In both cases, valid values are from 0.0 to 100.0 with a precision of 0.01.

    相关内容

    Jaeger

    了解如何配置代理以向 Jaeger 发送追踪请求。

    LightStep

    How to configure the proxies to send tracing requests to LightStep.

    Remotely Accessing Telemetry Addons

    This task shows you how to configure external access to the set of Istio telemetry addons.

    Zipkin

    Learn how to configure the proxies to send tracing requests to Zipkin.

    Mixer and the SPOF Myth

    Improving availability and reducing latency.

    Mixer Adapter Model

    Provides an overview of Mixer's plug-in architecture.