Registry / observability / opentelemetry-instrumentation-cohere

opentelemetry-instrumentation-cohere

JSON →
library0.62.3pypypi✓ verified 23d ago

This library provides OpenTelemetry instrumentation for the Cohere Python SDK, enabling automatic tracing of calls to Cohere's language model endpoints. It helps monitor performance, token usage, and costs associated with LLM applications. Regularly updated, the current version is 0.58.0, with releases occurring frequently, sometimes multiple times a month.

pip install opentelemetry-instrumentation-cohere cohere opentelemetry-sdk
INSTALL
IMPORT
SIG · OPENTELEMETRY-INST
O
opentelemetry-instrumentation-cohere
observabilitypythonv0.62.3
Install
8.7s avg
Import
444ms
Disk
102MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.62.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.456s · 106.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 8.7s · import 0.432s · 92MB
102MB installed
● package 102MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CohereInstrumentor
from opentelemetry.instrumentation.cohere import CohereInstrumentor
This is the main class to enable Cohere instrumentation.

This quickstart demonstrates how to set up OpenTelemetry tracing for Cohere API calls. It initializes a basic OpenTelemetry SDK with a console exporter, instruments the Cohere library, and then makes a sample chat completion request. Ensure the `COHERE_API_KEY` environment variable is set before running.

import os import cohere from opentelemetry import trace from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor from opentelemetry.instrumentation.cohere import CohereInstrumentor # 1. Set up OpenTelemetry SDK for console output resource = Resource.create({"service.name": "my-cohere-app"}) provider = TracerProvider(resource=resource) processor = SimpleSpanProcessor(ConsoleSpanExporter()) provider.add_span_processor(processor) trace.set_tracer_provider(provider) # 2. Instrument Cohere CohereInstrumentor().instrument() # 3. Use Cohere client (ensure COHERE_API_KEY environment variable is set) cohere_api_key = os.environ.get('COHERE_API_KEY', '') if not cohere_api_key: print("Warning: COHERE_API_KEY environment variable not set. Cohere client may fail.") # For demonstration, you might want to uncomment and replace 'YOUR_COHERE_API_KEY' for testing # cohere_api_key = 'YOUR_COHERE_API_KEY' if cohere_api_key: try: client = cohere.Client(cohere_api_key) response = client.chat( model="command", message="Hello, how are you today?" ) print("\nCohere Response:", response.text) print("\nTraces should be printed to the console above.") except Exception as e: print(f"Error calling Cohere: {e}") else: print("Skipping Cohere call because API key is not available.")
Debug
Known issues
breakingBreaking changes related to OpenTelemetry GenAI Semantic Conventions (gen_ai) have been introduced in versions 0.55.0 and later. Attribute names for LLM-related spans may have changed to align with the new conventions (e.g., `gen_ai.request.model` instead of older variations).
fix
Review the official OpenTelemetry 'gen_ai' semantic conventions documentation for updated attribute names. Update your queries, dashboards, and any code relying on specific attribute keys. Consider using `OTEL_SEMCONV_STABILITY_OPT_IN` if available for temporary backward compatibility during migration (check core OTel Python documentation).
affects: >=0.55.0
gotchaBy default, this instrumentation logs sensitive data like prompts, completions, and embeddings to span attributes, which might contain highly sensitive user data.
fix
To disable logging of content, set the environment variable `TRACELOOP_TRACE_CONTENT=false` before running your application.
affects: All
gotchaThe `CohereInstrumentor().instrument()` call must be executed *before* any `cohere.Client()` instance is created or any Cohere API calls are made, as instrumentation typically relies on monkey-patching existing libraries.
fix
Ensure `CohereInstrumentor().instrument()` is called early in your application's startup, preferably before initializing the Cohere client.
affects: All
gotchaSimply installing `opentelemetry-instrumentation-cohere` and calling `instrument()` will not make traces visible. You must also configure an OpenTelemetry SDK (e.g., `TracerProvider`, `SpanProcessor`, and an `Exporter`) in your application.
fix
Set up a complete OpenTelemetry SDK pipeline, including a `TracerProvider`, at least one `SpanProcessor` (e.g., `SimpleSpanProcessor` or `BatchSpanProcessor`), and an `Exporter` (e.g., `ConsoleSpanExporter`, `OTLPExporter`) to send your telemetry data to a backend or console. Refer to the OpenTelemetry Python SDK documentation for detailed setup.
affects: All
Upgrade
Version history
0.62.3latest on PyPI · released Aug 10, 2026
Audit
Dependencies
cohererequiredThe core library being instrumented. Requires Cohere Python SDK client >= 5.3.0.
opentelemetry-apirequiredCore OpenTelemetry API for defining telemetry. Automatically installed.
opentelemetry-sdkrequiredOpenTelemetry SDK is required in the application to process and export telemetry data.
pythonrequiredRequires Python version between 3.10 and 3.12 (exclusive of 4.0).
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
opentelemetry-instrumentation-cohere — pip install opentelemetry-instrumentation-cohere · libregistry