The LangWatch SDKs are built entirely on top of the robust OpenTelemetry (OTel) standard. This means seamless integration with existing OTel setups and interoperability with the wider OTel ecosystem across both Python and TypeScript environments.Documentation Index
Fetch the complete documentation index at: https://langwatch.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
LangWatch Spans are OpenTelemetry Spans
It’s important to understand that LangWatch traces and spans are standard OpenTelemetry traces and spans. LangWatch adds specific semantic attributes (likelangwatch.span.type, langwatch.inputs, langwatch.outputs, langwatch.metadata) to these standard spans to power its observability features.
This foundation provides several benefits:
- Interoperability: Traces generated with LangWatch can be sent to any OTel-compatible backend (Jaeger, Tempo, Datadog, etc.) alongside your other application traces.
- Familiar API: If you’re already familiar with OpenTelemetry concepts and APIs, working with LangWatch’s manual instrumentation will feel natural.
- Leverage Existing Setup: LangWatch integrates smoothly with your existing OTel
TracerProviderand instrumentation.
Leverage the OpenTelemetry Ecosystem: Auto-Instrumentation
One of the most powerful benefits of LangWatch’s OpenTelemetry foundation is its automatic compatibility with the extensive ecosystem of OpenTelemetry auto-instrumentation libraries. When you use standard OTel auto-instrumentation for libraries like web frameworks, databases, or task queues alongside LangWatch, you gain complete end-to-end visibility into your LLM application’s requests. Because LangWatch and these auto-instrumentors use the same underlying OpenTelemetry tracing system and context propagation mechanisms, spans generated across different parts of your application are automatically linked together into a single, unified trace.Examples of Auto-Instrumentation Integration
Here are common scenarios where combining LangWatch with OTel auto-instrumentation provides significant value:-
Web Frameworks: Using libraries like
opentelemetry-instrumentation-fastapi(Python) or@opentelemetry/instrumentation-express(TypeScript), an incoming HTTP request automatically starts a trace. When your request handler calls a function instrumented with LangWatch, those LangWatch spans become children of the incoming request span. -
HTTP Clients: If your LLM application makes outbound API calls using libraries instrumented by
opentelemetry-instrumentation-requests(Python) or@opentelemetry/instrumentation-http(TypeScript), these HTTP request spans will automatically appear within your LangWatch trace. -
Task Queues: When a request handled by your web server (and traced by LangWatch) enqueues a background job using
opentelemetry-instrumentation-celery(Python) or similar task queue instrumentations, the trace context is automatically propagated. -
Databases & ORMs: Using libraries like
opentelemetry-instrumentation-sqlalchemy(Python) or@opentelemetry/instrumentation-mongodb(TypeScript), any database queries executed during your LLM processing will appear as spans within the relevant LangWatch trace.
Basic Setup and Configuration
Python Setup
TypeScript Setup
Manual Span Management
Python Manual Span Control
TypeScript Manual Span Control
Advanced Configuration
Python Advanced Configuration
TypeScript Advanced Configuration
Sampling and Performance Tuning
Python Sampling Configuration
TypeScript Sampling Configuration
Complete Example: RAG with OpenAI and Background Tasks
Python Complete Example
TypeScript Complete Example
Debugging and Troubleshooting
Python Debugging
TypeScript Debugging
Best Practices
General Best Practices
- Always End Spans: Use try-finally blocks or context managers to ensure spans are ended
- Set Appropriate Types: Use meaningful span types for better categorization
- Add Context: Include relevant attributes and events
- Handle Errors: Properly record exceptions and set error status
- Use Async Context: Propagate span context across async boundaries
- Monitor Performance: Track the impact of span management on your application
Language-Specific Best Practices
Migration Checklist
When migrating from an existing OpenTelemetry setup:- Inventory Current Setup: Document all current instrumentations, exporters, and configurations
- Test in Development: Start with development environment migration
- Verify Data Flow: Ensure traces are appearing in LangWatch dashboard
- Performance Testing: Monitor application performance impact
- Gradual Rollout: Migrate environments one at a time
- Fallback Plan: Keep existing setup as backup during transition
- Documentation: Update team documentation and runbooks
Troubleshooting Common Issues
Common Migration Problems
- Duplicate Spans: Ensure only one observability setup is running
- Missing Traces: Check API key and endpoint configuration
- Performance Degradation: Adjust sampling and batch processing settings
- Context Loss: Verify context propagation configuration
- Instrumentation Conflicts: Check for conflicting instrumentations
Debugging Migration
Performance Considerations
When using OpenTelemetry with LangWatch, consider these performance implications:- Memory Usage: Spans consume memory until explicitly ended
- Context Propagation: Context management can be error-prone in complex async scenarios
- Error Handling: Ensure spans are always ended, even when exceptions occur
- Batch Processing: Use batch processors for high-volume applications
- Sampling: Implement sampling to reduce overhead in production