Istio provides some additional configuration options that you may find useful to fine-tune your telemetry data. These include options to set the service name reported with the telemetry data and the ability to add custom attributes to the span data.
The default configuration for Istio sets the service name on the telemetry data to APP_LABEL_AND_NAMESPACE
. If there is no app
label on the workload it will use istio-proxy
instead. The two value are concatenated with a period (ex. my-app.my-namespace). If this is not your preferred naming scheme, Istio provides the following options for you to choose from:
Value | Description |
---|---|
APP_LABEL_AND_NAMESPACE |
Default. Uses the app label and workload namespace to construct the service name. If the app label does not exist istio-proxy is used. |
CANONICAL_NAME_ONLY |
Uses the canonical name for the workload without the namespace |
CANONICAL_NAME_AND_NAMESPACE |
Uses the canonical name with the namespace |
This setting is managed in the defaultConfig
section of the mesh
config in the Istio ConfigMap
. Here is an example:
apiVersion: v1
kind: ConfigMap
metadata:
name: istio
namespace: istio-system
annotations:
meta.helm.sh/release-name: istiod
meta.helm.sh/release-namespace: istio-system
labels:
app.kubernetes.io/managed-by: Helm
install.operator.istio.io/owning-resource: unknown
istio.io/rev: default
operator.istio.io/component: Pilot
release: istiod
data:
meshNetworks: |-
networks: {}
mesh: |-
defaultConfig:
discoveryAddress: istiod.istio-system.svc:15012
# use only the canonical name to generate the services names
tracingServiceName: CANONICAL_NAME_ONLY
defaultProviders:
tracing:
- opentelemetry
extensionProviders:
- name: "opentelemetry"
opentelemetry:
service: "opentelemetry-collector.istio-system.svc.cluster.local"
port: 4317
enablePrometheusMerge: true
rootNamespace: null
trustDomain: cluster.local
After updating this configuration, apply the changes to your cluster:
kubectl apply -f istio-telemetry.yaml -n istio-system
Don’t forget to restart your workloads so the changes get applied to the sidecars.
Once you have restarted your workloads, load or refresh the Bookinfo product page again and review the traces in Cloud Observability. You should see the service names have been updated like so:
You can configure Istio telemetry to add tags/attributes to the spans that are generated by the sidecar proxies. This is helpful when you want to add additional context to the spans in order to better understand that state of the requests and/or support specific queries. You have three options to set the value for these attributes: get the value from an environment variable, extract the value from the request headers or hard code the value.
You can configure these attributes by modifying the Telemetry
resource that you created in the Configure Istio Telemetry section above. Here is an example with comments:
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: mesh-default
namespace: istio-system
spec:
accessLogging:
- providers:
- name: opentelemetry
metrics:
- providers:
- name: opentelemetry
tracing:
- providers:
- name: opentelemetry
# This section defines the custom attributes that will be
# added to the spans generated by the Istio sidecars
customTags:
my-attr.hard-coded: # this value will be the attribute key
literal: # use "literal" when hard coding the attribute value
value: "this is the value of my hard coded custom attribute"
my-attr.from-env-var: # this value will be the attribute key
environment: # use "environment" when getting the attribute value from an environment variable
name: my-env-var # the name of the environment variable to get the value from
defaultValue: "this is the default value" # default value to use when the environment variable is not found
my-attr.from-header: # this value will be the attribute key
header: # use "header" when getting the attribute value from the request headers
name: my-header # the name of the header to get the value from
defaultValue: "this is the default value" # default value to use when the header is not found
randomSamplingPercentage: 100
Once you have these configured deploy the changes to your cluster:
kubectl apply -f istio-telemetry.yaml -n istio-system
Again, don’t forget to restart your workloads so the changes get applied to the sidecars.
After you restart your workloads, load or refresh the Bookinfo product page again and review the traces in Cloud Observability. Notice the custom attributes now appear on your spans.
And that brings us to the end of this workshop. Before wrapping it up, let’s recap what you completed and discuss some next steps to further enhance observability with Istio.
next: Conclusion