Skip to main content

IBM watsonx.ai Python SDK tracing

Trace calls made through the ibm-watsonx-ai Python SDK with the maintained traceAI-watsonx package. It supports ibm-watsonx-ai 1.3.0 up to, but not including, 2.0.

pip install traceAI-watsonx

Set FI_API_KEY, FI_SECRET_KEY, and your watsonx.ai credentials (WATSONX_APIKEY, WATSONX_URL, WATSONX_PROJECT_ID) in your environment. Then:

import os

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
from ibm_watsonx_ai import Credentials
from ibm_watsonx_ai.foundation_models import ModelInference
from traceai_watsonx import WatsonxInstrumentor

provider = register(project_type=ProjectType.OBSERVE, project_name="watsonx-demo")
WatsonxInstrumentor().instrument(tracer_provider=provider)
model = ModelInference(
    model_id="ibm/granite-3-8b-instruct",
    credentials=Credentials(api_key=os.environ["WATSONX_APIKEY"], url=os.environ["WATSONX_URL"]),
    project_id=os.environ["WATSONX_PROJECT_ID"],
)
answer = model.chat(messages=[{"role": "user", "content": "What is the capital of Japan?"}])
print(answer["choices"][0]["message"]["content"])
provider.force_flush()

With the fi-instrument launcher or FI_INSTRUMENTATIONS, no code is needed: importing ibm_watsonx_ai turns this integration on.

Find the watsonx.chat span in your Future AGI project. Covered calls:

Span SDK methods
watsonx.text_completion ModelInference.generate, generate_text, generate_text_stream, agenerate, agenerate_stream
watsonx.chat ModelInference.chat, chat_stream, achat, achat_stream
watsonx.embeddings Embeddings.generate, embed_documents, embed_query, agenerate, aembed_documents, aembed_query

Each span records gen_ai.provider.name (ibm.watsonx.ai), the request model or deployment id, request parameters (those given to the call, over those the ModelInference or Embeddings object was created with), input and output messages with input.value / output.value, token usage (from input_token_count / generated_token_count, the embeddings input_token_count, or the chat usage), and finish reasons. One SDK call is one span: methods that call each other inside the SDK (generate_text calls generate, embed_query calls generate) are not traced twice, and the outer span takes its usage, finish reason and response model from the inner response. Only a plain-text generate_text_stream has no token counts, because it yields text only; use raw_response=True to get them. Prompt-template values (prompt_variables) are recorded as gen_ai.prompt.template.variables, not as a request parameter, and are removed by the input-hiding settings. For generate(prompt=[...]) each answer is recorded under its own prompt's message index and usage is summed.

Streams finish when fully consumed or closed; a stream abandoned without closing it is marked watsonx.stream.incomplete and carries no partial output. Errors set the span status to ERROR and error.type, and the exception is re-raised unchanged. Exception messages, stacks, credentials and embedding vectors are never exported. Non-text parts of chat messages (images) are not captured.

Pass TraceConfig(hide_inputs=True, hide_outputs=True) to instrument(config=...) to remove prompt and response content. Do not instrument HTTPX for the same requests, or you will get duplicate spans. The package does not send requests to IBM on its own.

Metadata

Release files for traceAI-watsonx 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for traceAI-watsonx 0.1.0
File Size Uploaded Provenance Actions
traceai_watsonx-0.1.0.tar.gz 8.3 kB Without provenance Details for traceai_watsonx-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for traceAI-watsonx 0.1.0
File Interpreter ABI Platform Actions
traceai_watsonx-0.1.0-py3-none-any.whl Python 3 none any Details for traceai_watsonx-0.1.0-py3-none-any.whl

Total release size: 17.6 kB

Release files / traceai_watsonx-0.1.0.tar.gz

Download URL traceai_watsonx-0.1.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
802a3b280540ea5b019ebf9196b73f5f715f7a2524e271601c59d9e7466a3557
BLAKE2b-256 checksum
How to use checksums
968c70179a767b3dc1a8dab904d3ef5281b3c705e978f0579758a9056431170a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / traceai_watsonx-0.1.0-py3-none-any.whl

Download URL traceai_watsonx-0.1.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a20d190c28732d29f74ee7c0238d04d65610f32c82d0a19cf3b02290ea55f1ce
BLAKE2b-256 checksum
How to use checksums
a632ac51de995cc6e9816c96f2ae9c5607b2a79f2e8a6a74c3e5f7ec83d49bc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for traceAI-watsonx 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page