Trace an AI Agent that Uses AI Model Hub with the Tracing Service
Overview
This tutorial demonstrates how to trace an AI agent that uses IONOS CLOUD AI Model Hub for inference and export its execution as distributed traces to the IONOS CLOUD Tracing Service (powered by Grafana Tempo). You will build a small Python agent that calls a large language model through the AI Model Hub OpenAI-compatible endpoint, instrument it with the OpenAI OpenTelemetry instrumentation (which emits gen_ai.* span attributes), and view the resulting spans, including the model, token usage, and latency, in Grafana.
This keeps both inference and observability inside IONOS CLOUD: the model runs on AI Model Hub, and the traces stay in your EU-hosted tracing pipeline.
Target audience
This tutorial benefits AI/ML engineers, application developers, and platform teams building LLM-powered applications who want visibility into agent behavior, latency, and cost. Readers benefit from basic familiarity with:
Python and virtual environments
LLM/OpenAI-compatible APIs
OpenTelemetry concepts (spans, exporters)
The IONOS CLOUD Console and API authentication
What you will learn
How to create a IONOS CLOUD tracing pipeline and retrieve its ingestion endpoint and key
How to instrument a Python LLM application with the OpenAI OpenTelemetry instrumentation.
How to export
gen_aitrace spans to your tracing pipeline over the OpenTelemetry Protocol (OTLP) using HTTP.How to call a model on AI Model Hub through its OpenAI-compatible endpoint.
How to explore GenAI traces (model, tokens, prompts, latency) in Grafana with TraceQL.
Before you begin
Ensure you have:
An active IONOS CLOUD account with the Access and manage Tracing privilege.
Access to IONOS CLOUD AI Model Hub with a model deployed and its OpenAI-compatible endpoint and API token.
An IONOS CLOUD API token to create the pipeline. To generate a token, see Token Manager.
Python 3.9 or later, and outbound
HTTPSaccess on port443.
Cost considerations
This tutorial creates billable resources: a IONOS CLOUD tracing pipeline (billed by trace data ingested and stored) and AI Model Hub inference usage (billed by token consumption).
Delete the pipeline after you finish, and review your AI Model Hub usage. For current rates, see the IONOS CLOUD price list (EUR).
Architecture
The diagram below shows the data flow:

The agent calls the model on AI Model Hub for inference. The OpenTelemetry instrumentation wraps each model call and produces a gen_ai span, capturing the model, token counts, and (optionally) prompts and responses. These spans are exported to your tracing pipeline and become searchable in Grafana.
Procedure
Create a tracing pipeline.
Create a pipeline configured for the otlp-http protocol:
The create response returns the pipeline id and the ingestion key (key). Save the key immediately: it is returned only once.
Important: Save the key immediately. The Tracing Service returns the ingestion key only once. Store it securely; if it is lost or exposed, rotate it through the Tracing Service API.
The create response does not include the ingestion endpoint. Retrieve the ingestion endpoint (https://<tracing-host>/v1/traces) and the grafanaEndpoint with a follow-up GET request, using the pipeline id:
Set up the Python environment.
Create a virtual environment and install the dependencies:
Provide the secrets as environment variables. Do not store credentials directly in the script:
Important: Handle tokens like passwords. The AI Model Hub token is a IONOS CLOUD credential. Do not paste it into files, chats, tickets, or version control. If exposed, revoke it immediately in the Token Manager and rotate the tracing pipeline key.
Write the instrumented agent.
Create agent_trace.py. Replace the endpoint hosts and model id with your values.
Run the agent.
The script prints the model's reply and exports the spans. A macOS LibreSSL/urllib3 warning, if shown, is harmless.
View GenAI traces in Grafana.
Open Grafana using the grafanaEndpoint you retrieved, open Explore, and select the Tracing (Tempo) data source. Query for GenAI spans with TraceQL:
Open the agent-run trace and expand the child openai.chat span. The trace shows GenAI attributes such as gen_ai.system, gen_ai.request.model, gen_ai.response.model, gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, and the prompt or the completion content when recording is activated.

Result: Your AI agent runs now appear as GenAI traces in Grafana. The agent-run trace contains the openai.chat span with gen_ai.* attributes for the model, token usage, latency, and (when recording is activated) the prompt and response content.
Troubleshooting
No
gen_aispans: Confirm the pipeline isAVAILABLE,IONOS_TRACING_APIKEYis set, andTRACES_ENDPOINTuses the full.../v1/tracespath.provider.shutdown()must run so buffered spans are flushed before the process exits.Authentication errors (
401) on ingestion: Theapikeyheader value must match the current pipeline key.Model call fails: Verify the AI Model Hub base URL ends in
/v1, the token is valid, and the model id is available on your hub.Doubled endpoint path: If you switch to the
OTEL_EXPORTER_OTLP_ENDPOINTbase environment variable instead of the explicitendpoint=, drop the/v1/tracessuffix; the exporter appends it.
Decommission resources
Delete the tracing pipeline through the API to stop billing, using the pipeline id from the creation response:
Then review your AI Model Hub usage.
Next steps
Last updated
Was this helpful?