Hi, I鈥檓 Tarun, and I鈥檓 working on integrating Phoenix into my project. I鈥檝e followed the documentation closely, but I鈥檓 having trouble getting my traces to appear in the cloud application. Even the quickstart tutorial doesn't seem to work for me. I'm not sure where I'm going wrong.
import os
from dotenv import load_dotenv
from phoenix.otel import register
import openai
load_dotenv('quick-proto/logic_gen/.env')
# Add Phoenix API Key for tracing
PHOENIX_API_KEY = os.environ.get('PHOENIX_API_KEY')
os.environ["PHOENIX_CLIENT_HEADERS"] = f"api_key={PHOENIX_API_KEY}"
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "https://app.phoenix.arize.com"
# configure the Phoenix tracer
tracer_provider = register(
project_name="default", # Default is 'default'
auto_instrument=True # See 'Trace all calls made to a library' below
)
tracer = tracer_provider.get_tracer(__name__)
client = openai.OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a haiku."}],
)
print(response.choices[0].message.content)
I get:
馃敪 OpenTelemetry Tracing Details 馃敪
| Phoenix Project: default
| Span Processor: SimpleSpanProcessor
| Collector Endpoint: https://app.phoenix.arize.com/v1/traces
| Transport: HTTP + protobuf
| Transport Headers: {'api_key': '****', 'authorization': '****'}
|
| Using a default SpanProcessor. `add_span_processor` will overwrite this default.
|
| 鈿狅笍 WARNING: It is strongly advised to use a BatchSpanProcessor in production environments.
|
| `register` has set this TracerProvider as the global OpenTelemetry default.
| To disable this behavior, call `register` with `set_global_tracer_provider=False`.
Whispers through the trees,
Autumn leaves dance with the breeze,
Nature's soft embrace.
But I don't see any traces on the app. I'd really appreciate any help I can get. Thank you for your time!
Ensure that your API key is correctly set and that the PHOENIX_COLLECTOR_ENDPOINT is properly configured. The endpoint should be https://app.phoenix.arize.com/v1/traces for cloud instances. Verify network connectivity to the Phoenix server and check for any firewall or proxy issues that might block the connection. Additionally, ensure that the environment variables are correctly loaded and that the register function is called before any OpenAI API calls.If the issue persists, consider using a BatchSpanProcessor for better performance in production environments, as suggested in the warning message. This can help manage the span export process more efficiently. If you need further assistance, please let me know.Sources:
- Quickstart: phoenix.otel.register
- OpenAI Integration
馃挕聽Hint: Mention RunLLM in the thread for followups.
Double-check that the PHOENIX_API_KEY is valid and correctly set in your environment. Ensure that the PHOENIX_COLLECTOR_ENDPOINT is set to https://app.phoenix.arize.com/v1/traces without any additional slashes or spaces. Verify that the OpenTelemetry setup is correct and that the register function is called before any OpenAI API calls. Additionally, check for any network issues that might prevent communication with the Phoenix server.If the problem persists, consider enabling debug logging to gather more information about the issue. You can do this by setting the log level to DEBUG in your OpenTelemetry configuration. This might provide more insights into what might be going wrong.Would you like more detailed troubleshooting steps?Sources:
- https://arize-ai.slack.com/archives/C04R3GXC8HK/p1722778288.923159
- https://github.com/Arize-ai/phoenix/issues/5364
馃挕聽Hint: Mention RunLLM in the thread for followups.
here's an example notebook: https://colab.research.google.com/github/Arize-ai/phoenix/blob/main/tutorials/experiments/agents-cookbook.ipynb
It would looks something like
mport phoenix as px
from phoenix.otel import register
# Add Phoenix API Key for tracing
PHOENIX_API_KEY = getpass("Enter your Phoenix API Key")
os.environ["PHOENIX_CLIENT_HEADERS"] = f"api_key={PHOENIX_API_KEY}"
# configure the Phoenix tracer
tracer_provider = register(
endpoint="https://app.phoenix.arize.com/v1/traces",
)
Thanks that worked. I'm facing another issue now, I'm trying to add tracing to my smolagents setup. and I see this in my logs
Failed to export batch code: 401, reason: I have a logic.py (which is the entrypoint) which calls the agents.py (where the setup for tracing exists).
load_dotenv()
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = f"api_key={os.environ.get('PHOENIX_API_KEY')}"
os.environ["PHOENIX_CLIENT_HEADERS"] = f"api_key={os.environ.get('PHOENIX_API_KEY')}"
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "https://app.phoenix.arize.com"
os.environ["HF_TOKEN"] = os.environ.get("HUGGINGFACE_API_KEY")
from phoenix.otel import register
# configure the Phoenix tracer
tracer_provider = register(
project_name="arize-takehome", # Default is 'default'
endpoint="https://app.phoenix.arize.com/v1/traces",
auto_instrument=True
)
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
SmolagentsInstrumentor().instrument(tracer_provider=tracer_provider)
This is what my setup looks like, I copied what is being done in your smolagents notebook as it is.
Hey Tarun N. - since you have auto_instrument=True - you actually don't need the later lines. For Failed to export batch code: 401, reason: - Is the traces showing up in the UI? This means your credentials are incorrect usually. I'm not sure it's very easy for me to debug with the given information. I have to shut my computer soon for the evening but def. let us know if you continue to be stuck.
Got it 馃憣
