OpenCensus Agent

After completing this task, you will understand how to have your application participate in tracing with the OpenCensus Agent, export those traces to the OpenTelemetry collector, and have the OpenTelemetry collector export those spans to Jaeger.

To learn how Istio handles tracing, visit this task’s overview.

Before you begin

  • Setup Istio by following the instructions in the Installation guide.

    The egress gateway and access logging will be enabled if you install the demo configuration profile.

  • Deploy the sleep sample app to use as a test source for sending requests. If you have automatic sidecar injection enabled, run the following command to deploy the sample app:

    Zip

    1. $ kubectl apply -f @samples/sleep/sleep.yaml@

    Otherwise, manually inject the sidecar before deploying the sleep application with the following command:

    Zip

    1. $ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)

    You can use any pod with curl installed as a test source.

  • Set the SOURCE_POD environment variable to the name of your source pod:

    1. $ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
  • Install Jaeger into your cluster.

  • Deploy the Bookinfo sample application.

Configure tracing

If you used an IstioOperator CR to install Istio, add the following field to your configuration:

  1. apiVersion: install.istio.io/v1alpha1
  2. kind: IstioOperator
  3. spec:
  4. meshConfig:
  5. defaultProviders:
  6. tracing:
  7. - "opencensus"
  8. enableTracing: true
  9. extensionProviders:
  10. - name: "opencensus"
  11. opencensus:
  12. service: "opentelemetry-collector.istio-system.svc.cluster.local"
  13. port: 55678
  14. context:
  15. - W3C_TRACE_CONTEXT

With this configuration Istio is installed with OpenCensus Agent as the default tracer. Trace data will be sent to an OpenTelemetry backend.

By default, Istio’s OpenCensus Agent tracing will attempt to read and write 4 types of trace headers:

If you supply multiple values, the proxy will attempt to read trace headers in the specified order, using the first one that successfully parsed and writing all headers. This permits interoperability between services that use different headers, e.g. one service that propagates B3 headers and one that propagates W3C Trace Context headers can participate in the same trace. In this example we only use W3C Trace Context.

In the default profile the sampling rate is 1%. Increase it to 100% using the Telemetry API:

  1. $ kubectl apply -f - <<EOF
  2. apiVersion: telemetry.istio.io/v1alpha1
  3. kind: Telemetry
  4. metadata:
  5. name: mesh-default
  6. namespace: istio-system
  7. spec:
  8. tracing:
  9. - randomSamplingPercentage: 100.00
  10. EOF

Deploy OpenTelemetry Collector

OpenTelemetry collector supports exporting traces to several backends by default in the core distribution. Other backends are available in the contrib distribution of OpenTelemetry collector.

Deploy and configure the collector to receive and export spans to the Jaeger instance:

  1. $ kubectl apply -f - <<EOF
  2. apiVersion: v1
  3. kind: ConfigMap
  4. metadata:
  5. name: opentelemetry-collector
  6. namespace: istio-system
  7. labels:
  8. app: opentelemetry-collector
  9. data:
  10. config: |
  11. receivers:
  12. opencensus:
  13. endpoint: 0.0.0.0:55678
  14. processors:
  15. memory_limiter:
  16. limit_mib: 100
  17. spike_limit_mib: 10
  18. check_interval: 5s
  19. exporters:
  20. zipkin:
  21. # Export via zipkin for easy querying
  22. endpoint: http://zipkin.istio-system.svc:9411/api/v2/spans
  23. logging:
  24. loglevel: debug
  25. extensions:
  26. health_check:
  27. port: 13133
  28. service:
  29. extensions:
  30. - health_check
  31. pipelines:
  32. traces:
  33. receivers:
  34. - opencensus
  35. processors:
  36. - memory_limiter
  37. exporters:
  38. - zipkin
  39. - logging
  40. ---
  41. apiVersion: v1
  42. kind: Service
  43. metadata:
  44. name: opentelemetry-collector
  45. namespace: istio-system
  46. labels:
  47. app: opentelemetry-collector
  48. spec:
  49. type: ClusterIP
  50. selector:
  51. app: opentelemetry-collector
  52. ports:
  53. - name: grpc-opencensus
  54. port: 55678
  55. protocol: TCP
  56. targetPort: 55678
  57. ---
  58. apiVersion: apps/v1
  59. kind: Deployment
  60. metadata:
  61. name: opentelemetry-collector
  62. namespace: istio-system
  63. labels:
  64. app: opentelemetry-collector
  65. spec:
  66. replicas: 1
  67. selector:
  68. matchLabels:
  69. app: opentelemetry-collector
  70. template:
  71. metadata:
  72. labels:
  73. app: opentelemetry-collector
  74. spec:
  75. containers:
  76. - name: opentelemetry-collector
  77. image: "otel/opentelemetry-collector:0.49.0"
  78. imagePullPolicy: IfNotPresent
  79. command:
  80. - "/otelcol"
  81. - "--config=/conf/config.yaml"
  82. ports:
  83. - name: grpc-opencensus
  84. containerPort: 55678
  85. protocol: TCP
  86. volumeMounts:
  87. - name: opentelemetry-collector-config
  88. mountPath: /conf
  89. readinessProbe:
  90. httpGet:
  91. path: /
  92. port: 13133
  93. resources:
  94. requests:
  95. cpu: 40m
  96. memory: 100Mi
  97. volumes:
  98. - name: opentelemetry-collector-config
  99. configMap:
  100. name: opentelemetry-collector
  101. items:
  102. - key: config
  103. path: config.yaml
  104. EOF

Access the dashboard

Remotely Accessing Telemetry Addons details how to configure access to the Istio addons through a gateway.

For testing (and temporary access), you may also use port-forwarding. Use the following, assuming you’ve deployed Jaeger to the istio-system namespace:

  1. $ istioctl dashboard jaeger

Generating traces using the Bookinfo sample

  1. When the Bookinfo application is up and running, access http://$GATEWAY_URL/productpage one or more times to generate trace information.

    To see trace data, you must send requests to your service. The number of requests depends on Istio’s sampling rate and can be configured using the Telemetry API. With the default sampling rate of 1%, you need to send at least 100 requests before the first trace is visible. To send a 100 requests to the productpage service, use the following command:

    1. $ for i in $(seq 1 100); do curl -s -o /dev/null "http://$GATEWAY_URL/productpage"; done
  2. From the left-hand pane of the dashboard, select productpage.default from the Service drop-down list and click Find Traces:

    Tracing Dashboard

    Tracing Dashboard

  3. Click on the most recent trace at the top to see the details corresponding to the latest request to /productpage:

    Detailed Trace View

    Detailed Trace View

  4. The trace is comprised of a set of spans, where each span corresponds to a Bookinfo service, invoked during the execution of a /productpage request, or internal Istio component, for example: istio-ingressgateway.

As you also configured logging exporter in OpenTelemetry Collector, you can see traces in the logs as well:

  1. $ kubectl -n istio-system logs deploy/opentelemetry-collector

Cleanup

  1. Remove any istioctl processes that may still be running using control-C or:

    1. $ killall istioctl
  2. If you are not planning to explore any follow-on tasks, refer to the Bookinfo cleanup instructions to shutdown the application.

  3. Remove the Jaeger addon:

    1. $ kubectl delete -f https://raw.githubusercontent.com/istio/istio/release-1.22/samples/addons/jaeger.yaml
  4. Remove the OpenTelemetry Collector:

    1. $ kubectl delete -n istio-system cm opentelemetry-collector
    2. $ kubectl delete -n istio-system svc opentelemetry-collector
    3. $ kubectl delete -n istio-system deploy opentelemetry-collector
  5. Remove, or set to "", the meshConfig.extensionProviders and meshConfig.defaultProviders setting in your Istio install configuration.

  6. Remove the telemetry resource:

    1. $ kubectl delete telemetries.telemetry.istio.io -n istio-system mesh-default