Simplify instrumentation for phoenix (#697)
This commit is contained in:
parent
f335ff4efe
commit
14d310b0dc
|
@ -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.
|
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
|
```shell
|
||||||
pip install smolagents
|
pip install 'smolagents[telemetry]'
|
||||||
pip install arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp openinference-instrumentation-smolagents
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run the collector in the background.
|
Then run the collector in the background.
|
||||||
|
@ -55,22 +54,14 @@ Then run the collector in the background.
|
||||||
python -m phoenix.server.main serve
|
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
|
```python
|
||||||
from opentelemetry import trace
|
from phoenix.otel import register
|
||||||
from opentelemetry.sdk.trace import TracerProvider
|
|
||||||
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
|
||||||
|
|
||||||
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
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"
|
register()
|
||||||
trace_provider = TracerProvider()
|
SmolagentsInstrumentor().instrument()
|
||||||
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
|
|
||||||
|
|
||||||
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)
|
|
||||||
```
|
```
|
||||||
Then you can run your agents!
|
Then you can run your agents!
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
|
||||||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
|
from phoenix.otel import register
|
||||||
from opentelemetry.sdk.trace import TracerProvider
|
|
||||||
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
|
||||||
|
register()
|
||||||
|
SmolagentsInstrumentor().instrument(skip_dep_check=True)
|
||||||
|
|
||||||
|
|
||||||
from smolagents import (
|
from smolagents import (
|
||||||
CodeAgent,
|
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!
|
# Then we run the agentic part!
|
||||||
model = HfApiModel()
|
model = HfApiModel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue