diff --git a/python/samples/02-agents/observability/README.md b/python/samples/02-agents/observability/README.md index f456f93dd7d..566f4ca9ed5 100644 --- a/python/samples/02-agents/observability/README.md +++ b/python/samples/02-agents/observability/README.md @@ -208,6 +208,40 @@ configure_otel_providers(exporters=[exporter]) enable_sensitive_telemetry() ``` +Or with [Arize AX](https://arize.com/docs/ax/integrations/python-agent-frameworks/microsoft/microsoft-agent-framework) or [Phoenix](https://arize.com/docs/phoenix), using the [`openinference-instrumentation-agent-framework`](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-agent-framework) span processor to convert Agent Framework's GenAI spans to OpenInference. Install `openinference-instrumentation-agent-framework>=0.1.13` and `opentelemetry-exporter-otlp-proto-http`. + +The processor must run before the exporter, so set up the tracer provider yourself rather than calling `configure_otel_providers()`. The example sends to Arize AX; for Phoenix, use the commented-out exporter: + +```python +from opentelemetry import trace +from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter +from opentelemetry.sdk.resources import Resource +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import BatchSpanProcessor +from openinference.instrumentation.agent_framework import AgentFrameworkToOpenInferenceProcessor +from agent_framework.observability import enable_sensitive_telemetry + +# Arize AX: authenticate with your space ID and API key +exporter = OTLPSpanExporter( + endpoint="https://otlp.arize.com/v1/traces", + headers={"arize-space-id": "", "arize-api-key": ""}, +) + +# Phoenix: use this exporter instead. localhost:6006 is a local `phoenix serve`; +# replace it with your Phoenix endpoint if Phoenix runs elsewhere +# exporter = OTLPSpanExporter(endpoint="http://localhost:6006/v1/traces") + +tracer_provider = TracerProvider(resource=Resource.create({"openinference.project.name": ""})) +tracer_provider.add_span_processor(AgentFrameworkToOpenInferenceProcessor()) +tracer_provider.add_span_processor(BatchSpanProcessor(exporter)) +trace.set_tracer_provider(tracer_provider) + +# Capture prompts, responses, and tool arguments; without this, spans have no +# messages or inputs and outputs. Only enable in development or test environments, +# as it may expose user or system secrets in production. +enable_sensitive_telemetry() +``` + **4. Manual setup** For full control, set up providers and exporters yourself. See [advanced_manual_setup_console_output.py](./advanced_manual_setup_console_output.py) for a complete example that sends traces, logs, and metrics to the console. The `create_resource()` helper in `agent_framework.observability` can build a resource with the appropriate service name and version from environment variables (or sensible defaults), although the sample does not use it. @@ -240,6 +274,7 @@ Exporters are **not** installed by default — install only what you need: - **Application Insights**: `azure-monitor-opentelemetry` - **Aspire Dashboard or other OTLP/gRPC backends**: `opentelemetry-exporter-otlp-proto-grpc` - **OTLP over HTTP**: `opentelemetry-exporter-otlp-proto-http` +- **Arize AX or Phoenix**: `openinference-instrumentation-agent-framework>=0.1.13` and `opentelemetry-exporter-otlp-proto-http` For other backends, refer to the documentation of the specific exporter.