Skip to content

fix(watsonx): instrument the installed IBM SDKs independently - #4780

Open
Boulea7 wants to merge 1 commit into
traceloop:mainfrom
Boulea7:fix/watsonx-installed-sdks
Open

Boulea7 wants to merge 1 commit into
traceloop:mainfrom
Boulea7:fix/watsonx-installed-sdks

Conversation

@Boulea7

@Boulea7 Boulea7 commented Dec 2, 2026 •

Copy link
Copy Markdown

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.

Jaeger showing the Watsonx generation span and token counts

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.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
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.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 57a9ba8b-2308-4670-9a8c-08f16fd92e76
Commits

Reviewing files that changed from the base of the PR and between b870d8a and 1b71724.

Files selected for processing: 3

  • packages/opentelemetry-instrumentation-watsonx/README.md
  • packages/opentelemetry-instrumentation-watsonx/opentelemetry/instrumentation/watsonx/__init__.py
  • packages/opentelemetry-instrumentation-watsonx/tests/test_registration.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants