Dynamic Tracing Control
Dynamic Tracing Control Cookbook
This cookbook demonstrates how to use Opik’s dynamic tracing control features
to optimize performance and implement flexible tracing strategies in production.
What You’ll Learn:
-
Enable/disable tracing at runtime without code changes
-
Implement conditional tracing based on user attributes
-
Create sampling strategies for high-throughput systems
-
Measure and optimize tracing performance impact
-
Control integration tracking dynamically
Prerequisites:
Setup and Imports
First, let’s import the necessary libraries and set up our environment.
1. Basic Runtime Control
The simplest use case is toggling tracing on and off during runtime.
2. Context-Aware Tracing
Create a context manager for temporary tracing control.
3. Conditional Tracing Strategies
Implement different strategies for when to enable tracing (see part 4 for connection)
4. Smart Request Handler
Create a request handler that uses tracing strategies.