{"library":"opentelemetry-util-genai","title":"OpenTelemetry GenAI Utilities","description":"The `opentelemetry-util-genai` package provides boilerplate and helper functions to standardize instrumentation for Generative AI applications within the OpenTelemetry Python ecosystem. It aims to minimize the effort required to instrument GenAI libraries by offering standardized approaches for generating spans, metrics, and events. The library is currently in a beta development stage (v0.3b0) and is part of the larger `opentelemetry-python-contrib` project, with ongoing updates and a focus on evolving semantic conventions.","language":"python","status":"active","last_verified":"Mon Apr 13","install":{"commands":["pip install opentelemetry-util-genai"],"cli":null},"imports":[],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\n\n# Enable experimental GenAI semantic conventions\nos.environ['OTEL_SEMCONV_STABILITY_OPT_IN'] = 'gen_ai_latest_experimental'\n\n# Configure message content capture for spans and events\nos.environ['OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT'] = 'SPAN_AND_EVENT'\n\n# Explicitly enable event emission (optional, defaults based on CAPTURE_MESSAGE_CONTENT)\nos.environ['OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT'] = 'true'\n\n# Example of a basic OpenTelemetry setup (from opentelemetry-sdk, not util-genai itself)\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.resources import Resource\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\n\n# Service name is required for most backends\nresource = Resource.create({\"service.name\": \"my-genai-app\"})\n\nprovider = TracerProvider(resource=resource)\nprocessor = BatchSpanProcessor(OTLPSpanExporter())\nprovider.add_span_processor(processor)\ntrace.set_tracer_provider(provider)\n\ntracer = trace.get_tracer(__name__)\n\nprint(\"OpenTelemetry GenAI environment variables configured and basic tracer initialized.\")\nprint(\"Further GenAI specific instrumentation would be provided by specialized libraries (e.g., opentelemetry-instrumentation-openai).\")\n","lang":"python","description":"This quickstart demonstrates how to configure the essential environment variables that control the behavior of `opentelemetry-util-genai` when used by other OpenTelemetry GenAI instrumentation libraries. It also includes a basic OpenTelemetry tracer setup, which is a prerequisite for any instrumentation. This package primarily provides internal utilities and relies on these environment variables for user-facing configuration, rather than direct API calls for typical end-user instrumentation.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}