Skip to main content

OpenTelemetry GenAI Utils

Project description

The GenAI Utils package will include boilerplate and helpers to standardize instrumentation for Generative AI. This package will provide APIs and decorators to minimize the work needed to instrument genai libraries, while providing standardization for generating both types of otel, “spans and metrics” and “spans, metrics and events”

This package relies on environment variables to configure capturing of message content. By default, message content will not be captured. Set the environment variable OTEL_SEMCONV_STABILITY_OPT_IN to gen_ai_latest_experimental to enable experimental features. Set the environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to one of: - NO_CONTENT: Do not capture message content (default). - SPAN_ONLY: Capture message content in spans only. - EVENT_ONLY: Capture message content in events only. - SPAN_AND_EVENT: Capture message content in both spans and events.

To control event emission, you can optionally set OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT to true or false (case-insensitive). This variable controls whether to emit gen_ai.client.inference.operation.details events. If not explicitly set, the default value is automatically determined by OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: - When NO_CONTENT or SPAN_ONLY is set: defaults to false - When EVENT_ONLY or SPAN_AND_EVENT is set: defaults to true If explicitly set, the user’s value takes precedence over the default.

This package provides these span attributes:

  • gen_ai.provider.name: Str(openai)

  • gen_ai.operation.name: Str(chat)

  • gen_ai.request.model: Str(gpt-3.5-turbo)

  • gen_ai.response.finish_reasons: Slice([“stop”])

  • gen_ai.response.model: Str(gpt-3.5-turbo-0125)

  • gen_ai.response.id: Str(chatcmpl-Bz8yrvPnydD9pObv625n2CGBPHS13)

  • gen_ai.usage.input_tokens: Int(24)

  • gen_ai.usage.output_tokens: Int(7)

  • gen_ai.input.messages: Str(‘[{“role”: “Human”, “parts”: [{“content”: “hello world”, “type”: “text”}]}]’)

  • gen_ai.output.messages: Str(‘[{“role”: “AI”, “parts”: [{“content”: “hello back”, “type”: “text”}], “finish_reason”: “stop”}]’)

  • gen_ai.system_instructions: Str(‘[{“content”: “You are a helpful assistant.”, “type”: “text”}]’) (when system instruction is provided)

When EVENT_ONLY or SPAN_AND_EVENT mode is enabled and a LoggerProvider is configured, the package also emits gen_ai.client.inference.operation.details events with structured message content (as dictionaries instead of JSON strings). Note that when using EVENT_ONLY or SPAN_AND_EVENT, the OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT environment variable defaults to true, so events will be emitted automatically unless explicitly set to false.

Installation

pip install opentelemetry-util-genai

Design Document

The design document for the OpenTelemetry GenAI Utils can be found at: Design Document

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opentelemetry_util_genai-0.3b0.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opentelemetry_util_genai-0.3b0-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file opentelemetry_util_genai-0.3b0.tar.gz.

File metadata

  • Download URL: opentelemetry_util_genai-0.3b0.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for opentelemetry_util_genai-0.3b0.tar.gz
Algorithm Hash digest
SHA256 83e127789a9ad615b8ca65f05fc36955a67ce257b06142bfd46159a3b7ed73d3
MD5 4c85cfccfdc9a82e124cd2a8d7ebfea6
BLAKE2b-256 a2d84dd2fb622d26ec45b10ef63eb87fd512f5d7467c7bd35ce390629bd6dff8

See more details on using hashes here.

File details

Details for the file opentelemetry_util_genai-0.3b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_util_genai-0.3b0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebc2b01bcb891ddc7218452470d189d3321cd742653299ff8e7de45debcfb986
MD5 c3bca6878300892a8d272ddaa5a4a8cd
BLAKE2b-256 18e5fada54909e445d7b4007f8b96221d571999efeab9446f3127cc1cebe5e07

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page