diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md b/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md index 85e864a..14c68da 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md @@ -2,13 +2,14 @@ An OpenTelemetry instrumentation for the `openai` client library. -This instrumentation currently only supports instrumenting the Chat completions APIs. +This instrumentation currently supports instrumenting the chat completions and the embeddings APIs. We currently support the following features: - `sync` and `async` chat completions -- Streaming support -- Functions calling with tools +- Streaming support for chat completions +- Functions calling with tools for chat completions - Client side metrics +- Embeddings API calls - Following 1.28.0 Gen AI Semantic Conventions ## Installation @@ -60,7 +61,7 @@ log events instead of span events. ### Elastic specific semantic conventions - New `embeddings` value for `gen_ai.operation.name` -- New `gen_ai.request.encoding_format` attribute with openai specific values `[float, base64]` +- New `gen_ai.request.encoding_formats` attribute with openai specific values `[[float], [base64]]` ## 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 3bb955b..ddaff52 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 @@ -48,8 +48,8 @@ EVENT_GEN_AI_SYSTEM_MESSAGE = "gen_ai.system.message" EVENT_GEN_AI_TOOL_MESSAGE = "gen_ai.tool.message" -# elastic specific attributes -GEN_AI_REQUEST_ENCODING_FORMAT = "gen_ai.request.encoding_format" +# 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 @@ -204,7 +204,7 @@ def _get_embeddings_span_attributes_from_wrapper(instance, kwargs) -> Attributes span_attributes.update(_attributes_from_client(client)) if (encoding_format := kwargs.get("encoding_format")) is not None: - span_attributes[GEN_AI_REQUEST_ENCODING_FORMAT] = encoding_format + span_attributes[GEN_AI_REQUEST_ENCODING_FORMATS] = [encoding_format] return span_attributes diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_embeddings.py b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_embeddings.py index 6ac3961..4c7ae7f 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_embeddings.py +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_embeddings.py @@ -18,7 +18,7 @@ import openai import pytest -from opentelemetry.instrumentation.openai.helpers import GEN_AI_REQUEST_ENCODING_FORMAT +from opentelemetry.instrumentation.openai.helpers import GEN_AI_REQUEST_ENCODING_FORMATS from opentelemetry.trace import SpanKind, StatusCode from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import ( GEN_AI_OPERATION_NAME, @@ -117,7 +117,7 @@ def test_all_the_client_options(provider_str, model, input_tokens, duration, tra GEN_AI_REQUEST_MODEL: model, GEN_AI_SYSTEM: "openai", GEN_AI_RESPONSE_MODEL: model, - GEN_AI_REQUEST_ENCODING_FORMAT: "float", + GEN_AI_REQUEST_ENCODING_FORMATS: ("float",), GEN_AI_USAGE_INPUT_TOKENS: input_tokens, SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, @@ -159,7 +159,7 @@ def test_all_the_client_options_integration(provider_str, model, trace_exporter, GEN_AI_REQUEST_MODEL: model, GEN_AI_SYSTEM: "openai", GEN_AI_RESPONSE_MODEL: model, - GEN_AI_REQUEST_ENCODING_FORMAT: "float", + GEN_AI_REQUEST_ENCODING_FORMATS: ("float",), GEN_AI_USAGE_INPUT_TOKENS: response.usage.prompt_tokens, SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, @@ -312,7 +312,7 @@ async def test_async_all_the_client_options( GEN_AI_REQUEST_MODEL: model, GEN_AI_SYSTEM: "openai", GEN_AI_RESPONSE_MODEL: model, - GEN_AI_REQUEST_ENCODING_FORMAT: "float", + GEN_AI_REQUEST_ENCODING_FORMATS: ("float",), GEN_AI_USAGE_INPUT_TOKENS: input_tokens, SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, @@ -355,7 +355,7 @@ async def test_async_all_the_client_options_integration(provider_str, model, tra GEN_AI_REQUEST_MODEL: model, GEN_AI_SYSTEM: "openai", GEN_AI_RESPONSE_MODEL: model, - GEN_AI_REQUEST_ENCODING_FORMAT: "float", + GEN_AI_REQUEST_ENCODING_FORMATS: ("float",), GEN_AI_USAGE_INPUT_TOKENS: response.usage.prompt_tokens, SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port,