diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md b/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md index 021f0e7..1bf58ae 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md @@ -10,7 +10,7 @@ We currently support the following features: - Functions calling with tools for chat completions - Client side metrics - Embeddings API calls -- Following 1.28.0 Gen AI Semantic Conventions +- Following 1.29.0 Gen AI Semantic Conventions ## Installation @@ -56,8 +56,7 @@ None ### Elastic specific semantic conventions -- New `embeddings` value for `gen_ai.operation.name` -- New `gen_ai.request.encoding_formats` attribute with openai specific values `[[float], [base64]]` +None at the moment ## Development diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/helpers.py b/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/helpers.py index bf08ade..6aa3f03 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/helpers.py +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/helpers.py @@ -38,6 +38,13 @@ GEN_AI_USAGE_INPUT_TOKENS, GEN_AI_USAGE_OUTPUT_TOKENS, ) + +try: + from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_REQUEST_ENCODING_FORMATS +except ImportError: + # available since 1.29.0 + GEN_AI_REQUEST_ENCODING_FORMATS = "gen_ai.request.encoding_formats" + from opentelemetry.metrics import Histogram from opentelemetry.trace import Span from opentelemetry.util.types import Attributes @@ -48,9 +55,6 @@ EVENT_GEN_AI_SYSTEM_MESSAGE = "gen_ai.system.message" EVENT_GEN_AI_TOOL_MESSAGE = "gen_ai.tool.message" -# not yet released attributes -GEN_AI_REQUEST_ENCODING_FORMATS = "gen_ai.request.encoding_formats" - # As this is only used for a type annotation, only import from openai module # when running type checker like pyright since we otherwise don't want to import # it before the app.