[OPIK-5664] [SDK] feat: global client management API with context-wise propagation and batching warning#6123
Merged
alexkuzmik merged 10 commits intomainfrom Apr 8, 2026
Conversation
Contributor
📋 PR Linter Failed❌ Missing Section. The description is missing the |
1 similar comment
Contributor
📋 PR Linter Failed❌ Missing Section. The description is missing the |
fdbbf84 to
c8fe29a
Compare
…-wise propagation Introduce get_global_client(), set_global_client(), reset_global_client(), and get_current_client_raw() to replace the lru_cache-based get_client_cached() singleton. The new API supports context-local client overrides via contextvars, enabling EvaluationSuite.run() and the evaluation engine to propagate an explicit Opik client to @track decorators and integrations in worker threads. Key changes: - EvaluationSuite stores and propagates the parent Opik client - StreamingExecutor sets the client in each worker thread via set_global_client(context_wise=True) - All integrations resolve the client lazily at runtime via @Property - ADK patchers no longer require an opik_client argument - get_client_cached() kept as a thin delegate for backwards compatibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Explicit client is used for experiment creation (not global) - EvaluationSuite.run() forwards its stored client - Worker threads see the same client via get_global_client() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The autouse fixture was calling reset_global_client() which ends the singleton client. Tests that accidentally created a real Opik client would block on network flush during teardown. Using end_client=False just clears the slot without network I/O. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add public `batching: bool = True` parameter to Opik.__init__ - Deprecate internal `_use_batching` param - Warn when Span.end()/update(), Trace.end()/update(), Opik.update_span(), Opik.update_trace() are called with batching enabled — updates can be silently dropped causing data loss - Add Streamer.use_batching property to check batching state - Replace all _use_batching=True callsites with batching=True Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The parameter is accepted but ignored — client resolves lazily via the _opik_client property. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix batching=False bug: _use_batching default back to False so Opik(batching=False) actually disables batching - Switch batching warnings from LOGGER.warning to warnings.warn so they deduplicate automatically (once per callsite per session) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c8fe29a to
76c2a5a
Compare
…tibility Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The workers==1 branch runs tasks inline without set_global_client, so @track decorators inside the task would fall back to the global singleton instead of using the explicit client. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
Author
Addressing baz-reviewer commentsFixed
Skipping (by design)
|
Contributor
|
Thanks for the detailed follow-up and rationale on each point. I appreciate the clarifications, but I can currently only save feedback to memory when it’s attached to specific code review findings, not broader PR-level or general comments like this. |
yaricom
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
Global Client Management API
Introduces
get_global_client(),set_global_client(),reset_global_client(), andget_current_client_raw()to replace thelru_cache-basedget_client_cached()singleton. The new API supports context-local client overrides viacontextvars, fixing OPIK-5664 whereEvaluationSuite.run()ignored the parent Opik client.Resolution order for
get_global_client():set_global_client(client, context_wise=True))set_global_client(client))Key changes:
EvaluationSuitestores and propagates the parent Opik client throughevaluate_suite()StreamingExecutorsets the client in each worker thread viaset_global_client(context_wise=True)@property(no more storing at init)opik_clientargumentget_client_cached()kept as a thin delegate for backwards compatibilityBatching Warning
Adds a public
batching: bool = Trueparameter toOpik.__init__(enabled by default). When update operations (Span.end()/update(),Trace.end()/update(),Opik.update_span()/update_trace()) are called on a client with batching enabled, a warning is emitted — updates can be silently dropped by the server if they arrive before the batched create request is flushed, resulting in data loss.Streamer.use_batchingproperty to check batching state_use_batchingdeprecated in favor of publicbatchingbatching=TrueTest Improvements
reset_global_client(end_client=False)— avoids network calls, cut test time from ~44s to ~22sevaluate_suite()and worker threadsChange checklist
Issues
Testing
EvaluationSuite.run()forwards stored client toevaluate_suite()get_global_client()Documentation
N/A — no user-facing documentation changes required. The new
batchingparameter andget_global_client()/set_global_client()APIs are documented via docstrings.