Prerequisites
- A Cloudflare AI Gateway. Create one in the Cloudflare dashboard under AI → AI Gateway.
- A running Phoenix instance (see Launch Phoenix). To export gateway spans, Cloudflare must be able to reach your Phoenix collector.
- Python 3.10+ (only to instrument your application).
Launch Phoenix
- Local
- Container
- Self-Host
pip install arize-phoenix && phoenix serve does the same thing. See Terminal setup for customization.To export gateway spans, AI Gateway sends them from Cloudflare’s edge, so Cloudflare must be able
to reach your Phoenix collector. A deployed Phoenix endpoint can receive spans directly. To use a
local endpoint, expose it with a tunnel such as cloudflared.
Set up tracing
- Export gateway spans
- Instrument your app
This option does not require application code. The gateway exports a span for each request it
proxies.In the Cloudflare dashboard, open your gateway, go to Settings → Otel Integration → Add
Destination, and enter these values:Save the destination, then send traffic through the gateway. Cloudflare exports spans in batches, so
wait a minute or two for them to appear.
- OTLP Traces Endpoint: your Phoenix endpoint with
/v1/tracesappended (for a local instance exposed through a tunnel, usehttps://<your-tunnel-hostname>/v1/traces). - Content Type: select Protobuf.
- Custom Headers: add
x-project-nameset to the Phoenix project you want traces to land in. Phoenix creates the project on the first span.
If your Phoenix requires an API key, the destination also needs an
Authorization value of
Bearer <your-phoenix-api-key>. Cloudflare can send this value as a header or read it from a
Secrets Store attached to the gateway. Some gateways reject a plain header and require the Secrets
Store. Use Cloudflare’s OTel integration docs
for the current setup steps.Link gateway spans to your app’s traces
When you export gateway spans, you can nest the gateway span under an existing application span instead of starting a new trace. Pass the parent context to the gateway request with these headers:Add custom metadata
Attach your own key/value metadata to gateway requests with thecf-aig-metadata header (JSON).
Cloudflare exports each key and value as a span attribute in Phoenix, so you can filter and group by
metadata such as user, team, environment, or tenant.
What renders in Phoenix
- Gateway export: each proxied request is an LLM span with the model name and token counts populated. The provider, cost, and full prompt and response are stored under the span’s Attributes.
- App instrumentation (OpenInference): spans include the model, token counts, and the prompt and response rendered in the formatted message view.
Troubleshooting
- No spans arriving (gateway export): confirm Content Type is Protobuf (JSON is
rejected), the endpoint ends in
/v1/traces, and Cloudflare can reach your Phoenix collector. - Spans in the wrong project: set the
x-project-nameheader (gateway export) orproject_nameinregister()(app instrumentation). - Nothing yet: Cloudflare exports in batches, so send a few requests and wait a minute or two.

