feat(closes OPEN-10364): make tracers init-based#647
Open
gustavocidornelas wants to merge 1 commit into
Open
Conversation
Contributor
|
@gustavocidornelas did you want me to review? |
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.
Pull Request
Summary
Turns
openlayer.lib.init()into an auto-instrumenting entry point.Calling
init()with no extra arguments now detects every installed Openlayer-supported LLM SDK (openai,anthropic,mistral,groq,gemini,oci,azure_content_understanding,litellm,portkey,google_adk) and patches it so that every newly-constructed client is auto-traced.Existing
trace_<x>(client)calls keep working. They're now also idempotent, so mixing auto-instrumentation with explicit wraps no longer double-wraps methods.Changes
auto_instrument: bool | list[str] = Trueparameter toinit()insrc/openlayer/lib/tracing/tracer.py.Procedural (not stored in
_tracer_config), evaluated fresh on every call.Falseshort-circuits, a list patchesonly that subset.
src/openlayer/lib/integrations/_auto.pywith:IntegrationSpecdataclass, 10-entryREGISTRY,auto_instrument(targets)andunpatch_all()orchestrators, plus shared_patch_class_init/_unpatch_class_inithelpers that wrap a client class
__init__viafunctools.wraps(so__wrapped__makes unpatch trivially reversible)._patch_<x>()/_unpatch_<x>()helpers added to 7 tracers (openai_tracer.py,anthropic_tracer.py,mistral_tracer.py,groq_tracer.py,gemini_tracer.py,oci_tracer.py,azure_content_understanding_tracer.py). Each wraps the SDK's client class__init__so new instances auto-call theexisting
trace_<x>(client)function (theportkey_tracer.pypattern). Covers sync + async + Azure variants whereapplicable.
trace_<x>(client)in 9 tracer files gained agetattr(client, "_openlayer_patched", False) is Trueentry guard plus a marker assignment before return. Pre-existing correctnessimprovement — without it, calling
trace_openai(client)twice nested the wrappers and double-counted every call. Thestrict
is Truecomparison avoids false positives fromMagicMock's auto-attribute behavior (caught by the bedrocktest suite).
configure()deprecated alias updated to defaultauto_instrument=Falseviakwargs.setdefault. Existingconfigure()callers see no surprise patching on upgrade.auto_instrumentandunpatch_allfromopenlayer.lib._is_installedprobes the full dotted path viaimportlib.util.find_spec(not just the top-level segment).Fixes a namespace-package collision where
google.adkfalsely reported installed becausegoogle.generativeaiwasinstalled under the same namespace.
Context
OPEN-10364: Make tracers init-based
Testing
Monitoring
Notes
init()today (no args) will now auto-instrument every installed supported SDKon their next upgrade. This is the intended behavior — the "init-based" tracer model — but worth a callout in the
changelog. Users can opt out with
init(auto_instrument=False)or by switching to the deprecatedconfigure()(which preserves the no-patching default).
init()are NOT retroactively auto-traced. The patch wraps theclass
__init__, so only future construction goes through it. Class-method-level patching for catching pre-existinginstances is deferred.
different mechanism), LangChain auto-instrumentation (callback-based, no clean global hook), and the
auto_instrumentenv-var convenience.with the rest. The returned
dict[str, bool]reflects per-integration success.