You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(watsonx): instrument the installed IBM SDKs independently - #4780
The Watsonx instrumentor already wraps both IBM clients, but its dependency check stops setup when only ibm-watsonx-ai is installed. Installing only ibm-watson-machine-learning leaves several of its methods wrapped when setup reaches the missing newer package.
This change registers the supported clients found in the process, tracks those wrappers for teardown and restores them if setup fails partway through. It also handles the shared constructor in the first ibm-watsonx-ai releases. This addresses the direct SDK instrumentation part of #4689. The zero-code discovery metadata is tracked separately there.
All eight registration tests pass. I also exercised the public IBM ModelInference.generate() method with a local synthetic backend across six installations, including each client on its own, both clients together and the earliest supported client. Registration produced one generation span per call and teardown restored the original methods. With IBM's 1.9.1 client, Jaeger received this span with two input tokens and one output token.
I also ran the existing replay suite in offline mode on the base and the change. Both runs encountered the same eight fixture errors. Four event recordings are missing and the other four recordings did not match the SDK requests.
Added tests covering the change.
Included an observability screenshot.
Used the conventional PR title.
Updated the Watsonx documentation.
Summary by CodeRabbit
New Features
Watsonx instrumentation now supports both legacy and current SDK versions, with the option to instrument either client or both in the same process.
Documentation
Updated the usage guide with supported SDK versions and manual instrumentation options.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You have signed the CLA already but the status is still pending? Let us recheck it.
No actionable comments were generated in the recent review.
Walkthrough
The Watsonx instrumentation now detects supported legacy and current SDK installations, wraps model methods from the selected SDKs, and restores wrappers after uninstrumentation or partial setup failure. The README documents supported versions and manual instrumentation options.
Changes: Watsonx SDK instrumentation
Layer / File(s)
Summary
SDK selection and dependency reporting packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py, packages/opentelemetry-instrumentation-watsonx/README.md
The instrumentor defines separate requirements for the legacy and current SDKs and detects requirements without dependency conflicts. instrumentation_dependencies() returns detected requirements, or the legacy requirement if none are detected. The README lists supported SDK versions and describes instrumenting either client or both.
Model wrapper lifecycle and registration tests packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py, packages/opentelemetry-instrumentation-watsonx/tests/test_registration.py
The instrumentor wraps methods from selected SDKs, skips inherited methods when the base model is also selected, and restores wrappers after setup failure or uninstrumentation. Tests cover SDK selection, inherited constructors, and partial-registration cleanup.
sequenceDiagram
participant WatsonxInstrumentor
participant InstalledSDKMetadata
participant SDKModelClasses
participant WrapperStack
WatsonxInstrumentor->>InstalledSDKMetadata: detect supported SDK requirements
WatsonxInstrumentor->>SDKModelClasses: import models for selected SDKs
WatsonxInstrumentor->>WrapperStack: register successful method wrappers
WatsonxInstrumentor->>WrapperStack: close wrappers during cleanup or setup failure
Loading
Possibly related issues
traceloop/openllmetry issue 4689 — This PR adds direct instrumentation for the ibm-watsonx-ai SDK described in the issue. The issue's zero-code discovery metadata is tracked separately.
Suggested reviewers:gyliu513, huang-cn
Merge Risk: Minimal · up to 1b717
The change makes Watsonx instrumentation work when only one of the two supported IBM SDKs is installed, and it restores wrappers cleanly on teardown or failed setup. No merge-blocking issue was found. One minor edge case remains for metadata-less SDK source trees combined with the dependency-check bypass; it is not documented as supported.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "fix(watsonx): instrument the installed IBM SDKs independently" matches the main change. The PR registers each supported IBM SDK (ibm-watsonx-ai and ibm-watson-machine-learning) separately w…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix(watsonx): instrument the installed IBM SDKs independently" matches the main change. The PR registers each supported IBM SDK (ibm-watsonx-ai and ibm-watson-machine-learning) separately when installed. It also tracks wrappers for teardown and rolls them back on partial setup failure. The title names the fix and the scope (Watsonx, installed SDKs, independent handling), so it is specific and related to the changeset. It is a conventional-commit style title and is under 72 characters.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this 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
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.
The Watsonx instrumentor already wraps both IBM clients, but its dependency check stops setup when only
ibm-watsonx-aiis installed. Installing onlyibm-watson-machine-learningleaves several of its methods wrapped when setup reaches the missing newer package.This change registers the supported clients found in the process, tracks those wrappers for teardown and restores them if setup fails partway through. It also handles the shared constructor in the first
ibm-watsonx-aireleases. This addresses the direct SDK instrumentation part of #4689. The zero-code discovery metadata is tracked separately there.All eight registration tests pass. I also exercised the public IBM
ModelInference.generate()method with a local synthetic backend across six installations, including each client on its own, both clients together and the earliest supported client. Registration produced one generation span per call and teardown restored the original methods. With IBM's 1.9.1 client, Jaeger received this span with two input tokens and one output token.I also ran the existing replay suite in offline mode on the base and the change. Both runs encountered the same eight fixture errors. Four event recordings are missing and the other four recordings did not match the SDK requests.
Summary by CodeRabbit