{"id":3197,"library":"opentelemetry-instrumentation-groq","title":"OpenTelemetry Groq Instrumentation","description":"OpenTelemetry Groq instrumentation for Python allows automatic tracing of calls to the Groq API. It integrates with the OpenTelemetry Python SDK to capture LLM-related operations, requests, responses, and metadata, conforming to the OpenTelemetry Generative AI semantic conventions. The current version is 0.58.0, with frequent releases to keep up with Groq API changes and OpenTelemetry semantic convention updates.","status":"active","version":"0.58.0","language":"en","source_language":"en","source_url":"https://github.com/traceloop/openllmetry/tree/main/packages/opentelemetry-instrumentation-groq","tags":["opentelemetry","instrumentation","groq","llm","ai","observability","tracing"],"install":[{"cmd":"pip install opentelemetry-instrumentation-groq groq","lang":"bash","label":"Install package and Groq client"}],"dependencies":[{"reason":"Core OpenTelemetry API for tracing.","package":"opentelemetry-api"},{"reason":"OpenTelemetry SDK for provider and processor setup.","package":"opentelemetry-sdk"},{"reason":"Defines the standard attribute names and values for GenAI operations.","package":"opentelemetry-semantic-conventions"},{"reason":"The Groq client library being instrumented. This package does not bundle it.","package":"groq","optional":false}],"imports":[{"symbol":"GroqInstrumentor","correct":"from opentelemetry.instrumentation.groq import GroqInstrumentor"}],"quickstart":{"code":"import os\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.groq import GroqInstrumentor\n\n# 1. Configure OpenTelemetry SDK\nresource = Resource.create({\"service.name\": \"groq-llm-app\"})\nprovider = TracerProvider(resource=resource)\nprocessor = SimpleSpanProcessor(ConsoleSpanExporter())\nprovider.add_span_processor(processor)\ntrace.set_tracer_provider(provider)\n\n# 2. Instrument the Groq library\nGroqInstrumentor().instrument()\n\n# 3. Ensure Groq API key is set\ngroq_api_key = os.environ.get(\"GROQ_API_KEY\", \"\n    # In a real application, use proper secret management.\n    # For this quickstart, ensure the env var is set or provide a dummy key for testing.\n\")\n\nif not groq_api_key:\n    print(\"Warning: GROQ_API_KEY environment variable not set.\")\n    print(\"Skipping Groq API call. Please set GROQ_API_KEY to run the example.\")\nelse:\n    print(\"Making Groq API call...\")\n    try:\n        from groq import Groq\n\n        client = Groq(api_key=groq_api_key)\n\n        chat_completion = client.chat.completions.create(\n            messages=[\n                {\n                    \"role\": \"user\",\n                    \"content\": \"Explain the concept of 'observability' in one sentence.\"\n                }\n            ],\n            model=\"llama3-8b-8192\",\n            temperature=0.7,\n            max_tokens=100\n        )\n\n        print(\"Groq Response:\", chat_completion.choices[0].message.content)\n        print(\"Traces should be printed to console.\")\n\n    except Exception as e:\n        print(f\"An error occurred during Groq API call: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to set up the OpenTelemetry SDK with a console exporter, instrument the Groq client, and make a sample API call. Traces generated by the Groq client will be printed to the console."},"warnings":[{"fix":"Update your telemetry data consumers (dashboards, alerts, processors) to reflect the new OpenTelemetry GenAI semantic convention attribute names. Refer to the OpenTelemetry GenAI specification for details.","message":"The instrumentation has migrated to the OpenTelemetry Generative AI semantic conventions (gen_ai), starting from version 0.53.0. This change renames many span attributes (e.g., `llm.request.type` to `gen_ai.request.type`) and introduces new ones. Custom dashboards, alerts, or queries relying on older attribute names will break.","severity":"breaking","affected_versions":">=0.53.0"},{"fix":"Ensure `GroqInstrumentor().instrument()` is called early in your application's lifecycle, ideally before any other `groq` imports or client instantiations.","message":"The instrumentation must be initialized (`GroqInstrumentor().instrument()`) *before* the `groq` library is imported or its client is instantiated for automatic tracing to work correctly. If `groq` is imported first, its methods might not be patched.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure `pip install groq` is run in your environment in addition to `pip install opentelemetry-instrumentation-groq`.","message":"This package only provides the OpenTelemetry instrumentation. It requires the `groq` library itself to be installed separately for the instrumentation to function. If `groq` is not installed, the instrumentation will be enabled but won't find the target methods to patch.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}