Arize Phoenix

Sync Phoenix (OpenInference) traces and their span annotations into a dataset.

What syncs#

Phoenix stores OpenTelemetry spans with OpenInference attributes. Each trace's root span becomes one record, and its span annotations with a numeric score (human feedback, or evaluations you logged) become scores; label-only annotations are skipped. When the root span isn't an LLM span (a LangChain chain, say), its input.value and output.value become the messages.

Phoenix / OpenInferencegrad record
Span IDid (the merge key for late annotations)
llm.input_messages / llm.output_messagesmessages
Span annotations (name → score)scores
session.idsession_id
user.idmetadata.user_id
llm.model_namemetadata.model
metadata (such as version), tag.tagsmetadata, metadata.tags

To import an exported OTel file once instead, use grad import FILE --format otel.

Tag spans with the model and version#

Python
from phoenix.otel import using_attributes

with using_attributes(
    session_id="sess_42",
    user_id="user_7",
    metadata={"model": "your-org/support-sft", "version": "v42"},
    tags=["prod"],
):
    ...  # call the model through an instrumented client

Send feedback from production#

Annotate the span with the user's rating. Get the span ID from OpenTelemetry while the span is active:

Python
from opentelemetry.trace import format_span_id, get_current_span
from phoenix.client import Client

span_id = format_span_id(get_current_span().get_span_context().span_id)

Client().spans.add_span_annotation(
    span_id=span_id,
    annotation_name="resolved",
    annotator_kind="HUMAN",
    label="thumbs-up",
    score=1,
)

From another service, POST /v1/span_annotations does the same over HTTP. Annotations added later are picked up by the next sync (see How syncing works).

Connect it to grad#

Store the key once as a workspace secret (it reads the value from stdin and never returns it), then add a source to a dataset. The schedule is a cron expression; leave it out to sync only when you ask.

Shell
grad secrets set phoenix-prod   # paste a Phoenix API key

grad sources add phoenix \
  --dataset support-prod \
  --host https://app.phoenix.arize.com/s/your-space \
  --secret phoenix-prod \
  --project support-bot \
  --schedule "*/30 * * * *"

grad sources list
grad sources sync src_01J9X

How syncing works#

Each sync is incremental: it pulls traces added since the last sync, plus scores and corrections added to traces it already has, so feedback that arrives days later still counts. Records are matched by the provider's trace ID and the latest score wins. Traces younger than 10 minutes wait for the next sync, because providers take a few minutes to expose new data. Phoenix has no time filter on annotations, so grad finds them through their spans: annotations on new spans land with the next sync, and annotations on spans from the last 7 days within 15 minutes (GRAD_SOURCES_PHOENIX_RESCAN_SECONDS on the workers changes the window). Older annotations need a full sync.

Syncs add dataset versions (a scheduled one at most every version_interval, 15 minutes by default; see Versions). Old versions never change, so a run keeps the exact data it pinned. If you edit old scores or change the mapping, grad sources sync src_01J9X --full (or source.sync(full=True)) rebuilds the dataset from the provider as a new version.

source.sync() returns the import job (call .wait() to block), or the sync already in progress; on the CLI, add --wait. A source syncs at most once a minute, and one that keeps failing backs off and then pauses; see When a sync fails.

A one-off grad import of an exported file is a snapshot: it never gets later feedback. Use a source for the feedback loop.

Filter what syncs#

Every source takes the shared filters, sample_rate and record caps. grad sends name, from/to, metadata and a single user_id or session_id to Phoenix's spans API; the rest (tags included, which Phoenix can't match) are matched after fetching.

Choose what to train on#

Records keep the provider's scores in scores and its model and version tags in metadata, so you can pick a slice before training. A filter runs on the server, costs nothing to re-run, and saves the slice as its own dataset:

Python
from grad import Grad

client = Grad()
good = client.datasets.get("support-prod").filter(
    scores={"resolved": ">=1"},
    metadata={"version": "v42"},
    name="support-prod-v42-good",
)
print(good.count())

A router can use the raw dataset as is: it learns from every score, good and bad.

Keys and hosts#

  • Key: a Phoenix API key, required when the Phoenix server has authentication on (Phoenix Cloud always does).
  • Project: the Phoenix project name or id, default if you leave it out. Add one source per project.
  • Hosts (required): your Phoenix Cloud space URL (https://app.phoenix.arize.com/s/your-space), or your self-hosted Phoenix URL, such as http://phoenix.internal:6006. A private address like that one needs GRAD_SOURCES_EGRESS_ALLOW; see Private hosts.

Private hosts#

Sync workers only call public https:// hosts, so a provider key can't be pointed at an internal service by mistake. To sync from a provider on your own network, list its address range in GRAD_SOURCES_EGRESS_ALLOW (comma-separated CIDRs, such as 10.20.0.0/16) on the import workers; plain http:// is then allowed to those addresses too. Store the key with that host too (grad secrets set NAME --allowed-host HOST, or allowed_hosts=[...]): a secret only goes to the public provider hosts unless it names others. On Helm, set it in workers.import.env and allow the range in networkPolicy.workerEgress (see Self-hosting).