Modern applications are increasingly built using microservices architectures, often deployed on Kubernetes. AI agents and applications are usually bundle into one or more of these microservices. This distributed nature introduces complexity in monitoring, troubleshooting, and optimizing performance across multiple interconnected services. Dynatrace simplifies this challenge by providing comprehensive end-to-end observability for applications running on Kubernetes.
In this tutorial, we will
We'll use OpenTelemetry with OpenInference as the primary mechanism to emit GenAI specific telemetry data (spans/metrics such as models, tokens, latencies, and costs) into Dynatrace.
OneAgent complements this by delivering full-stack Kubernetes and application context (infrastructure health, workload/process detection, logs, code-level visibility, vulnerability) and by correlating OTEL traces with services, problems, and Dynatrace Intelligence insights.
For production workloads, route your GenAI telemetry through an OpenTelemetry Collector. The collector provides sampling features that help controlling the cost for OpenTelemetry data.
values.yamlmode: deploymentimage:repository: ghcr.io/dynatrace/dynatrace-otel-collector/dynatrace-otel-collectortag: 0.33.0command:name: dynatrace-otel-collectorextraEnvs:- name: DT_API_TOKENvalueFrom:secretKeyRef:name: dynatrace-otelcol-dt-api-credentialskey: DT_API_TOKEN- name: DT_ENDPOINTvalueFrom:secretKeyRef:name: dynatrace-otelcol-dt-api-credentialskey: DT_ENDPOINTresources:limits:memory: 512MialternateConfig:extensions:health_check:endpoint: "${env:MY_POD_IP}:13133"processors:cumulative_to_delta:max_staleness: 25hk8sattributes:extract:metadata:- k8s.pod.name- k8s.pod.uid- k8s.pod.ip- k8s.deployment.name- k8s.replicaset.name- k8s.statefulset.name- k8s.daemonset.name- k8s.job.name- k8s.cronjob.name- k8s.namespace.name- k8s.node.name- k8s.cluster.uid- k8s.container.nameannotations:- from: podkey_regex: metadata.dynatrace.com/(.*)tag_name: $$1- from: podkey: metadata.dynatrace.comtag_name: metadata.dynatrace.compod_association:- sources:- from: resource_attributename: k8s.pod.name- from: resource_attributename: k8s.namespace.name- sources:- from: resource_attributename: k8s.pod.ip- sources:- from: resource_attributename: k8s.pod.uid- sources:- from: connectiontransform:error_mode: ignoretrace_statements: &dynatrace_transformations# Set attributes taken from k8s metadata.- context: resourcestatements:- set(attributes["k8s.workload.kind"], "job") where IsString(attributes["k8s.job.name"])- set(attributes["k8s.workload.name"], attributes["k8s.job.name"]) where IsString(attributes["k8s.job.name"])- set(attributes["k8s.workload.kind"], "cronjob") where IsString(attributes["k8s.cronjob.name"])- set(attributes["k8s.workload.name"], attributes["k8s.cronjob.name"]) where IsString(attributes["k8s.cronjob.name"])- set(attributes["k8s.workload.kind"], "daemonset") where IsString(attributes["k8s.daemonset.name"])- set(attributes["k8s.workload.name"], attributes["k8s.daemonset.name"]) where IsString(attributes["k8s.daemonset.name"])- set(attributes["k8s.workload.kind"], "statefulset") where IsString(attributes["k8s.statefulset.name"])- set(attributes["k8s.workload.name"], attributes["k8s.statefulset.name"]) where IsString(attributes["k8s.statefulset.name"])- set(attributes["k8s.workload.kind"], "replicaset") where IsString(attributes["k8s.replicaset.name"])- set(attributes["k8s.workload.name"], attributes["k8s.replicaset.name"]) where IsString(attributes["k8s.replicaset.name"])- set(attributes["k8s.workload.kind"], "deployment") where IsString(attributes["k8s.deployment.name"])- set(attributes["k8s.workload.name"], attributes["k8s.deployment.name"]) where IsString(attributes["k8s.deployment.name"])# remove the delete statements if you want to preserve these attributes- delete_key(attributes, "k8s.deployment.name")- delete_key(attributes, "k8s.replicaset.name")- delete_key(attributes, "k8s.statefulset.name")- delete_key(attributes, "k8s.daemonset.name")- delete_key(attributes, "k8s.cronjob.name")- delete_key(attributes, "k8s.job.name")# Set attributes from metadata specified in Dynatrace and set through the Dynatrace Operator.# For more info: https://docs.dynatrace.com/docs/shortlink/k8s-metadata-telemetry-enrichment- context: resourcestatements:- merge_maps(attributes, ParseJSON(attributes["metadata.dynatrace.com"]), "upsert") where IsMatch(attributes["metadata.dynatrace.com"], "^\\{")- delete_key(attributes, "metadata.dynatrace.com")metric_statements: *dynatrace_transformationslog_statements: *dynatrace_transformationsreceivers:otlp:protocols:grpc:endpoint: ${env:MY_POD_IP}:4317http:endpoint: ${env:MY_POD_IP}:4318file_log: nullexporters:otlp_http:endpoint: "${env:DT_ENDPOINT}"headers:Authorization: "Api-Token ${env:DT_API_TOKEN}"service:extensions: [health_check]pipelines:traces:receivers: [otlp]processors: [k8sattributes, transform]exporters: [otlp_http]metrics:receivers: [otlp]processors: [k8sattributes, transform, cumulative_to_delta]exporters: [otlp_http]logs:receivers: [otlp]processors: [k8sattributes, transform]exporters: [otlp_http]
We recommend setting the max_staleness parameter of the cumulative_to_delta processor to a value higher than how often the Collector receives metrics (for example, how often metrics via OTLP are received, or how long the Prometheus scrape interval is). This ensures that no references to abandoned metric streams accumulate in memory over time.
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-chartshelm repo updatehelm upgrade -i dynatrace-collector open-telemetry/opentelemetry-collector -f values.yaml
Create a Dynatrace token so the OpenTelemetry Collector can report data to your Dynatrace tenant, see Platform tokens. The token needs to have the following scopes:
metrics.ingest)logs.ingest)openTelemetryTrace.ingest)Instrument your application with OpenInference and export spans to the collector you deployed in the previous step.
Install the OpenInference instrumentor for your provider or framework and the OpenTelemetry SDK. This example uses OpenAI.
pip install openinference-instrumentation-openai opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
Initialize the tracer. Add the following code at the beginning of your main file.
import osfrom openinference.instrumentation.openai import OpenAIInstrumentorfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporterfrom opentelemetry.sdk.resources import Resource, SERVICE_NAMEfrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import BatchSpanProcessoros.environ.setdefault("OPENINFERENCE_ENABLE_GENAI_SEMCONV", "true")tracer_provider = TracerProvider(resource=Resource.create({SERVICE_NAME: "<your-service>"}))exporter = OTLPSpanExporter(endpoint="http://<COLLECTOR_SERVICE>:4318/v1/traces",)tracer_provider.add_span_processor(BatchSpanProcessor(exporter))OpenAIInstrumentor().instrument(tracer_provider=tracer_provider)
Replace the placeholders with relevant values:
<COLLECTOR_SERVICE>: The Kubernetes service name of the collector that you deployed, for example dynatrace-collector-opentelemetry-collector.<your-service>: Your app's name.For other providers and frameworks, swap the instrumentor and follow the matching OpenInference sample.
OpenInference emits spans only. To get GenAI metrics and normalized gen_ai.* attributes, see Normalize your OpenInference attributes.
The combination of OneAgent and OpenTelemetry-based instrumentation empowers end-to-end tracing across services. OpenTelemetry instrumentation emits GenAI spans and metrics (for example, model, token usage, latency, cost) based on the OpenTelemetry semantic conventions for GenAI. For more information, see Semantic Conventions for GenAI agent and framework spans.
There are multiple ways you can leverage GenAI spans and metrics.
In Distributed Tracing, it is possible to inspect the GenAI requests.
On the right-hand side, GenAI attributes are available for the relevant GenAI spans, providing detailed insights into key metrics.
These attributes help developers and operators better understand the performance and behavior of GenAI components, enabling more effective monitoring and optimization of AI-powered services.

Furthermore, advanced features like Application Security are now available.
In
Kubernetes, you can directly see if your AI agents or services have any active vulnerabilities.

In the
Kubernetes > Deployments > Workload > Additional Telemetry tab, additional metrics are also displayed for the monitored service, which enable you to discover new AI signals to help you better understand your workloads.
You can also add the displayed metrics directly in
Dashboards without the need to manually create DQL queries.
To do this, select >
Pin to dashboard.
