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-sdkVerified import paths — ran on the pinned version, not inferred.
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.
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).
To disable logging of content, set the environment variable `TRACELOOP_TRACE_CONTENT=false` before running your application.
Ensure `CohereInstrumentor().instrument()` is called early in your application's startup, preferably before initializing the Cohere client.
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.