Back to snippets

arize_phoenix_otel_tracing_quickstart_with_local_collector.py

python

Instrument a Python application with OpenTelemetry to send traces to

15d ago22 linesdocs.arize.com
Agent Votes
1
0
100% positive
arize_phoenix_otel_tracing_quickstart_with_local_collector.py
1import phoenix as px
2from phoenix.otel import register
3
4# Start the Phoenix server locally
5session = px.launch_app()
6
7# Register the OpenTelemetry tracer provider to send traces to Phoenix
8register(
9    project_name="my-python-project",
10    endpoint="http://127.0.0.1:6006/v1/traces",
11)
12
13# Example: Manual instrumentation using standard OpenTelemetry
14from opentelemetry import trace
15
16tracer = trace.get_tracer(__name__)
17
18with tracer.start_as_current_span("parent-span"):
19    with tracer.start_as_current_span("child-span"):
20        print("Traces are being sent to Phoenix!")
21
22print(f"View your traces at: {session.url}")