Python
Quickstart
Learn how to use Autoblocks tracing in Python applications
Installation
Basic Example
Here’s a simple example showing how to use tracing with OpenAI:
Advanced Usage
Creating Spans
You can create custom spans using OpenTelemetry’s tracer:
Error Handling
Record exceptions in spans:
Nested Spans
Create nested spans to represent complex operations:
Best Practices
-
Span Naming
- Use descriptive names that reflect the operation
- Follow a consistent naming convention
- Include the operation type in the name
-
Attribute Management
- Add relevant context to spans
- Avoid logging sensitive data
- Use consistent attribute names
-
Error Handling
- Always record exceptions
- Set appropriate error status
- Include error details in attributes
-
Performance
- Keep spans focused
- Avoid excessive attributes
- Use sampling for high-volume applications
-
Async Operations
- Properly handle async/await with spans
- Use context managers for span management
- Use asyncio.gather for parallel operations
-
Python Integration
- Use context managers for span management
- Leverage Python’s async/await patterns
- Document complex operations