{"id":2156,"library":"opentelemetry-instrumentation-cohere","title":"OpenTelemetry Cohere Instrumentation","description":"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.","status":"active","version":"0.58.0","language":"en","source_language":"en","source_url":"https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-cohere","tags":["opentelemetry","observability","tracing","llm","ai","cohere","instrumentation"],"install":[{"cmd":"pip install opentelemetry-instrumentation-cohere cohere opentelemetry-sdk","lang":"bash","label":"Install with dependencies"}],"dependencies":[{"reason":"The core library being instrumented. Requires Cohere Python SDK client >= 5.3.0.","package":"cohere","optional":false},{"reason":"Core OpenTelemetry API for defining telemetry. Automatically installed.","package":"opentelemetry-api","optional":false},{"reason":"OpenTelemetry SDK is required in the application to process and export telemetry data.","package":"opentelemetry-sdk","optional":false},{"reason":"Requires Python version between 3.10 and 3.12 (exclusive of 4.0).","package":"python","optional":false}],"imports":[{"note":"This is the main class to enable Cohere instrumentation.","symbol":"CohereInstrumentor","correct":"from opentelemetry.instrumentation.cohere import CohereInstrumentor"}],"quickstart":{"code":"import os\nimport cohere\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor\nfrom opentelemetry.instrumentation.cohere import CohereInstrumentor\n\n# 1. Set up OpenTelemetry SDK for console output\nresource = Resource.create({\"service.name\": \"my-cohere-app\"})\nprovider = TracerProvider(resource=resource)\nprocessor = SimpleSpanProcessor(ConsoleSpanExporter())\nprovider.add_span_processor(processor)\ntrace.set_tracer_provider(provider)\n\n# 2. Instrument Cohere\nCohereInstrumentor().instrument()\n\n# 3. Use Cohere client (ensure COHERE_API_KEY environment variable is set)\ncohere_api_key = os.environ.get('COHERE_API_KEY', '')\n\nif not cohere_api_key:\n    print(\"Warning: COHERE_API_KEY environment variable not set. Cohere client may fail.\")\n    # For demonstration, you might want to uncomment and replace 'YOUR_COHERE_API_KEY' for testing\n    # cohere_api_key = 'YOUR_COHERE_API_KEY'\n\nif cohere_api_key:\n    try:\n        client = cohere.Client(cohere_api_key)\n        response = client.chat(\n            model=\"command\",\n            message=\"Hello, how are you today?\"\n        )\n        print(\"\\nCohere Response:\", response.text)\n        print(\"\\nTraces should be printed to the console above.\")\n    except Exception as e:\n        print(f\"Error calling Cohere: {e}\")\nelse:\n    print(\"Skipping Cohere call because API key is not available.\")\n\n","lang":"python","description":"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."},"warnings":[{"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).","message":"Breaking 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).","severity":"breaking","affected_versions":">=0.55.0"},{"fix":"To disable logging of content, set the environment variable `TRACELOOP_TRACE_CONTENT=false` before running your application.","message":"By default, this instrumentation logs sensitive data like prompts, completions, and embeddings to span attributes, which might contain highly sensitive user data.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure `CohereInstrumentor().instrument()` is called early in your application's startup, preferably before initializing the Cohere client.","message":"The `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.","severity":"gotcha","affected_versions":"All"},{"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.","message":"Simply 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}