Skip to main content
Temporal is a durable execution platform for long-running workflows. Temporal’s Python SDK emits OpenTelemetry spans for client calls, workflows, and activities. Send those spans to Phoenix, then use an OpenInference instrumentor inside your activities to capture LLM calls in the same trace.
This page uses Temporal’s built-in OpenTelemetry support plus OpenInference LLM instrumentation. It isn’t a Temporal-specific OpenInference instrumentor.

Install

You also need a Temporal service. For local development, install the Temporal CLI and start a dev server:

Setup

Set your API keys as environment variables:
Create the tracer provider with Temporal’s create_tracer_provider(), which is replay-safe: workflow spans get deterministic IDs and aren’t exported again when Temporal replays workflow code. Export it to Phoenix and enable the OpenInference OpenAI instrumentor before any Temporal client or worker code runs:
instrumentation.py

Run Temporal

Register Temporal’s OpenTelemetryPlugin when you create the client. With the plugin installed, Temporal creates spans for client calls, workflows, and activities, and propagates trace context across those boundaries. Temporal workflow code must stay deterministic, so put network I/O, including LLM calls, in activities:
app.py
In production you run the worker and the code that starts workflows as separate processes. Both import instrumentation.py and connect with the OpenTelemetryPlugin, so trace context flows from the client through the worker.

Observe

Open the temporal project in Phoenix. Each workflow run is one trace:
  • Temporal client, workflow, and activity spans from the OpenTelemetryPlugin
  • An OpenInference LLM span for the OpenAI call, nested under the activity span, with the prompt, response, and token usage
  • Errors, retries, and latency for each step

Troubleshooting

  • LLM spans aren’t nested under activities. Make sure the LLM call runs inside the activity, and that Temporal and the OpenInference instrumentor use the same tracer provider.
  • Duplicate or unexpected workflow spans. Temporal replays workflow code. Keep I/O and LLM calls in activities, not in workflow methods, and create the tracer provider with create_tracer_provider().
  • No traces in Phoenix. Confirm instrumentation.py runs before the Temporal client and worker are created, and that PHOENIX_COLLECTOR_ENDPOINT is set in every process.

Resources