@arizeai/phoenix-otel package provides OpenTelemetry-based instrumentation for automatic tracing of LLM applications in Node.js.
Installation
Quick Start
register()
The main function for setting up Phoenix tracing.Signature
Parameters
The project name that spans will be associated with in Phoenix. This helps organize and filter traces in the Phoenix UI.Default:
"default"The URL to the Phoenix server. Can be postfixed with the tracing path. If not provided, the system will check the
PHOENIX_COLLECTOR_URL environment variable.The URL will be automatically normalized to include the /v1/traces endpoint if not present.Default: http://localhost:6006The API key for authenticating with the Phoenix instance. If not provided, the system will check the
PHOENIX_API_KEY environment variable.The API key will be automatically added to the Authorization header as a Bearer token.Additional headers to be included when communicating with the OTLP collector. These headers will be merged with any automatically generated headers (like Authorization).
Whether to use batching for span processing.
true(default): UsesOpenInferenceBatchSpanProcessorfor better performance in productionfalse: UsesOpenInferenceSimpleSpanProcessorfor immediate span export (useful for debugging)
trueA list of OpenTelemetry instrumentations to automatically register.Note: This feature may only work with CommonJS projects. ESM projects may require manual instrumentation registration.
Custom span processors to add to the tracer provider.Important: When provided, this will override the default span processor created from the
url, apiKey, headers, and batch parameters.Whether to register the tracer provider as the global provider.When
true (default), the provider will be registered globally and can be accessed throughout the application. Set to false if you want to manage the provider lifecycle manually or use multiple providers.Default: trueThe diagnostic log level for the built-in
DiagConsoleLogger.This controls the verbosity of OpenTelemetry’s internal logging. Omit this parameter to disable built-in logging entirely.Available levels: DiagLogLevel.DEBUG, DiagLogLevel.INFO, DiagLogLevel.WARN, DiagLogLevel.ERRORReturns
The configured
NodeTracerProvider instance that can be used to create traces.Examples
Advanced Components
For fine-grained control, you can use lower-level functions and components.getDefaultSpanProcessor()
Creates a default span processor configured for Phoenix.ensureCollectorEndpoint()
Normalizes a Phoenix server URL to ensure it includes the correct OTLP traces endpoint.createNoOpProvider()
Creates a no-op tracer provider for testing or when tracing is disabled.Manual Tracing
Create custom traces and spans using the OpenTelemetry API:Using Context API
Framework Integration
Express.js
Next.js
Create an instrumentation file:next.config.js:
Vercel AI SDK
Environment Variables
Phoenix server URL for trace collectionDefault:
http://localhost:6006API key for authentication with Phoenix Cloud
Node environment (development, production, etc.)
Configuration Examples
Development
Production
Testing
Troubleshooting
Traces Not Appearing
- Verify Phoenix is running:
http://localhost:6006 - Check the URL is correct
- Enable debug logging:
ESM Issues
For ESM projects, you may need to use dynamic imports:Performance Issues
- Always use
batch: truein production - Adjust batch size if needed via custom span processors
- Consider sampling for high-volume applications
See Also
- TypeScript Client Reference - Interact with Phoenix
- TypeScript Evals Reference - Run evaluations
- OpenTelemetry Documentation - Official OTEL docs