Simplify instrumentation for phoenix (#697)

This commit is contained in:
Aymeric Roucher 2025-02-18 19:42:55 +01:00 committed by GitHub
parent f335ff4efe
commit 14d310b0dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 24 deletions

View File

@ -45,8 +45,7 @@ Here's how it then looks like on the platform:
First install the required packages. Here we install [Phoenix by Arize AI](https://github.com/Arize-ai/phoenix) because that's a good solution to collect and inspect the logs, but there are other OpenTelemetry-compatible platforms that you could use for this collection & inspection part.
```shell
pip install smolagents
pip install arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp openinference-instrumentation-smolagents
pip install 'smolagents[telemetry]'
```
Then run the collector in the background.
@ -55,22 +54,14 @@ Then run the collector in the background.
python -m phoenix.server.main serve
```
Finally, set up `SmolagentsInstrumentor` to trace your agents and send the traces to Phoenix at the endpoint defined below.
Finally, set up `SmolagentsInstrumentor` to trace your agents and send the traces to Phoenix default endpoint.
```python
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from phoenix.otel import register
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
endpoint = "http://0.0.0.0:6006/v1/traces"
trace_provider = TracerProvider()
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
register()
SmolagentsInstrumentor().instrument()
```
Then you can run your agents!

View File

@ -1,7 +1,10 @@
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from phoenix.otel import register
register()
SmolagentsInstrumentor().instrument(skip_dep_check=True)
from smolagents import (
CodeAgent,
@ -12,13 +15,6 @@ from smolagents import (
)
# Let's setup the instrumentation first
trace_provider = TracerProvider()
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter("http://0.0.0.0:6006/v1/traces")))
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider, skip_dep_check=True)
# Then we run the agentic part!
model = HfApiModel()