IBM watsonx.ai
Trace IBM watsonx.ai model calls with cetra from Python.
Install
Section titled “Install”pip install ibm-watsonx-ai opentelemetry-instrumentation-watsonx opentelemetry-exporter-otlp-proto-httpSet up
Section titled “Set up”from opentelemetry import tracefrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporterfrom opentelemetry.instrumentation.watsonx import WatsonxInstrumentorfrom opentelemetry.sdk.trace import TracerProviderfrom opentelemetry.sdk.trace.export import BatchSpanProcessor
provider = TracerProvider()provider.add_span_processor( BatchSpanProcessor( OTLPSpanExporter( endpoint="http://localhost:8080/v1/traces", headers={"Authorization": "Bearer <SK_CETRA_KEY>"}, ) ))trace.set_tracer_provider(provider)WatsonxInstrumentor().instrument(tracer_provider=provider)
# Call watsonx.ai with ibm_watsonx_ai as usual.provider.shutdown()Replace <SK_CETRA_KEY> with your sk-cetra- API key. See Send OpenTelemetry.
What you get
Section titled “What you get”- Model calls are recorded by the OpenLLMetry watsonx instrumentation.
- No built-in price: add a custom model price in Settings → Model prices to get a cost.
Limits
Section titled “Limits”- Setup only: calling watsonx.ai needs an IBM Cloud account, and no spans of it are captured in the repository. The provider shown is whatever the OpenLLMetry instrumentation records; cetra’s host table has no watsonx host.
- The built-in prices have no IBM watsonx.ai rows, so cost is empty until you add a custom model price in Settings → Model prices.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Custom model prices: price a model the built-in prices do not cover.