[FR]: Conditional tracing at runtime
Feature Request: Enable/Disable Opik Tracing Dynamically at Runtime
Currently, Opik tracing, once configured and applied (e.g., via the @opik_track decorator or integrations like track_bedrock), appears to be always active for the instrumented functions or integrations. There isn't a straightforward, built-in way to dynamically enable or disable tracing for the entire application or specific parts of it at runtime without changing the instrumentation code or restarting the application.
This limitation can be problematic in several scenarios:
- We want to trace only a subset of requests/operations (e.g., based on user type, request parameters or a dynamic sampling rate).
- We want to avoid the overhead of tracing for all invocations, especially in high-throughput systems where constant tracing might be unnecessary or too costly.
Proposal
A global runtime toggle within the Opik SDK that controls whether tracing is active. The @opik_track decorator and other integrated tracing functions (like track_bedrock()) should consult this global state before initiating any tracing activities.
This could be implemented by:
-
Introducing a global configuration function and state checker within the Opik SDK:
from opik import set_tracing_active, is_tracing_active # To enable tracing globally set_tracing_active(True) # To disable tracing globally set_tracing_active(False) # To check current state if is_tracing_active(): print("Opik tracing is currently active.") -
Modifying Opik's tracing mechanisms to respect this global state: The
@opik_trackdecorator and other automatic instrumentation points (e.g., for Bedrock, other SDKs) would internally checkopik.is_tracing_active()before creating spans or sending data. Ifis_tracing_active()returnsFalse, the original function would be called directly without any tracing overhead.Simplified internal logic for
@opik_trackwould look like this:# This is a conceptual representation of the internal change def opik_track_decorator_factory(*decorator_args, **decorator_kwargs): def actual_decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): if opik.is_tracing_active(): # The new runtime check # Proceed with actual opik_track logic return get_original_opik_track_decorator(*decorator_args, **decorator_kwargs)(func)(*args, **kwargs) else: # Execute the function without tracing return func(*args, **kwargs) return wrapper return actual_decorator
/bounty 100
💎 $100 bounty • Comet
Steps to solve:
- Read Contributing Docs: See contributing guide and read on how to setup Opik and contribute to various parts of the code base.
- Start working: Comment
/attempt #2090with your implementation plan - Submit work: Create a pull request including
/claim #2090in the PR body to claim the bounty - Review: Team will review PR and any clarifying questions and if successful changes will be merged
- Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts
❗ Important guidelines:
- Do NOT start multiple bounties
- To claim a bounty, you need to provide a short demo video of your changes in your pull request
- If anything is unclear, ask for clarification before starting as this will help avoid potential rework
- Low quality AI PRs will not receive review and will be closed
- Please ask to be assigned before attempting to work on the bounty
Thank you for contributing to Comet!
| Attempt | Started (UTC) | Solution | Actions |
|---|---|---|---|
| 🟢 @vladimirrotariu | Jul 21, 2025, 05:54:39 AM | #2789 | Reward |
| 🟢 @Gmin2 | May 27, 2025, 07:31:28 PM | #2289 | Reward |
can i take a shot at this @vincentkoc ?
@Gmin2 you can proceed 🙏
/attempt #2090
Is this issue describing a situation I have encountered where, since adding @opik.track decorator explicitly (instead of just relying on track_openai as we did prior), in environments where we have Opik disabled (i.e. opik.configure is NOT called), I'm still seeing attempts to reach the Opik API?
test-1 | !!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
test-1 | ============================== 1 failed in 1.58s ===============================
test-1 | OPIK: Failed to process CreateSpansBatchMessage. Error: headers: {'date': 'Tue, 17 Jun 2025 18:38:47 GMT', 'content-type': 'application/json', 'content-length': '51', 'connection': 'keep-alive', 'set-cookie': 'AWSALB=ksqCJbUNuI5KNP2CiejwxuuSLpgyoOuQGT/UuxdtcS5GrGnf3OGq/j7dkB22vzzd4ckTuIRjuTVwICD2mqlBJqNuKm3lqJzEPYv9CGfYfe2Txze80Egks/yXDAwQ; Expires=Tue, 24 Jun 2025 18:38:47 GMT; Path=/, AWSALBCORS=ksqCJbUNuI5KNP2CiejwxuuSLpgyoOuQGT/UuxdtcS5GrGnf3OGq/j7dkB22vzzd4ckTuIRjuTVwICD2mqlBJqNuKm3lqJzEPYv9CGfYfe2Txze80Egks/yXDAwQ; Expires=Tue, 24 Jun 2025 18:38:47 GMT; Path=/; SameSite=None; Secure', 'server': 'nginx'}, status_code: 401, body: {'code': 401, 'message': 'API key should be provided'}
Is there any workaround where the Opik SDK will only attempt to connect to the remote API if it's been explicitly configured, like an "is active" concept?
/attempt #2090
Hi @vincentkoc , could you please assign to me this FR? 😁
🎉🎈 @vladimirrotariu has been awarded $100 by Comet! 🎈🎊