Trace a Deployed App

Once you are done iterating in a notebook, you can get the same observability in production

How to Instrument an Application

The same tracing capabilities you used during your experimentation in the notebook is available when you deploy your application. As illustrated in the image above, Phoenix is made up of tracing capabilities as well as collecting capabilities. Notably,phoenix.trace is in fact a wrapper around OpenInference auto-instrumentation and the OpenTelemetry SDK. When you deploy your application, you only need to bring along the instrumentation parts. Let's take the following code in the notebook and look at how this might look on the server. BEFORE

from phoenix.trace.openai import OpenAIInstrumentor



from openinference.semconv.resource import ResourceAttributes
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor
from opentelemetry import trace as trace_api
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

resource = Resource(attributes={
    ResourceAttributes.PROJECT_NAME: '<your-project-name>'
tracer_provider = trace_sdk.TracerProvider(resource=resource)
# If you deploy phoenix via compose, your endpoint will look something like below
span_exporter = OTLPSpanExporter(endpoint="http://phoenix:6006/v1/traces")
span_processor = SimpleSpanProcessor(span_exporter=span_exporter)


Note that you DO NOT need to install Phoenix to collect traces. All you need is OpenInference instrumentation and OpenTelemetry. The dependancies would look like:

pip install openinference-instrumentation-openai openinference-semantic-conventions opentelemetry-sdk opentelemetry-exporter-otlp

Note that instrumentation MUST be initialized BEFORE you use initialize any library or package that you are instrumenting.

Once you've made the appropriate instrumentation, you can deploy phoenix and the traces will be exported to the phoenix server (collector). For fully working Python examples, check out our example apps

Exporting Traces to Arize

Arize is an enterprise grade observability platform that supports the same capabilities as Phoenix. Note that you can export your traces to both Phoenix and Arize if you so desire (simply add two exporters). See the Arize documentation for details.

Last updated