mirror of https://github.com/istio/istio.io.git
Add OpenTelemetry tracing example (#14566)
* Add OpenTelemetry tracing task * Add tests * Use consistent casing for "collector" * Fix lint * remove tests for now * Re-add tests * Fix indentation * Better test file names * Use demo profile and re-use collector deployment function * Fix cleanup wrong code * Use demo profile on both tests * Update test reference to HTTP exporter commit in Istio * make gen * Remove HTTP example * Revert Istio update * Add boilerplate for collector on its own namespace * Adapt collector namespace * Fix function call * Create the observability namespace * Add missing import * Add boiler plate for book info trace generation * Remove zipkin and Jaeger things * Fix clean up, properly uninstall Istio and collector * Not remove istio-system namespace during cleanup * Re-use collector deploy boilerplate * Fix snippet meshconfig file name * Remove indentation * PR suggestions
This commit is contained in:
parent
96aa94af57
commit
5c54913765
|
@ -0,0 +1,159 @@
|
|||
---
|
||||
title: OpenTelemetry
|
||||
description: Learn how to configure the proxies to send OpenTelemetry traces to a Collector.
|
||||
weight: 10
|
||||
keywords: [telemetry,tracing,opentelemetry,span,port-forwarding]
|
||||
aliases:
|
||||
- /docs/tasks/telemetry/distributed-tracing/opentelemetry/
|
||||
owner: istio/wg-policies-and-telemetry-maintainers
|
||||
test: yes
|
||||
---
|
||||
|
||||
After completing this task, you will understand how to have your application participate in tracing with [OpenTelemetry](https://www.opentelemetry.io/), regardless of the language, framework, or platform you use to build your application.
|
||||
|
||||
This task uses the [Bookinfo](/docs/examples/bookinfo/) sample as the example application and the
|
||||
[OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) as the receiver of traces.
|
||||
|
||||
To learn how Istio handles tracing, visit this task's [overview](../overview/).
|
||||
|
||||
Istio can be configured to export [OpenTelemetry Protocol (OTLP)](https://opentelemetry.io/docs/specs/otel/protocol/)
|
||||
traces via gRPC.
|
||||
|
||||
## Deploy the OpenTelemetry Collector
|
||||
|
||||
{{< boilerplate start-otel-collector-service >}}
|
||||
|
||||
## 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.
|
||||
|
||||
### 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](https://opentelemetry.io/docs/languages/js/resources/#adding-resources-with-environment-variables). The environment detector adds attributes from the environment variable
|
||||
`OTEL_RESOURCE_ATTRIBUTES` to the exported OpenTelemetry resource.
|
||||
|
||||
{{< text syntax=bash snip_id=none >}}
|
||||
$ cat <<EOF > ./tracing-grpc.yaml
|
||||
apiVersion: install.istio.io/v1alpha1
|
||||
kind: IstioOperator
|
||||
spec:
|
||||
meshConfig:
|
||||
enableTracing: true
|
||||
extensionProviders:
|
||||
- name: otel-tracing
|
||||
opentelemetry:
|
||||
port: 4317
|
||||
service: opentelemetry-collector.observability.svc.cluster.local
|
||||
resource_detectors:
|
||||
environment: {}
|
||||
EOF
|
||||
$ istioctl install -f ./tracing-grpc.yaml --skip-confirmation
|
||||
$ kubectl label namespace default istio-injection=enabled
|
||||
{{< /text >}}
|
||||
|
||||
## Enable tracing for mesh via Telemetry API
|
||||
|
||||
Enable tracing by applying the following configuration:
|
||||
|
||||
{{< text syntax=bash snip_id=enable_telemetry >}}
|
||||
$ kubectl apply -f - <<EOF
|
||||
apiVersion: telemetry.istio.io/v1alpha1
|
||||
kind: Telemetry
|
||||
metadata:
|
||||
name: otel-demo
|
||||
spec:
|
||||
tracing:
|
||||
- providers:
|
||||
- name: otel-tracing
|
||||
randomSamplingPercentage: 100
|
||||
customTags:
|
||||
"my-attribute":
|
||||
literal:
|
||||
value: "default-value"
|
||||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
## Deploy the Bookinfo Application
|
||||
|
||||
Deploy the [Bookinfo](/docs/examples/bookinfo/#deploying-the-application) 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.
|
||||
|
||||
{{< boilerplate trace-generation >}}
|
||||
|
||||
1. 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:
|
||||
|
||||
{{< text syntax=yaml snip_id=none >}}
|
||||
Resource SchemaURL:
|
||||
Resource labels:
|
||||
-> service.name: STRING(productpage.default)
|
||||
ScopeSpans #0
|
||||
ScopeSpans SchemaURL:
|
||||
InstrumentationScope
|
||||
Span #0
|
||||
Trace ID : 79fb7b59c1c3a518750a5d6dad7cd2d1
|
||||
Parent ID : 0cf792b061f0ad51
|
||||
ID : 2dff26f3b4d6d20f
|
||||
Name : egress reviews:9080
|
||||
Kind : SPAN_KIND_CLIENT
|
||||
Start time : 2024-01-30 15:57:58.588041 +0000 UTC
|
||||
End time : 2024-01-30 15:57:59.451116 +0000 UTC
|
||||
Status code : STATUS_CODE_UNSET
|
||||
Status message :
|
||||
Attributes:
|
||||
-> node_id: STRING(sidecar~10.244.0.8~productpage-v1-564d4686f-t6s4m.default~default.svc.cluster.local)
|
||||
-> zone: STRING()
|
||||
-> guid:x-request-id: STRING(da543297-0dd6-998b-bd29-fdb184134c8c)
|
||||
-> http.url: STRING(http://reviews:9080/reviews/0)
|
||||
-> http.method: STRING(GET)
|
||||
-> downstream_cluster: STRING(-)
|
||||
-> user_agent: STRING(curl/7.74.0)
|
||||
-> http.protocol: STRING(HTTP/1.1)
|
||||
-> peer.address: STRING(10.244.0.8)
|
||||
-> request_size: STRING(0)
|
||||
-> response_size: STRING(441)
|
||||
-> component: STRING(proxy)
|
||||
-> upstream_cluster: STRING(outbound|9080||reviews.default.svc.cluster.local)
|
||||
-> upstream_cluster.name: STRING(outbound|9080||reviews.default.svc.cluster.local)
|
||||
-> http.status_code: STRING(200)
|
||||
-> response_flags: STRING(-)
|
||||
-> istio.namespace: STRING(default)
|
||||
-> istio.canonical_service: STRING(productpage)
|
||||
-> istio.mesh_id: STRING(cluster.local)
|
||||
-> istio.canonical_revision: STRING(v1)
|
||||
-> istio.cluster_id: STRING(Kubernetes)
|
||||
-> my-attribute: STRING(default-value)
|
||||
{{< /text >}}
|
||||
|
||||
## Cleanup
|
||||
|
||||
1. Remove the Telemetry resource:
|
||||
|
||||
{{< text syntax=bash snip_id=cleanup_telemetry >}}
|
||||
$ kubectl delete telemetry otel-demo
|
||||
{{< /text >}}
|
||||
|
||||
1. Remove any `istioctl` processes that may still be running using control-C or:
|
||||
|
||||
{{< text syntax=bash snip_id=none >}}
|
||||
$ killall istioctl
|
||||
{{< /text >}}
|
||||
|
||||
1. Uninstall the OpenTelemetry Collector:
|
||||
|
||||
{{< text syntax=bash snip_id=cleanup_collector >}}
|
||||
$ kubectl delete -f @samples/open-telemetry/otel.yaml@ -n observability
|
||||
$ kubectl delete namespace observability
|
||||
{{< /text >}}
|
||||
|
||||
1. If you are not planning to explore any follow-on tasks, refer to the
|
||||
[Bookinfo cleanup](/docs/examples/bookinfo/#cleanup) instructions
|
||||
to shutdown the application.
|
|
@ -0,0 +1,50 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC2034,SC2153,SC2155,SC2164
|
||||
|
||||
# Copyright Istio Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
####################################################################################################
|
||||
# WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE:
|
||||
# docs/tasks/observability/distributed-tracing/opentelemetry/index.md
|
||||
####################################################################################################
|
||||
source "content/en/boilerplates/snips/start-otel-collector-service.sh"
|
||||
source "content/en/boilerplates/snips/trace-generation.sh"
|
||||
|
||||
snip_enable_telemetry() {
|
||||
kubectl apply -f - <<EOF
|
||||
apiVersion: telemetry.istio.io/v1alpha1
|
||||
kind: Telemetry
|
||||
metadata:
|
||||
name: otel-demo
|
||||
spec:
|
||||
tracing:
|
||||
- providers:
|
||||
- name: otel-tracing
|
||||
randomSamplingPercentage: 100
|
||||
customTags:
|
||||
"my-attribute":
|
||||
literal:
|
||||
value: "default-value"
|
||||
EOF
|
||||
}
|
||||
|
||||
snip_cleanup_telemetry() {
|
||||
kubectl delete telemetry otel-demo
|
||||
}
|
||||
|
||||
snip_cleanup_collector() {
|
||||
kubectl delete -f samples/open-telemetry/otel.yaml -n observability
|
||||
kubectl delete namespace observability
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090,SC2154,SC2155,SC2034,SC2016
|
||||
|
||||
# Copyright Istio Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -e
|
||||
set -u
|
||||
set -o pipefail
|
||||
|
||||
source "tests/util/samples.sh"
|
||||
source "tests/util/addons.sh"
|
||||
|
||||
# @setup profile=demo
|
||||
|
||||
# Deploy the OTel collector
|
||||
bpsnip_start_otel_collector_service__1
|
||||
bpsnip_start_otel_collector_service__2
|
||||
_wait_for_deployment observability opentelemetry-collector
|
||||
|
||||
# Enable OTel Tracing extension via Telememetry API
|
||||
snip_enable_telemetry
|
||||
|
||||
# Install Bookinfo application
|
||||
startup_bookinfo_sample
|
||||
|
||||
_set_ingress_environment_variables
|
||||
GATEWAY_URL="$INGRESS_HOST:$INGRESS_PORT"
|
||||
bpsnip_trace_generation__1
|
||||
|
||||
# @cleanup
|
||||
cleanup_bookinfo_sample
|
||||
snip_cleanup_telemetry
|
||||
snip_cleanup_collector
|
Loading…
Reference in New Issue