feat: Introduce new integrations API and convert anthropic#118
feat: Introduce new integrations API and convert anthropic#118Abhijeet Prasad (AbhiPrasad) merged 1 commit intomainfrom
Conversation
aab6190 to
a837b93
Compare
ViaDézo1er / cedric (viadezo1er)
left a comment
There was a problem hiding this comment.
Since we need to migrate all providers, should additional features for providers that haven't been migrated yet be postponed until their migration is done (unless there's an explicit customer request)?
|
|
||
| Keep the class focused on orchestration. Provider-specific tracing logic should stay in `tracing.py`. | ||
|
|
||
| If the provider already supports direct instance wrapping, expose a `wrap(client)` method on the integration class that returns the traced client wrapper. |
There was a problem hiding this comment.
Which providers do this?
There was a problem hiding this comment.
I needed to update the skill - I deleted this .wrap stuff, will fix!
ViaDézo1er / cedric (viadezo1er)
left a comment
There was a problem hiding this comment.
(I don't know if this is a plausible situation)
If some providers share a similar API and we could create some shared functions/classes to reduce LoC and improve code reuse, where should this shared code live?
Or maybe we don't want to have any code shared between providers?
We can just add a utility folder, or figure that out at this time. |
a837b93 to
90e9cce
Compare
no, we can just do this on a case by case basis. Not that much activity on this repo, so we can get away with less merge conflicts. |
ViaDézo1er / cedric (viadezo1er)
left a comment
There was a problem hiding this comment.
I assume the CI is failing because the old tests are running against the new codebase and it has to be merged for the tests to be updated?
Good to merge
90e9cce to
d179fbd
Compare
yeah I gotta fix that. Thanks for the review! |
d179fbd to
218ce96
Compare
218ce96 to
11d3bd7
Compare
Convert the Google ADK (Agent Development Kit) instrumentation from the legacy wrappers pattern to the new integrations API introduced in #118. - Extract tracing helpers into integrations/adk/tracing.py - Create ADK patchers (agent, runner, flow, mcp_tool) in patchers.py - Add AdkIntegration class with proper registration - Move tests and cassettes from wrappers/adk/ to integrations/adk/ - Move auto_instrument test script to integrations/auto_test_scripts/ - Slim down wrappers/adk/__init__.py to delegate to integrations - Update noxfile.py with ADK integration test sessions - Update integrations base and registry for ADK support
Convert the Google ADK (Agent Development Kit) instrumentation from the legacy wrappers pattern to the new integrations API introduced in #118. - Extract tracing helpers into integrations/adk/tracing.py - Create ADK patchers (agent, runner, flow, mcp_tool) in patchers.py - Add AdkIntegration class with proper registration - Move tests and cassettes from wrappers/adk/ to integrations/adk/ - Move auto_instrument test script to integrations/auto_test_scripts/ - Slim down wrappers/adk/__init__.py to delegate to integrations - Update noxfile.py with ADK integration test sessions - Update integrations base and registry for ADK support
Convert the Google ADK (Agent Development Kit) instrumentation from the legacy wrappers pattern to the new integrations API introduced in #118. - Extract tracing helpers into integrations/adk/tracing.py - Create ADK patchers (agent, runner, flow, mcp_tool) in patchers.py - Add AdkIntegration class with proper registration - Move tests and cassettes from wrappers/adk/ to integrations/adk/ - Move auto_instrument test script to integrations/auto_test_scripts/ - Slim down wrappers/adk/__init__.py to delegate to integrations - Update noxfile.py with ADK integration test sessions - Update integrations base and registry for ADK support
Convert the Google ADK (Agent Development Kit) instrumentation from the legacy wrappers pattern to the new integrations API introduced in #118. - Extract tracing helpers into integrations/adk/tracing.py - Create ADK patchers (agent, runner, flow, mcp_tool) in patchers.py - Add AdkIntegration class with proper registration - Move tests and cassettes from wrappers/adk/ to integrations/adk/ - Move auto_instrument test script to integrations/auto_test_scripts/ - Slim down wrappers/adk/__init__.py to delegate to integrations - Update noxfile.py with ADK integration test sessions - Update integrations base and registry for ADK support
This PR introduces a new integrations API for provider instrumentation (wrappers) and migrates Anthropic to it as the first implementation. The goal is to separate three concerns that were previously mixed together in individual wrappers:
This PR is inspired by the current Ruby SDK implementation.
AI Summary
A new base integration layer lives under
py/src/braintrust/integrations/.BaseIntegrationis the orchestration class. It is responsible for:enabled_patchers/disabled_patchersConceptually,
BaseIntegration.setup()is now the standard entry point for “instrument this library in the current process”.BasePatcheris the unit of patch work. It represents one concrete patch strategy and is responsible for:This PR also adds
FunctionWrapperPatcher, a reusableBasePatchersubclass for the common case where instrumentation is done withwrapt.wrap_function_wrapperagainst a single target path.Supporting types added with this work:
IntegrationRuntime: normalized runtime facts for one integration (name,module,version)IntegrationPatchConfig: user-facing config object for selecting patchersversioning.py: a small stdlib-only helper for version detection and simple spec matchingAnthropic Migration
AnthropicIntegrationdefines:name = "anthropic"import_names = ("anthropic",)min_version = "0.48.0"anthropic.init.syncanthropic.init.asyncThose patchers wrap:
anthropic.Anthropic.__init__anthropic.AsyncAnthropic.__init__The constructor patching model is straightforward: after a client is constructed, Braintrust replaces the instance’s
messagesandbeta.messagessurfaces with traced wrappers. Those wrappers preserve Anthropic behavior while adding span creation, metadata capture, token metrics, time-to-first-token, stream aggregation, and error logging for sync, async, and streaming request paths.This means the old Anthropic tracing logic did not disappear, but it was moved behind a cleaner integration boundary:
The old
braintrust.wrappers.anthropicmodule is now a compatibility shim that re-exports the new Anthropic wrapper entry points.User-Facing Changes
The main user-facing change is that Anthropic instrumentation is now configurable instead of being strictly all-or-nothing.
Existing behavior still works:
Users can now also choose which Anthropic patchers to apply:
New public surfaces introduced by this PR:
braintrust.integrations.AnthropicIntegrationbraintrust.integrations.IntegrationPatchConfigbraintrust.integrations.anthropic.wrap_anthropicExisting exports:
braintrust.wrappers.anthropic.wrap_anthropicstill works for compatibilityIn practical terms, this PR is additive for users: