发布

  • [OPIK-5664] [SDK] feat: global client management API with context-wise propagation and batching warning (#6123)

    frostbyte_neo 发布于 2026-04-08 13:08:55 +00:00

    • [OPIK-5664] [SDK] feat: add global client management API with context-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

    • test: add client propagation tests for evaluate_suite
    • 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

    • fix: skip .end() in test teardown to avoid network calls

    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

    • feat: add public batching param to Opik and warn on update with batching
    • 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

    • chore: lint fixes and version bump to 1.11.0

    Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

    • fix: keep opik_client param on OpikTracer for backwards compatibility

    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: address PR review comments
    • 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

    • Fix lint errors

    • fix: preserve opik_client arg order in OpikTracer for backwards compatibility

    Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

    • fix: set context client in single-worker evaluation path

    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


    Co-authored-by: Claude Opus 4.6 (1M context) noreply@anthropic.com

    下载附件