OpenTelemetry

After completing this task, you will understand how to have your application participate in tracing with OpenTelemetry, regardless of the language, framework, or platform you use to build your application.

This task uses the Bookinfo sample as the example application and the OpenTelemetry Collector as the receiver of traces.

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

Deploy the OpenTelemetry Collector

  • Create a namespace for the OpenTelemetry Collector:

    1. $ kubectl create namespace observability
  • Deploy the OpenTelemetry Collector. You can use this example configuration as a starting point: otel.yaml

    Zip

    1. $ kubectl apply -f @samples/open-telemetry/otel.yaml@ -n observability

Installation

All tracing options can be configured globally via MeshConfig. To simplify configuration, it is recommended to create a single YAML file which you can pass to the istioctl install -f command.

Choosing the exporter

Istio can be configured to export OpenTelemetry Protocol (OTLP) traces via gRPC or HTTP. Only one exporter can be configured at a time (either gRPC or HTTP).

Exporting via gRPC

In this example, traces will be exported via OTLP/gRPC to the OpenTelemetry Collector. The example also enables the environment resource detector. The environment detector adds attributes from the environment variable OTEL_RESOURCE_ATTRIBUTES to the exported OpenTelemetry resource.

  1. $ cat <<EOF | istioctl install -y -f -
  2. apiVersion: install.istio.io/v1alpha1
  3. kind: IstioOperator
  4. spec:
  5. meshConfig:
  6. enableTracing: true
  7. extensionProviders:
  8. - name: otel-tracing
  9. opentelemetry:
  10. port: 4317
  11. service: opentelemetry-collector.observability.svc.cluster.local
  12. resource_detectors:
  13. environment: {}
  14. EOF

Exporting via HTTP

In this example, traces will be exported via OTLP/HTTP to the OpenTelemetry Collector. The example also enables the environment resource detector. The environment detector adds attributes from the environment variable OTEL_RESOURCE_ATTRIBUTES to the exported OpenTelemetry resource.

  1. $ cat <<EOF | istioctl install -y -f -
  2. apiVersion: install.istio.io/v1alpha1
  3. kind: IstioOperator
  4. spec:
  5. meshConfig:
  6. enableTracing: true
  7. extensionProviders:
  8. - name: otel-tracing
  9. opentelemetry:
  10. port: 4318
  11. service: opentelemetry-collector.observability.svc.cluster.local
  12. http:
  13. path: "/v1/traces"
  14. timeout: 5s
  15. headers:
  16. - name: "custom-header"
  17. value: "custom value"
  18. resource_detectors:
  19. environment: {}
  20. EOF

Enable tracing for mesh via Telemetry API

Enable tracing by applying the following configuration:

  1. $ kubectl apply -f - <<EOF
  2. apiVersion: telemetry.istio.io/v1alpha1
  3. kind: Telemetry
  4. metadata:
  5. name: otel-demo
  6. spec:
  7. tracing:
  8. - providers:
  9. - name: otel-tracing
  10. randomSamplingPercentage: 100
  11. customTags:
  12. "my-attribute":
  13. literal:
  14. value: "default-value"
  15. EOF

Deploy the Bookinfo Application

Deploy the Bookinfo sample application.

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. The OpenTelemetry Collector used in the example is configured to export traces to the console. If you used the example Collector config, you can verify traces are arriving by looking at the Collector logs. It should contain something like:

    1. Resource SchemaURL:
    2. Resource labels:
    3. -> service.name: STRING(productpage.default)
    4. ScopeSpans #0
    5. ScopeSpans SchemaURL:
    6. InstrumentationScope
    7. Span #0
    8. Trace ID : 79fb7b59c1c3a518750a5d6dad7cd2d1
    9. Parent ID : 0cf792b061f0ad51
    10. ID : 2dff26f3b4d6d20f
    11. Name : egress reviews:9080
    12. Kind : SPAN_KIND_CLIENT
    13. Start time : 2024-01-30 15:57:58.588041 +0000 UTC
    14. End time : 2024-01-30 15:57:59.451116 +0000 UTC
    15. Status code : STATUS_CODE_UNSET
    16. Status message :
    17. Attributes:
    18. -> node_id: STRING(sidecar~10.244.0.8~productpage-v1-564d4686f-t6s4m.default~default.svc.cluster.local)
    19. -> zone: STRING()
    20. -> guid:x-request-id: STRING(da543297-0dd6-998b-bd29-fdb184134c8c)
    21. -> http.url: STRING(http://reviews:9080/reviews/0)
    22. -> http.method: STRING(GET)
    23. -> downstream_cluster: STRING(-)
    24. -> user_agent: STRING(curl/7.74.0)
    25. -> http.protocol: STRING(HTTP/1.1)
    26. -> peer.address: STRING(10.244.0.8)
    27. -> request_size: STRING(0)
    28. -> response_size: STRING(441)
    29. -> component: STRING(proxy)
    30. -> upstream_cluster: STRING(outbound|9080||reviews.default.svc.cluster.local)
    31. -> upstream_cluster.name: STRING(outbound|9080||reviews.default.svc.cluster.local)
    32. -> http.status_code: STRING(200)
    33. -> response_flags: STRING(-)
    34. -> istio.namespace: STRING(default)
    35. -> istio.canonical_service: STRING(productpage)
    36. -> istio.mesh_id: STRING(cluster.local)
    37. -> istio.canonical_revision: STRING(v1)
    38. -> istio.cluster_id: STRING(Kubernetes)
    39. -> my-attribute: STRING(default-value)

Cleanup

  1. Remove the Telemetry resource:

    1. $ kubectl delete telemetry otel-demo
  2. Remove any istioctl processes that may still be running using control-C or:

    1. $ killall istioctl
  3. Uninstall the OpenTelemetry Collector:

    Zip

    1. $ kubectl delete -f @samples/open-telemetry/otel.yaml@ -n observability
    2. $ kubectl delete namespace observability
  4. If you are not planning to explore any follow-on tasks, refer to the Bookinfo cleanup instructions to shutdown the application.