From 5807b3094c832975d53fae697ae174f0974b7421 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 2 Dec 2024 15:59:57 +0100 Subject: [PATCH] elastic-opentelemetry-instrumentation-openai: Drop span events support --- .../README.md | 6 +- .../instrumentation/openai/__init__.py | 61 +- .../openai/environment_variables.py | 2 - .../instrumentation/openai/helpers.py | 56 - .../instrumentation/openai/wrappers.py | 24 +- ...ents[azure_provider_chat_completions].yaml | 155 -- ...nts[ollama_provider_chat_completions].yaml | 85 -- ...nts[openai_provider_chat_completions].yaml | 133 -- ...ents[azure_provider_chat_completions].yaml | 104 -- ...nts[ollama_provider_chat_completions].yaml | 80 -- ...nts[openai_provider_chat_completions].yaml | 112 -- ...ents[azure_provider_chat_completions].yaml | 182 --- ...nts[openai_provider_chat_completions].yaml | 177 --- ...ents[azure_provider_chat_completions].yaml | 155 -- ...nts[ollama_provider_chat_completions].yaml | 85 -- ...nts[openai_provider_chat_completions].yaml | 133 -- ...nts[ollama_provider_chat_completions].yaml | 175 --- ...nts[openai_provider_chat_completions].yaml | 155 -- ...ents[azure_provider_chat_completions].yaml | 160 --- ...nts[ollama_provider_chat_completions].yaml | 156 -- ...nts[openai_provider_chat_completions].yaml | 156 -- ...ents[azure_provider_chat_completions].yaml | 182 --- ...nts[ollama_provider_chat_completions].yaml | 129 -- ...nts[openai_provider_chat_completions].yaml | 177 --- .../tests/test_chat_completions.py | 1272 +++-------------- 25 files changed, 205 insertions(+), 3907 deletions(-) delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[azure_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[openai_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[azure_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[openai_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_tools_with_capture_message_content_span_events[azure_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_tools_with_capture_message_content_span_events[openai_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[azure_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[openai_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_parallel_tools_and_capture_message_content_span_events[ollama_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_parallel_tools_and_capture_message_content_span_events[openai_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[azure_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[ollama_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[openai_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[azure_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml delete mode 100644 instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[openai_provider_chat_completions].yaml diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md b/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md index 14c68da..021f0e7 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/README.md @@ -27,9 +27,6 @@ opentelemetry-instrument python use_openai.py # You can record more information about prompts as log events by enabling content capture. OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true opentelemetry-instrument python use_openai.py - -# You can record more information about prompts as span events by enabling content capture. -OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true ELASTIC_OTEL_GENAI_EVENTS=span opentelemetry-instrument python use_openai.py ``` Or manual instrumentation: @@ -55,8 +52,7 @@ chat_completion = client.chat.completions.create(model="gpt-4o-mini", messages=m ### Instrumentation specific environment variable configuration -- `ELASTIC_OTEL_GENAI_EVENTS` (default: `span`): when set to `log` exports GenAI events as -log events instead of span events. +None ### Elastic specific semantic conventions diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/__init__.py b/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/__init__.py index 0a9be4c..0f0feb3 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/__init__.py +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/__init__.py @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import logging import os from timeit import default_timer @@ -26,14 +25,12 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap from opentelemetry.instrumentation.openai.environment_variables import ( - ELASTIC_OTEL_GENAI_EVENTS, OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, ) from opentelemetry.instrumentation.openai.helpers import ( _get_embeddings_span_attributes_from_wrapper, _get_event_attributes, _get_span_attributes_from_wrapper, - _message_from_choice, _record_token_usage_metrics, _record_operation_duration_metric, _send_log_events_from_messages, @@ -46,10 +43,6 @@ from opentelemetry.instrumentation.openai.version import __version__ from opentelemetry.instrumentation.openai.wrappers import StreamWrapper from opentelemetry.metrics import get_meter -from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import ( - GEN_AI_COMPLETION, - GEN_AI_PROMPT, -) from opentelemetry.semconv._incubating.metrics.gen_ai_metrics import ( create_gen_ai_client_token_usage, create_gen_ai_client_operation_duration, @@ -86,13 +79,6 @@ def _instrument(self, **kwargs): == "true" ) - # we support 3 values for deciding how to send events: - # - "latest" to match latest semconv, as 1.28.0 it's log - # - "log" to send log events (default) - # - "span" to send span events - genai_events = os.environ.get(ELASTIC_OTEL_GENAI_EVENTS, "latest").lower() - self.event_kind = "span" if genai_events == "span" else "log" - tracer_provider = kwargs.get("tracer_provider") self.tracer = get_tracer( __name__, @@ -165,13 +151,7 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs): if self.capture_message_content: messages = kwargs.get("messages", []) - if self.event_kind == "log": - _send_log_events_from_messages(self.event_logger, messages=messages, attributes=event_attributes) - elif span.is_recording(): - try: - span.add_event(EVENT_GEN_AI_CONTENT_PROMPT, attributes={GEN_AI_PROMPT: json.dumps(messages)}) - except TypeError: - logger.error(f"Failed to serialize {EVENT_GEN_AI_CONTENT_PROMPT}") + _send_log_events_from_messages(self.event_logger, messages=messages, attributes=event_attributes) start_time = default_timer() try: @@ -188,7 +168,6 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs): stream=result, span=span, capture_message_content=self.capture_message_content, - event_kind=self.event_kind, event_attributes=event_attributes, event_logger=self.event_logger, start_time=start_time, @@ -205,19 +184,7 @@ def _chat_completion_wrapper(self, wrapped, instance, args, kwargs): _record_operation_duration_metric(self.operation_duration_metric, span, start_time) if self.capture_message_content: - if self.event_kind == "log": - _send_log_events_from_choices( - self.event_logger, choices=result.choices, attributes=event_attributes - ) - elif span.is_recording(): - # same format as the prompt - completion = [_message_from_choice(choice) for choice in result.choices] - try: - span.add_event( - EVENT_GEN_AI_CONTENT_COMPLETION, attributes={GEN_AI_COMPLETION: json.dumps(completion)} - ) - except TypeError: - logger.error(f"Failed to serialize {EVENT_GEN_AI_CONTENT_COMPLETION}") + _send_log_events_from_choices(self.event_logger, choices=result.choices, attributes=event_attributes) span.end() @@ -239,14 +206,7 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs): ) as span: if self.capture_message_content: messages = kwargs.get("messages", []) - - if self.event_kind == "log": - _send_log_events_from_messages(self.event_logger, messages=messages, attributes=event_attributes) - elif span.is_recording(): - try: - span.add_event(EVENT_GEN_AI_CONTENT_PROMPT, attributes={GEN_AI_PROMPT: json.dumps(messages)}) - except TypeError: - logger.error(f"Failed to serialize {EVENT_GEN_AI_CONTENT_PROMPT}") + _send_log_events_from_messages(self.event_logger, messages=messages, attributes=event_attributes) start_time = default_timer() try: @@ -263,7 +223,6 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs): stream=result, span=span, capture_message_content=self.capture_message_content, - event_kind=self.event_kind, event_attributes=event_attributes, event_logger=self.event_logger, start_time=start_time, @@ -280,19 +239,7 @@ async def _async_chat_completion_wrapper(self, wrapped, instance, args, kwargs): _record_operation_duration_metric(self.operation_duration_metric, span, start_time) if self.capture_message_content: - if self.event_kind == "log": - _send_log_events_from_choices( - self.event_logger, choices=result.choices, attributes=event_attributes - ) - elif span.is_recording(): - # same format as the prompt - completion = [_message_from_choice(choice) for choice in result.choices] - try: - span.add_event( - EVENT_GEN_AI_CONTENT_COMPLETION, attributes={GEN_AI_COMPLETION: json.dumps(completion)} - ) - except TypeError: - logger.error(f"Failed to serialize {EVENT_GEN_AI_CONTENT_COMPLETION}") + _send_log_events_from_choices(self.event_logger, choices=result.choices, attributes=event_attributes) span.end() diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/environment_variables.py b/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/environment_variables.py index 5c02d77..c40b41c 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/environment_variables.py +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/environment_variables.py @@ -15,5 +15,3 @@ # limitations under the License. OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT = "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT" - -ELASTIC_OTEL_GENAI_EVENTS = "ELASTIC_OTEL_GENAI_EVENTS" 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 ddaff52..bf08ade 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 @@ -79,62 +79,6 @@ def _set_embeddings_span_attributes_from_response(span: Span, model: str, usage: span.set_attribute(GEN_AI_USAGE_INPUT_TOKENS, usage.prompt_tokens) -def _message_from_choice(choice): - """Format a choice into a message of the same shape of the prompt""" - if tool_calls := getattr(choice.message, "tool_calls", None): - return { - "role": choice.message.role, - "content": "", - "tool_calls": [ - { - "id": tool_call.id, - "type": tool_call.type, - "function": { - "name": tool_call.function.name, - "arguments": tool_call.function.arguments, - }, - } - for tool_call in tool_calls - ], - } - else: - return {"role": choice.message.role, "content": choice.message.content} - - -def _message_from_stream_choices(choices): - """Format an iterable of choices into a message of the same shape of the prompt""" - messages = {} - tool_calls = {} - for choice in choices: - messages.setdefault(choice.index, {"role": None, "content": ""}) - message = messages[choice.index] - if choice.delta.role: - message["role"] = choice.delta.role - if choice.delta.content: - message["content"] += choice.delta.content - - if choice.delta.tool_calls: - for call in choice.delta.tool_calls: - tool_calls.setdefault(choice.index, {}) - tool_calls[choice.index].setdefault(call.index, {"function": {"arguments": ""}}) - tool_call = tool_calls[choice.index][call.index] - if call.function.arguments: - tool_call["function"]["arguments"] += call.function.arguments - if call.function.name: - tool_call["function"]["name"] = call.function.name - if call.id: - tool_call["id"] = call.id - if call.type: - tool_call["type"] = call.type - - for message_index in tool_calls: - message = messages[message_index] - message["tool_calls"] = [arguments for _, arguments in sorted(tool_calls[message_index].items())] - - # assumes there's only one message - return [message for _, message in sorted(messages.items())][0] - - def _attributes_from_client(client) -> Attributes: span_attributes = {} diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/wrappers.py b/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/wrappers.py index 4321512..7d3d7c5 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/wrappers.py +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/src/opentelemetry/instrumentation/openai/wrappers.py @@ -14,13 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json import logging -from typing import Literal from opentelemetry._events import EventLogger from opentelemetry.instrumentation.openai.helpers import ( - _message_from_stream_choices, _record_token_usage_metrics, _record_operation_duration_metric, _set_span_attributes_from_response, @@ -28,9 +25,6 @@ ) from opentelemetry.metrics import Histogram from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE -from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import ( - GEN_AI_COMPLETION, -) from opentelemetry.trace import Span from opentelemetry.trace.status import StatusCode from opentelemetry.util.types import Attributes @@ -46,7 +40,6 @@ def __init__( stream, span: Span, capture_message_content: bool, - event_kind: Literal["log", "span"], event_attributes: Attributes, event_logger: EventLogger, start_time: float, @@ -56,7 +49,6 @@ def __init__( self.stream = stream self.span = span self.capture_message_content = capture_message_content - self.event_kind = event_kind self.event_attributes = event_attributes self.event_logger = event_logger self.token_usage_metric = token_usage_metric @@ -85,19 +77,9 @@ def end(self, exc=None): _record_token_usage_metrics(self.token_usage_metric, self.span, self.usage) if self.capture_message_content: - if self.event_kind == "log": - _send_log_events_from_stream_choices( - self.event_logger, choices=self.choices, span=self.span, attributes=self.event_attributes - ) - elif self.span.is_recording(): - # same format as the prompt - completion = [_message_from_stream_choices(self.choices)] - try: - self.span.add_event( - EVENT_GEN_AI_CONTENT_COMPLETION, attributes={GEN_AI_COMPLETION: json.dumps(completion)} - ) - except TypeError: - logger.error(f"Failed to serialize {EVENT_GEN_AI_CONTENT_COMPLETION}") + _send_log_events_from_stream_choices( + self.event_logger, choices=self.choices, span=self.span, attributes=self.event_attributes + ) self.span.end() diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[azure_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[azure_provider_chat_completions].yaml deleted file mode 100644 index e1fcb26..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[azure_provider_chat_completions].yaml +++ /dev/null @@ -1,155 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "unused" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - api-key: - - test_azure_api_key - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '133' - content-type: - - application/json - host: - - test.openai.azure.com - user-agent: - - AsyncAzureOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - async:asyncio - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview - response: - body: - string: |- - { - "choices": [ - { - "content_filter_results": { - "hate": { - "filtered": false, - "severity": "safe" - }, - "self_harm": { - "filtered": false, - "severity": "safe" - }, - "sexual": { - "filtered": false, - "severity": "safe" - }, - "violence": { - "filtered": false, - "severity": "safe" - } - }, - "finish_reason": "stop", - "index": 0, - "logprobs": null, - "message": { - "content": "Atlantic Ocean", - "role": "assistant" - } - } - ], - "created": 1731468960, - "id": "chatcmpl-ASySeHu4TgKtlulOVp4LU8yTNRvoM", - "model": "gpt-4-32k", - "object": "chat.completion", - "prompt_filter_results": [ - { - "prompt_index": 0, - "content_filter_results": { - "hate": { - "filtered": false, - "severity": "safe" - }, - "self_harm": { - "filtered": false, - "severity": "safe" - }, - "sexual": { - "filtered": false, - "severity": "safe" - }, - "violence": { - "filtered": false, - "severity": "safe" - } - } - } - ], - "system_fingerprint": null, - "usage": { - "completion_tokens": 2, - "prompt_tokens": 24, - "total_tokens": 26 - } - } - headers: - Cache-Control: - - no-cache, must-revalidate - Content-Length: - - '805' - Content-Type: - - application/json - Date: - - Wed, 13 Nov 2024 03:36:00 GMT - Set-Cookie: test_set_cookie - Strict-Transport-Security: - - max-age=31536000; includeSubDomains; preload - access-control-allow-origin: - - '*' - apim-request-id: - - 38407302-010e-4318-8ba2-cd1c61e474c5 - azureml-model-session: - - d156-20241010120317 - openai-organization: test_openai_org_id - x-accel-buffering: - - 'no' - x-content-type-options: - - nosniff - x-ms-client-request-id: - - 38407302-010e-4318-8ba2-cd1c61e474c5 - x-ms-rai-invoked: - - 'true' - x-ms-region: - - Switzerland North - x-ratelimit-remaining-requests: - - '79' - x-ratelimit-remaining-tokens: - - '79968' - x-request-id: - - 3910c5ca-854a-481d-b76c-e4140883c952 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml deleted file mode 100644 index b2e071a..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml +++ /dev/null @@ -1,85 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "qwen2.5:0.5b" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '139' - content-type: - - application/json - host: - - localhost:11434 - user-agent: - - AsyncOpenAI/Python 1.50.2 - x-stainless-arch: - - arm64 - x-stainless-async: - - async:asyncio - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.50.2 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: http://localhost:11434/v1/chat/completions - response: - body: - string: |- - { - "id": "chatcmpl-816", - "object": "chat.completion", - "created": 1731311784, - "model": "qwen2.5:0.5b", - "system_fingerprint": "fp_ollama", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": "Antarctica ocean." - }, - "finish_reason": "stop" - } - ], - "usage": { - "prompt_tokens": 46, - "completion_tokens": 6, - "total_tokens": 52 - } - } - headers: - Content-Length: - - '303' - Content-Type: - - application/json - Date: - - Mon, 11 Nov 2024 07:56:24 GMT - Set-Cookie: test_set_cookie - openai-organization: test_openai_org_key - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[openai_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[openai_provider_chat_completions].yaml deleted file mode 100644 index 6998876..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_basic_with_capture_message_content_span_events[openai_provider_chat_completions].yaml +++ /dev/null @@ -1,133 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "gpt-4o-mini" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '138' - content-type: - - application/json - host: - - api.openai.com - user-agent: - - AsyncOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - async:asyncio - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://api.openai.com/v1/chat/completions - response: - body: - string: |- - { - "id": "chatcmpl-ASfaOHHT6qOYpFc5M7uzSkgfXnnpJ", - "object": "chat.completion", - "created": 1731396404, - "model": "gpt-4o-mini-2024-07-18", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": "South Atlantic Ocean.", - "refusal": null - }, - "logprobs": null, - "finish_reason": "stop" - } - ], - "usage": { - "prompt_tokens": 24, - "completion_tokens": 4, - "total_tokens": 28, - "prompt_tokens_details": { - "cached_tokens": 0, - "audio_tokens": 0 - }, - "completion_tokens_details": { - "reasoning_tokens": 0, - "audio_tokens": 0, - "accepted_prediction_tokens": 0, - "rejected_prediction_tokens": 0 - } - }, - "system_fingerprint": "fp_0ba0d124f1" - } - headers: - CF-Cache-Status: - - DYNAMIC - CF-RAY: - - 8e14cba439f0ce22-SIN - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Tue, 12 Nov 2024 07:26:44 GMT - Server: - - cloudflare - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - X-Content-Type-Options: - - nosniff - access-control-expose-headers: - - X-Request-ID - alt-svc: - - h3=":443"; ma=86400 - content-length: - - '771' - openai-organization: test_openai_org_key - openai-processing-ms: - - '213' - openai-version: - - '2020-10-01' - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-ratelimit-limit-requests: - - '10000' - x-ratelimit-limit-tokens: - - '200000' - x-ratelimit-remaining-requests: - - '9984' - x-ratelimit-remaining-tokens: - - '199966' - x-ratelimit-reset-requests: - - 2m17.802s - x-ratelimit-reset-tokens: - - 10ms - x-request-id: - - req_e6b1a7306539cbcad166c1907ae46d4f - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[azure_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[azure_provider_chat_completions].yaml deleted file mode 100644 index ead3805..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[azure_provider_chat_completions].yaml +++ /dev/null @@ -1,104 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "unused", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - api-key: - - test_azure_api_key - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '149' - content-type: - - application/json - host: - - test.openai.azure.com - user-agent: - - AsyncAzureOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - async:asyncio - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview - response: - body: - string: |+ - data: {"choices":[],"created":0,"id":"","model":"","object":"","prompt_filter_results":[{"prompt_index":0,"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}}}]} - - data: {"choices":[{"content_filter_results":{},"delta":{"content":"","role":"assistant"},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466223,"id":"chatcmpl-ASxkVWhWg2yeY7IV8yr6Lywa7fke4","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":"Atlantic"},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466223,"id":"chatcmpl-ASxkVWhWg2yeY7IV8yr6Lywa7fke4","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":" Ocean"},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466223,"id":"chatcmpl-ASxkVWhWg2yeY7IV8yr6Lywa7fke4","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{},"finish_reason":"stop","index":0,"logprobs":null}],"created":1731466223,"id":"chatcmpl-ASxkVWhWg2yeY7IV8yr6Lywa7fke4","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: [DONE] - - headers: - Cache-Control: - - no-cache, must-revalidate - Content-Type: - - text/event-stream - Date: - - Wed, 13 Nov 2024 02:50:23 GMT - Set-Cookie: test_set_cookie - Strict-Transport-Security: - - max-age=31536000; includeSubDomains; preload - Transfer-Encoding: - - chunked - access-control-allow-origin: - - '*' - apim-request-id: - - 32da387e-289d-4876-8d37-adc936ab09da - azureml-model-session: - - d156-20241010120317 - openai-organization: test_openai_org_id - x-accel-buffering: - - 'no' - x-content-type-options: - - nosniff - x-ms-client-request-id: - - 32da387e-289d-4876-8d37-adc936ab09da - x-ms-rai-invoked: - - 'true' - x-ms-region: - - Switzerland North - x-ratelimit-remaining-requests: - - '71' - x-ratelimit-remaining-tokens: - - '79612' - x-request-id: - - 132f6f5c-067a-47e2-bc7d-79aa543876b4 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml deleted file mode 100644 index f13de93..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml +++ /dev/null @@ -1,80 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "qwen2.5:0.5b", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '155' - content-type: - - application/json - host: - - localhost:11434 - user-agent: - - AsyncOpenAI/Python 1.50.2 - x-stainless-arch: - - arm64 - x-stainless-async: - - async:asyncio - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.50.2 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: http://localhost:11434/v1/chat/completions - response: - body: - string: |+ - data: {"id":"chatcmpl-752","object":"chat.completion.chunk","created":1731311784,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"South"},"finish_reason":null}]} - - data: {"id":"chatcmpl-752","object":"chat.completion.chunk","created":1731311784,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" America"},"finish_reason":null}]} - - data: {"id":"chatcmpl-752","object":"chat.completion.chunk","created":1731311784,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"'s"},"finish_reason":null}]} - - data: {"id":"chatcmpl-752","object":"chat.completion.chunk","created":1731311784,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" Atlantic"},"finish_reason":null}]} - - data: {"id":"chatcmpl-752","object":"chat.completion.chunk","created":1731311784,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" Ocean"},"finish_reason":null}]} - - data: {"id":"chatcmpl-752","object":"chat.completion.chunk","created":1731311784,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"."},"finish_reason":null}]} - - data: {"id":"chatcmpl-752","object":"chat.completion.chunk","created":1731311784,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}]} - - data: [DONE] - - headers: - Content-Type: - - text/event-stream - Date: - - Mon, 11 Nov 2024 07:56:24 GMT - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - openai-organization: test_openai_org_key - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[openai_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[openai_provider_chat_completions].yaml deleted file mode 100644 index 5cc7e03..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_stream_with_capture_message_content_span_events[openai_provider_chat_completions].yaml +++ /dev/null @@ -1,112 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "gpt-4o-mini", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '154' - content-type: - - application/json - host: - - api.openai.com - user-agent: - - AsyncOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - async:asyncio - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://api.openai.com/v1/chat/completions - response: - body: - string: |+ - data: {"id":"chatcmpl-ASfaPHhHlSFtYDMa1S0QSWewTPhuS","object":"chat.completion.chunk","created":1731396405,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"role":"assistant","content":"","refusal":null},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaPHhHlSFtYDMa1S0QSWewTPhuS","object":"chat.completion.chunk","created":1731396405,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"content":"South"},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaPHhHlSFtYDMa1S0QSWewTPhuS","object":"chat.completion.chunk","created":1731396405,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"content":" Atlantic"},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaPHhHlSFtYDMa1S0QSWewTPhuS","object":"chat.completion.chunk","created":1731396405,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"content":" Ocean"},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaPHhHlSFtYDMa1S0QSWewTPhuS","object":"chat.completion.chunk","created":1731396405,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"content":"."},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaPHhHlSFtYDMa1S0QSWewTPhuS","object":"chat.completion.chunk","created":1731396405,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]} - - data: [DONE] - - headers: - CF-Cache-Status: - - DYNAMIC - CF-RAY: - - 8e14cbaf8f6d49b4-SIN - Connection: - - keep-alive - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 12 Nov 2024 07:26:46 GMT - Server: - - cloudflare - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - X-Content-Type-Options: - - nosniff - access-control-expose-headers: - - X-Request-ID - alt-svc: - - h3=":443"; ma=86400 - openai-organization: test_openai_org_key - openai-processing-ms: - - '203' - openai-version: - - '2020-10-01' - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-ratelimit-limit-requests: - - '10000' - x-ratelimit-limit-tokens: - - '200000' - x-ratelimit-remaining-requests: - - '9981' - x-ratelimit-remaining-tokens: - - '199966' - x-ratelimit-reset-requests: - - 2m41.915s - x-ratelimit-reset-tokens: - - 10ms - x-request-id: - - req_cdcc4e2158d7bd20d7769f8ed24a54a1 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_tools_with_capture_message_content_span_events[azure_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_tools_with_capture_message_content_span_events[azure_provider_chat_completions].yaml deleted file mode 100644 index 5044176..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_tools_with_capture_message_content_span_events[azure_provider_chat_completions].yaml +++ /dev/null @@ -1,182 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user." - }, - { - "role": "user", - "content": "Hi, can you tell me the delivery date for my order?" - }, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?" - }, - { - "role": "user", - "content": "i think it is order_12345" - } - ], - "model": "unused", - "tools": [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID." - } - }, - "required": [ - "order_id" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - api-key: - - test_azure_api_key - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '837' - content-type: - - application/json - host: - - test.openai.azure.com - user-agent: - - AsyncAzureOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - async:asyncio - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview - response: - body: - string: |- - { - "choices": [ - { - "content_filter_results": {}, - "finish_reason": "tool_calls", - "index": 0, - "logprobs": null, - "message": { - "content": null, - "role": "assistant", - "tool_calls": [ - { - "function": { - "arguments": "{\n \"order_id\": \"order_12345\"\n}", - "name": "get_delivery_date" - }, - "id": "call_Lm5cpl4sJy5b1FfEjsnbbjlL", - "type": "function" - } - ] - } - } - ], - "created": 1731466225, - "id": "chatcmpl-ASxkX3IDac2dYI6AB8L4iA7SJaNii", - "model": "gpt-4-32k", - "object": "chat.completion", - "prompt_filter_results": [ - { - "prompt_index": 0, - "content_filter_results": { - "hate": { - "filtered": false, - "severity": "safe" - }, - "self_harm": { - "filtered": false, - "severity": "safe" - }, - "sexual": { - "filtered": false, - "severity": "safe" - }, - "violence": { - "filtered": false, - "severity": "safe" - } - } - } - ], - "system_fingerprint": null, - "usage": { - "completion_tokens": 20, - "prompt_tokens": 144, - "total_tokens": 164 - } - } - headers: - Cache-Control: - - no-cache, must-revalidate - Content-Length: - - '780' - Content-Type: - - application/json - Date: - - Wed, 13 Nov 2024 02:50:25 GMT - Set-Cookie: test_set_cookie - Strict-Transport-Security: - - max-age=31536000; includeSubDomains; preload - access-control-allow-origin: - - '*' - apim-request-id: - - d0d1d8a8-c031-48c8-b8f5-20fa4a9789ed - azureml-model-session: - - d160-20241010151341 - openai-organization: test_openai_org_id - x-accel-buffering: - - 'no' - x-content-type-options: - - nosniff - x-ms-client-request-id: - - d0d1d8a8-c031-48c8-b8f5-20fa4a9789ed - x-ms-rai-invoked: - - 'true' - x-ms-region: - - Switzerland North - x-ratelimit-remaining-requests: - - '71' - x-ratelimit-remaining-tokens: - - '79580' - x-request-id: - - 14c4426a-d72d-4c3c-aa90-5026d7d7e314 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_tools_with_capture_message_content_span_events[openai_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_tools_with_capture_message_content_span_events[openai_provider_chat_completions].yaml deleted file mode 100644 index 914e6e8..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_async_tools_with_capture_message_content_span_events[openai_provider_chat_completions].yaml +++ /dev/null @@ -1,177 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user." - }, - { - "role": "user", - "content": "Hi, can you tell me the delivery date for my order?" - }, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?" - }, - { - "role": "user", - "content": "i think it is order_12345" - } - ], - "model": "gpt-4o-mini", - "tools": [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID." - } - }, - "required": [ - "order_id" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '842' - content-type: - - application/json - host: - - api.openai.com - user-agent: - - AsyncOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - async:asyncio - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://api.openai.com/v1/chat/completions - response: - body: - string: |- - { - "id": "chatcmpl-ASfaRyXEFFt9GzMooIy1bDXqjYnWV", - "object": "chat.completion", - "created": 1731396407, - "model": "gpt-4o-mini-2024-07-18", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": null, - "tool_calls": [ - { - "id": "call_fW4XFpzxFZ7Rfj5dsDcZTezg", - "type": "function", - "function": { - "name": "get_delivery_date", - "arguments": "{\"order_id\":\"order_12345\"}" - } - } - ], - "refusal": null - }, - "logprobs": null, - "finish_reason": "tool_calls" - } - ], - "usage": { - "prompt_tokens": 140, - "completion_tokens": 19, - "total_tokens": 159, - "prompt_tokens_details": { - "cached_tokens": 0, - "audio_tokens": 0 - }, - "completion_tokens_details": { - "reasoning_tokens": 0, - "audio_tokens": 0, - "accepted_prediction_tokens": 0, - "rejected_prediction_tokens": 0 - } - }, - "system_fingerprint": "fp_0ba0d124f1" - } - headers: - CF-Cache-Status: - - DYNAMIC - CF-RAY: - - 8e14cbb9deeb49d2-SIN - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Tue, 12 Nov 2024 07:26:48 GMT - Server: - - cloudflare - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - X-Content-Type-Options: - - nosniff - access-control-expose-headers: - - X-Request-ID - alt-svc: - - h3=":443"; ma=86400 - content-length: - - '1046' - openai-organization: test_openai_org_key - openai-processing-ms: - - '711' - openai-version: - - '2020-10-01' - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-ratelimit-limit-requests: - - '10000' - x-ratelimit-limit-tokens: - - '200000' - x-ratelimit-remaining-requests: - - '9979' - x-ratelimit-remaining-tokens: - - '199921' - x-ratelimit-reset-requests: - - 2m57.53s - x-ratelimit-reset-tokens: - - 23ms - x-request-id: - - req_fb7b2d2cbb3f604371ed39bd6692351b - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[azure_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[azure_provider_chat_completions].yaml deleted file mode 100644 index 62e5895..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[azure_provider_chat_completions].yaml +++ /dev/null @@ -1,155 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "unused" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - api-key: - - test_azure_api_key - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '133' - content-type: - - application/json - host: - - test.openai.azure.com - user-agent: - - AzureOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview - response: - body: - string: |- - { - "choices": [ - { - "content_filter_results": { - "hate": { - "filtered": false, - "severity": "safe" - }, - "self_harm": { - "filtered": false, - "severity": "safe" - }, - "sexual": { - "filtered": false, - "severity": "safe" - }, - "violence": { - "filtered": false, - "severity": "safe" - } - }, - "finish_reason": "stop", - "index": 0, - "logprobs": null, - "message": { - "content": "Atlantic Ocean", - "role": "assistant" - } - } - ], - "created": 1731466210, - "id": "chatcmpl-ASxkIgV0VKpWeEuyJHsem9UEl4fAt", - "model": "gpt-4-32k", - "object": "chat.completion", - "prompt_filter_results": [ - { - "prompt_index": 0, - "content_filter_results": { - "hate": { - "filtered": false, - "severity": "safe" - }, - "self_harm": { - "filtered": false, - "severity": "safe" - }, - "sexual": { - "filtered": false, - "severity": "safe" - }, - "violence": { - "filtered": false, - "severity": "safe" - } - } - } - ], - "system_fingerprint": null, - "usage": { - "completion_tokens": 2, - "prompt_tokens": 24, - "total_tokens": 26 - } - } - headers: - Cache-Control: - - no-cache, must-revalidate - Content-Length: - - '805' - Content-Type: - - application/json - Date: - - Wed, 13 Nov 2024 02:50:10 GMT - Set-Cookie: test_set_cookie - Strict-Transport-Security: - - max-age=31536000; includeSubDomains; preload - access-control-allow-origin: - - '*' - apim-request-id: - - 47b7e79e-0daf-4994-83c4-a9d0217af3b7 - azureml-model-session: - - d161-20241010160330 - openai-organization: test_openai_org_id - x-accel-buffering: - - 'no' - x-content-type-options: - - nosniff - x-ms-client-request-id: - - 47b7e79e-0daf-4994-83c4-a9d0217af3b7 - x-ms-rai-invoked: - - 'true' - x-ms-region: - - Switzerland North - x-ratelimit-remaining-requests: - - '73' - x-ratelimit-remaining-tokens: - - '79788' - x-request-id: - - 3d6bc529-270c-4ee1-b864-752625329806 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml deleted file mode 100644 index 4f57f6c..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml +++ /dev/null @@ -1,85 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "qwen2.5:0.5b" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '139' - content-type: - - application/json - host: - - localhost:11434 - user-agent: - - OpenAI/Python 1.50.2 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.50.2 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: http://localhost:11434/v1/chat/completions - response: - body: - string: |- - { - "id": "chatcmpl-433", - "object": "chat.completion", - "created": 1731311782, - "model": "qwen2.5:0.5b", - "system_fingerprint": "fp_ollama", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": "The Atlantic Ocean." - }, - "finish_reason": "stop" - } - ], - "usage": { - "prompt_tokens": 46, - "completion_tokens": 5, - "total_tokens": 51 - } - } - headers: - Content-Length: - - '305' - Content-Type: - - application/json - Date: - - Mon, 11 Nov 2024 07:56:22 GMT - Set-Cookie: test_set_cookie - openai-organization: test_openai_org_key - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[openai_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[openai_provider_chat_completions].yaml deleted file mode 100644 index b1e1c2a..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_basic_with_capture_message_content_span_events[openai_provider_chat_completions].yaml +++ /dev/null @@ -1,133 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?" - } - ], - "model": "gpt-4o-mini" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '138' - content-type: - - application/json - host: - - api.openai.com - user-agent: - - OpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://api.openai.com/v1/chat/completions - response: - body: - string: |- - { - "id": "chatcmpl-ASfaC6FMNUKWFqBJmf9rmRluWyRAF", - "object": "chat.completion", - "created": 1731396392, - "model": "gpt-4o-mini-2024-07-18", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": "South Atlantic Ocean.", - "refusal": null - }, - "logprobs": null, - "finish_reason": "stop" - } - ], - "usage": { - "prompt_tokens": 24, - "completion_tokens": 4, - "total_tokens": 28, - "prompt_tokens_details": { - "cached_tokens": 0, - "audio_tokens": 0 - }, - "completion_tokens_details": { - "reasoning_tokens": 0, - "audio_tokens": 0, - "accepted_prediction_tokens": 0, - "rejected_prediction_tokens": 0 - } - }, - "system_fingerprint": "fp_9b78b61c52" - } - headers: - CF-Cache-Status: - - DYNAMIC - CF-RAY: - - 8e14cb5db8012eb6-SIN - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Tue, 12 Nov 2024 07:26:33 GMT - Server: - - cloudflare - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - X-Content-Type-Options: - - nosniff - access-control-expose-headers: - - X-Request-ID - alt-svc: - - h3=":443"; ma=86400 - content-length: - - '771' - openai-organization: test_openai_org_key - openai-processing-ms: - - '386' - openai-version: - - '2020-10-01' - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-ratelimit-limit-requests: - - '10000' - x-ratelimit-limit-tokens: - - '200000' - x-ratelimit-remaining-requests: - - '9993' - x-ratelimit-remaining-tokens: - - '199966' - x-ratelimit-reset-requests: - - 54.04s - x-ratelimit-reset-tokens: - - 10ms - x-request-id: - - req_3e642cdb3e05072702a405418b9d3455 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_parallel_tools_and_capture_message_content_span_events[ollama_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_parallel_tools_and_capture_message_content_span_events[ollama_provider_chat_completions].yaml deleted file mode 100644 index ac300a7..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_parallel_tools_and_capture_message_content_span_events[ollama_provider_chat_completions].yaml +++ /dev/null @@ -1,175 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful assistant providing weather updates." - }, - { - "role": "user", - "content": "What is the weather in New York City and London?" - } - ], - "model": "qwen2.5:0.5b", - "stream": true, - "tools": [ - { - "type": "function", - "function": { - "name": "get_weather", - "strict": true, - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string" - } - }, - "required": [ - "location" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '450' - content-type: - - application/json - host: - - localhost:11434 - user-agent: - - OpenAI/Python 1.50.2 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.50.2 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: http://localhost:11434/v1/chat/completions - response: - body: - string: |+ - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\u003ctool_call\u003e"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\n"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"{\""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"name"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"get"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"_weather"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\","},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"arguments"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" {\""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"location"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"New"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" York"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" City"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\"}}\n"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\u003c/tool_call\u003e"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\n"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\u003ctool_call\u003e"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\n"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"{\""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"name"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"get"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"_weather"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\","},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"arguments"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" {\""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"location"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"London"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\"}}\n"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\u003c/tool_call\u003e"},"finish_reason":null}]} - - data: {"id":"chatcmpl-918","object":"chat.completion.chunk","created":1731311783,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}]} - - data: [DONE] - - headers: - Content-Type: - - text/event-stream - Date: - - Mon, 11 Nov 2024 07:56:23 GMT - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - openai-organization: test_openai_org_key - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_parallel_tools_and_capture_message_content_span_events[openai_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_parallel_tools_and_capture_message_content_span_events[openai_provider_chat_completions].yaml deleted file mode 100644 index a557c38..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_parallel_tools_and_capture_message_content_span_events[openai_provider_chat_completions].yaml +++ /dev/null @@ -1,155 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful assistant providing weather updates." - }, - { - "role": "user", - "content": "What is the weather in New York City and London?" - } - ], - "model": "gpt-4o-mini", - "stream": true, - "tools": [ - { - "type": "function", - "function": { - "name": "get_weather", - "strict": true, - "parameters": { - "type": "object", - "properties": { - "location": { - "type": "string" - } - }, - "required": [ - "location" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '449' - content-type: - - application/json - host: - - api.openai.com - user-agent: - - OpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://api.openai.com/v1/chat/completions - response: - body: - string: |+ - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"role":"assistant","content":null},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"call_awpPik83NVMEmnWIARc49DVf","type":"function","function":{"name":"get_weather","arguments":""}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\"lo"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"catio"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"n\": \"N"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"ew Y"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"ork C"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"ity\"}"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":1,"id":"call_LPkfKwdcq3Tqg06fTFVIDcV5","type":"function","function":{"name":"get_weather","arguments":""}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":1,"function":{"arguments":"{\"lo"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":1,"function":{"arguments":"catio"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":1,"function":{"arguments":"n\": \"L"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":1,"function":{"arguments":"ondo"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":1,"function":{"arguments":"n\"}"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7","object":"chat.completion.chunk","created":1731396397,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"tool_calls"}]} - - data: [DONE] - - headers: - CF-Cache-Status: - - DYNAMIC - CF-RAY: - - 8e14cb7bcd51ce22-SIN - Connection: - - keep-alive - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 12 Nov 2024 07:26:38 GMT - Server: - - cloudflare - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - X-Content-Type-Options: - - nosniff - access-control-expose-headers: - - X-Request-ID - alt-svc: - - h3=":443"; ma=86400 - openai-organization: test_openai_org_key - openai-processing-ms: - - '1268' - openai-version: - - '2020-10-01' - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-ratelimit-limit-requests: - - '10000' - x-ratelimit-limit-tokens: - - '200000' - x-ratelimit-remaining-requests: - - '9988' - x-ratelimit-remaining-tokens: - - '199956' - x-ratelimit-reset-requests: - - 1m41.081s - x-ratelimit-reset-tokens: - - 13ms - x-request-id: - - req_b2971ad760eb9f1fb8ec7bc289fba757 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[azure_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[azure_provider_chat_completions].yaml deleted file mode 100644 index 2de43cc..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[azure_provider_chat_completions].yaml +++ /dev/null @@ -1,160 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user." - }, - { - "role": "user", - "content": "Hi, can you tell me the delivery date for my order?" - }, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?" - }, - { - "role": "user", - "content": "i think it is order_12345" - } - ], - "model": "unused", - "stream": true, - "tools": [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID." - } - }, - "required": [ - "order_id" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - api-key: - - test_azure_api_key - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '853' - content-type: - - application/json - host: - - test.openai.azure.com - user-agent: - - AzureOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview - response: - body: - string: |+ - data: {"choices":[],"created":0,"id":"","model":"","object":"","prompt_filter_results":[{"prompt_index":0,"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}}}]} - - data: {"choices":[{"content_filter_results":{},"delta":{"content":null,"role":"assistant","tool_calls":[{"function":{"arguments":"","name":"get_delivery_date"},"id":"call_hR2GEOnGJhmLsHHsMgfLuICf","index":0,"type":"function"}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"{\n"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":" "},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":" \""},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"order"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"_id"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"\":"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":" \""},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"order"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"_"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"123"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"45"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"\"\n"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{"tool_calls":[{"function":{"arguments":"}"},"index":0}]},"finish_reason":null,"index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: {"choices":[{"content_filter_results":{},"delta":{},"finish_reason":"tool_calls","index":0,"logprobs":null}],"created":1731466214,"id":"chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr","model":"gpt-4-32k","object":"chat.completion.chunk","system_fingerprint":null} - - data: [DONE] - - headers: - Cache-Control: - - no-cache, must-revalidate - Content-Type: - - text/event-stream - Date: - - Wed, 13 Nov 2024 02:50:14 GMT - Set-Cookie: test_set_cookie - Strict-Transport-Security: - - max-age=31536000; includeSubDomains; preload - Transfer-Encoding: - - chunked - access-control-allow-origin: - - '*' - apim-request-id: - - 0fd69d8a-a962-41e2-afe5-61f4a011d059 - azureml-model-session: - - d156-20241010120317 - openai-organization: test_openai_org_id - x-accel-buffering: - - 'no' - x-content-type-options: - - nosniff - x-ms-client-request-id: - - 0fd69d8a-a962-41e2-afe5-61f4a011d059 - x-ms-rai-invoked: - - 'true' - x-ms-region: - - Switzerland North - x-ratelimit-remaining-requests: - - '72' - x-ratelimit-remaining-tokens: - - '79724' - x-request-id: - - 947b357e-4e8f-41f6-a941-1e5390c3e7b0 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[ollama_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[ollama_provider_chat_completions].yaml deleted file mode 100644 index 429d402..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[ollama_provider_chat_completions].yaml +++ /dev/null @@ -1,156 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user." - }, - { - "role": "user", - "content": "Hi, can you tell me the delivery date for my order?" - }, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?" - }, - { - "role": "user", - "content": "i think it is order_12345" - } - ], - "model": "qwen2.5:0.5b", - "stream": true, - "tools": [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID." - } - }, - "required": [ - "order_id" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '859' - content-type: - - application/json - host: - - localhost:11434 - user-agent: - - OpenAI/Python 1.50.2 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.50.2 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: http://localhost:11434/v1/chat/completions - response: - body: - string: |+ - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\u003ctool_call\u003e"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\n"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"{\""},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"name"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"get"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"_delivery"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"_date"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\","},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"arguments"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" {\""},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"order"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"_id"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\":"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":" \""},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"order"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"_"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"1"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"2"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"3"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"4"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"5"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\"}}\n"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":"\u003c/tool_call\u003e"},"finish_reason":null}]} - - data: {"id":"chatcmpl-268","object":"chat.completion.chunk","created":1731311782,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}]} - - data: [DONE] - - headers: - Content-Type: - - text/event-stream - Date: - - Mon, 11 Nov 2024 07:56:22 GMT - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - openai-organization: test_openai_org_key - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[openai_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[openai_provider_chat_completions].yaml deleted file mode 100644 index 15be4e5..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_stream_with_tools_and_capture_message_content_span_events[openai_provider_chat_completions].yaml +++ /dev/null @@ -1,156 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user." - }, - { - "role": "user", - "content": "Hi, can you tell me the delivery date for my order?" - }, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?" - }, - { - "role": "user", - "content": "i think it is order_12345" - } - ], - "model": "gpt-4o-mini", - "stream": true, - "tools": [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID." - } - }, - "required": [ - "order_id" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '858' - content-type: - - application/json - host: - - api.openai.com - user-agent: - - OpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://api.openai.com/v1/chat/completions - response: - body: - string: |+ - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"role":"assistant","content":null,"tool_calls":[{"index":0,"id":"call_RlWXV8zAJhzxsh6JqMHY0HbV","type":"function","function":{"name":"get_delivery_date","arguments":""}}],"refusal":null},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\""}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"order"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"_id"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"\":\""}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"order"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"_"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"123"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"45"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"\"}"}}]},"logprobs":null,"finish_reason":null}]} - - data: {"id":"chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX","object":"chat.completion.chunk","created":1731396395,"model":"gpt-4o-mini-2024-07-18","system_fingerprint":"fp_0ba0d124f1","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"tool_calls"}]} - - data: [DONE] - - headers: - CF-Cache-Status: - - DYNAMIC - CF-RAY: - - 8e14cb707e5f81e4-SIN - Connection: - - keep-alive - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 12 Nov 2024 07:26:36 GMT - Server: - - cloudflare - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - X-Content-Type-Options: - - nosniff - access-control-expose-headers: - - X-Request-ID - alt-svc: - - h3=":443"; ma=86400 - openai-organization: test_openai_org_key - openai-processing-ms: - - '328' - openai-version: - - '2020-10-01' - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-ratelimit-limit-requests: - - '10000' - x-ratelimit-limit-tokens: - - '200000' - x-ratelimit-remaining-requests: - - '9990' - x-ratelimit-remaining-tokens: - - '199921' - x-ratelimit-reset-requests: - - 1m25.566s - x-ratelimit-reset-tokens: - - 23ms - x-request-id: - - req_a4c989b5de9332354762cf40ddf1c95a - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[azure_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[azure_provider_chat_completions].yaml deleted file mode 100644 index 41384c7..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[azure_provider_chat_completions].yaml +++ /dev/null @@ -1,182 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user." - }, - { - "role": "user", - "content": "Hi, can you tell me the delivery date for my order?" - }, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?" - }, - { - "role": "user", - "content": "i think it is order_12345" - } - ], - "model": "unused", - "tools": [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID." - } - }, - "required": [ - "order_id" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - api-key: - - test_azure_api_key - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '837' - content-type: - - application/json - host: - - test.openai.azure.com - user-agent: - - AzureOpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview - response: - body: - string: |- - { - "choices": [ - { - "content_filter_results": {}, - "finish_reason": "tool_calls", - "index": 0, - "logprobs": null, - "message": { - "content": null, - "role": "assistant", - "tool_calls": [ - { - "function": { - "arguments": "{\n \"order_id\": \"order_12345\"\n}", - "name": "get_delivery_date" - }, - "id": "call_hR2GEOnGJhmLsHHsMgfLuICf", - "type": "function" - } - ] - } - } - ], - "created": 1731466206, - "id": "chatcmpl-ASxkERPeCSyiDvA8jyN5dhIpAYryd", - "model": "gpt-4-32k", - "object": "chat.completion", - "prompt_filter_results": [ - { - "prompt_index": 0, - "content_filter_results": { - "hate": { - "filtered": false, - "severity": "safe" - }, - "self_harm": { - "filtered": false, - "severity": "safe" - }, - "sexual": { - "filtered": false, - "severity": "safe" - }, - "violence": { - "filtered": false, - "severity": "safe" - } - } - } - ], - "system_fingerprint": null, - "usage": { - "completion_tokens": 20, - "prompt_tokens": 144, - "total_tokens": 164 - } - } - headers: - Cache-Control: - - no-cache, must-revalidate - Content-Length: - - '780' - Content-Type: - - application/json - Date: - - Wed, 13 Nov 2024 02:50:07 GMT - Set-Cookie: test_set_cookie - Strict-Transport-Security: - - max-age=31536000; includeSubDomains; preload - access-control-allow-origin: - - '*' - apim-request-id: - - 9284d670-be85-4101-8dde-1647df437da9 - azureml-model-session: - - d156-20241010120317 - openai-organization: test_openai_org_id - x-accel-buffering: - - 'no' - x-content-type-options: - - nosniff - x-ms-client-request-id: - - 9284d670-be85-4101-8dde-1647df437da9 - x-ms-rai-invoked: - - 'true' - x-ms-region: - - Switzerland North - x-ratelimit-remaining-requests: - - '75' - x-ratelimit-remaining-tokens: - - '79820' - x-request-id: - - c6bbd315-92fa-4d9e-a832-d1cfc9fc0bb2 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml deleted file mode 100644 index 853d15e..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[ollama_provider_chat_completions].yaml +++ /dev/null @@ -1,129 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user." - }, - { - "role": "user", - "content": "Hi, can you tell me the delivery date for my order?" - }, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?" - }, - { - "role": "user", - "content": "i think it is order_12345" - } - ], - "model": "qwen2.5:0.5b", - "tools": [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID." - } - }, - "required": [ - "order_id" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '843' - content-type: - - application/json - host: - - localhost:11434 - user-agent: - - OpenAI/Python 1.50.2 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.50.2 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: http://localhost:11434/v1/chat/completions - response: - body: - string: |- - { - "id": "chatcmpl-705", - "object": "chat.completion", - "created": 1731311780, - "model": "qwen2.5:0.5b", - "system_fingerprint": "fp_ollama", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": "", - "tool_calls": [ - { - "id": "call_u9zt4jf1", - "type": "function", - "function": { - "name": "get_delivery_date", - "arguments": "{\"order_id\":\"order_12345\"}" - } - } - ] - }, - "finish_reason": "tool_calls" - } - ], - "usage": { - "prompt_tokens": 241, - "completion_tokens": 28, - "total_tokens": 269 - } - } - headers: - Content-Length: - - '436' - Content-Type: - - application/json - Date: - - Mon, 11 Nov 2024 07:56:20 GMT - Set-Cookie: test_set_cookie - openai-organization: test_openai_org_key - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[openai_provider_chat_completions].yaml b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[openai_provider_chat_completions].yaml deleted file mode 100644 index c520076..0000000 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/cassettes/.test_chat_completions/test_tools_with_capture_message_content_span_events[openai_provider_chat_completions].yaml +++ /dev/null @@ -1,177 +0,0 @@ -interactions: -- request: - body: |- - { - "messages": [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user." - }, - { - "role": "user", - "content": "Hi, can you tell me the delivery date for my order?" - }, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?" - }, - { - "role": "user", - "content": "i think it is order_12345" - } - ], - "model": "gpt-4o-mini", - "tools": [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID." - } - }, - "required": [ - "order_id" - ], - "additionalProperties": false - } - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - authorization: - - Bearer test_openai_api_key - connection: - - keep-alive - content-length: - - '842' - content-type: - - application/json - host: - - api.openai.com - user-agent: - - OpenAI/Python 1.54.3 - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 1.54.3 - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.12.6 - method: POST - uri: https://api.openai.com/v1/chat/completions - response: - body: - string: |- - { - "id": "chatcmpl-ASfa9bDXRwPIhzm7t58LNXJLZnBgC", - "object": "chat.completion", - "created": 1731396389, - "model": "gpt-4o-mini-2024-07-18", - "choices": [ - { - "index": 0, - "message": { - "role": "assistant", - "content": null, - "tool_calls": [ - { - "id": "call_QerODwH75OIstmsLXRkCOy4X", - "type": "function", - "function": { - "name": "get_delivery_date", - "arguments": "{\"order_id\":\"order_12345\"}" - } - } - ], - "refusal": null - }, - "logprobs": null, - "finish_reason": "tool_calls" - } - ], - "usage": { - "prompt_tokens": 140, - "completion_tokens": 19, - "total_tokens": 159, - "prompt_tokens_details": { - "cached_tokens": 0, - "audio_tokens": 0 - }, - "completion_tokens_details": { - "reasoning_tokens": 0, - "audio_tokens": 0, - "accepted_prediction_tokens": 0, - "rejected_prediction_tokens": 0 - } - }, - "system_fingerprint": "fp_0ba0d124f1" - } - headers: - CF-Cache-Status: - - DYNAMIC - CF-RAY: - - 8e14cb494bcd401e-SIN - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Tue, 12 Nov 2024 07:26:30 GMT - Server: - - cloudflare - Set-Cookie: test_set_cookie - Transfer-Encoding: - - chunked - X-Content-Type-Options: - - nosniff - access-control-expose-headers: - - X-Request-ID - alt-svc: - - h3=":443"; ma=86400 - content-length: - - '1046' - openai-organization: test_openai_org_key - openai-processing-ms: - - '516' - openai-version: - - '2020-10-01' - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-ratelimit-limit-requests: - - '10000' - x-ratelimit-limit-tokens: - - '200000' - x-ratelimit-remaining-requests: - - '9995' - x-ratelimit-remaining-tokens: - - '199921' - x-ratelimit-reset-requests: - - 40.008s - x-ratelimit-reset-tokens: - - 23ms - x-request-id: - - req_8c75e0b1c7b908bb414fba6160183ea7 - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_chat_completions.py b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_chat_completions.py index 75193c7..dac91ea 100644 --- a/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_chat_completions.py +++ b/instrumentation/elastic-opentelemetry-instrumentation-openai/tests/test_chat_completions.py @@ -54,8 +54,6 @@ OPENAI_VERSION = tuple([int(x) for x in openai.version.VERSION.split(".")]) -providers = ["openai_provider_chat_completions", "ollama_provider_chat_completions", "azure_provider_chat_completions"] - # TODO: provide a wrapper to generate parameters names and values for parametrize? test_basic_test_data = [ @@ -107,6 +105,7 @@ def test_basic( duration, trace_exporter, metrics_reader, + logs_exporter, request, ): provider = request.getfixturevalue(provider_str) @@ -144,7 +143,9 @@ def test_basic( SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, } - assert span.events == () + + logs = logs_exporter.get_finished_logs() + assert len(logs) == 0 operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) attributes = { @@ -213,6 +214,7 @@ def test_all_the_client_options( duration, trace_exporter, metrics_reader, + logs_exporter, request, ): provider = request.getfixturevalue(provider_str) @@ -264,7 +266,9 @@ def test_all_the_client_options( SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, } - assert span.events == () + + logs = logs_exporter.get_finished_logs() + assert len(logs) == 0 operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) attributes = { @@ -445,6 +449,7 @@ def test_function_calling_with_tools( duration, trace_exporter, metrics_reader, + logs_exporter, request, ): provider = request.getfixturevalue(provider_str) @@ -498,151 +503,6 @@ def test_function_calling_with_tools( assert span.kind == SpanKind.CLIENT assert span.status.status_code == StatusCode.UNSET - assert dict(span.attributes) == { - GEN_AI_OPERATION_NAME: "chat", - GEN_AI_REQUEST_MODEL: model, - GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: response_id, - GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: ("tool_calls",), - GEN_AI_USAGE_INPUT_TOKENS: input_tokens, - GEN_AI_USAGE_OUTPUT_TOKENS: output_tokens, - SERVER_ADDRESS: provider.server_address, - SERVER_PORT: provider.server_port, - } - assert span.events == () - - operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) - attributes = { - GEN_AI_REQUEST_MODEL: model, - GEN_AI_RESPONSE_MODEL: response_model, - } - assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=duration - ) - assert_token_usage_metric( - provider, - token_usage_metric, - attributes=attributes, - input_data_point=input_tokens, - output_data_point=output_tokens, - ) - - -test_tools_with_capture_message_content_span_events_test_data = [ - ( - "openai_provider_chat_completions", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "South Atlantic Ocean.", - "chatcmpl-ASfa9bDXRwPIhzm7t58LNXJLZnBgC", - "call_QerODwH75OIstmsLXRkCOy4X", - 140, - 19, - 0.006761051714420319, - ), - ( - "azure_provider_chat_completions", - "unused", - "gpt-4-32k", - "South Atlantic Ocean", - "chatcmpl-ASxkERPeCSyiDvA8jyN5dhIpAYryd", - "call_hR2GEOnGJhmLsHHsMgfLuICf", - 144, - 20, - 0.002889830619096756, - ), - ( - "ollama_provider_chat_completions", - "qwen2.5:0.5b", - "qwen2.5:0.5b", - "The Falklands Islands are located in the oceans south of South America.", - "chatcmpl-705", - "call_u9zt4jf1", - 241, - 28, - 0.002600736916065216, - ), -] - - -@pytest.mark.vcr() -@pytest.mark.parametrize( - "provider_str,model,response_model,content,response_id,function_call_id,input_tokens,output_tokens,duration", - test_tools_with_capture_message_content_span_events_test_data, -) -def test_tools_with_capture_message_content_span_events( - provider_str, - model, - response_model, - content, - response_id, - function_call_id, - input_tokens, - output_tokens, - duration, - trace_exporter, - metrics_reader, - request, -): - provider = request.getfixturevalue(provider_str) - client = provider.get_client() - - # Redo the instrumentation dance to be affected by the environment variable - OpenAIInstrumentor().uninstrument() - with mock.patch.dict( - "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, - ): - OpenAIInstrumentor().instrument() - - tools = [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID.", - }, - }, - "required": ["order_id"], - "additionalProperties": False, - }, - }, - } - ] - - messages = [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user.", - }, - {"role": "user", "content": "Hi, can you tell me the delivery date for my order?"}, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?", - }, - {"role": "user", "content": "i think it is order_12345"}, - ] - - response = client.chat.completions.create(model=model, messages=messages, tools=tools) - tool_call = response.choices[0].message.tool_calls[0] - assert tool_call.function.name == "get_delivery_date" - assert json.loads(tool_call.function.arguments) == {"order_id": "order_12345"} - - spans = trace_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.name == f"chat {model}" - assert span.kind == SpanKind.CLIENT - assert span.status.status_code == StatusCode.UNSET - assert dict(span.attributes) == { GEN_AI_OPERATION_NAME: "chat", GEN_AI_REQUEST_MODEL: model, @@ -656,14 +516,9 @@ def test_tools_with_capture_message_content_span_events( SERVER_PORT: provider.server_port, } - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} + logs = logs_exporter.get_finished_logs() + assert len(logs) == 0 - assert_tool_call_event( - completion_event, [ToolCall(function_call_id, "get_delivery_date", '{"order_id": "order_12345"}')] - ) operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) attributes = { GEN_AI_REQUEST_MODEL: model, @@ -989,7 +844,7 @@ def test_tools_with_capture_message_content_integration( @pytest.mark.vcr() @pytest.mark.parametrize("provider_str,model,duration", test_connection_error_test_data) -def test_connection_error(provider_str, model, duration, trace_exporter, metrics_reader, request): +def test_connection_error(provider_str, model, duration, trace_exporter, metrics_reader, logs_exporter, request): provider = request.getfixturevalue(provider_str) client = openai.Client(base_url="http://localhost:9999/v5", api_key="unused", max_retries=1) @@ -1019,7 +874,9 @@ def test_connection_error(provider_str, model, duration, trace_exporter, metrics SERVER_ADDRESS: "localhost", SERVER_PORT: 9999, } - assert span.events == () + + logs = logs_exporter.get_finished_logs() + assert len(logs) == 0 (operation_duration_metric,) = get_sorted_metrics(metrics_reader) attributes = { @@ -1035,13 +892,103 @@ def test_connection_error(provider_str, model, duration, trace_exporter, metrics ) -test_basic_with_capture_message_content_span_events_test_data = [ +@pytest.mark.integration +@pytest.mark.parametrize( + "provider_str,model,response_model", + [ + ( + "openai_provider_chat_completions", + "gpt-4o-mini", + "gpt-4o-mini-2024-07-18", + ) + ], +) +def test_basic_with_capture_message_content_integration( + provider_str, + model, + response_model, + trace_exporter, + logs_exporter, + metrics_reader, + request, +): + provider = request.getfixturevalue(provider_str) + + # Redo the instrumentation dance to be affected by the environment variable + OpenAIInstrumentor().uninstrument() + with mock.patch.dict( + "os.environ", + {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true"}, + ): + OpenAIInstrumentor().instrument() + + client = provider.get_client() + + messages = [ + { + "role": "user", + "content": "Answer in up to 3 words: Which ocean contains the falkland islands?", + } + ] + + response = client.chat.completions.create(model=model, messages=messages) + content = response.choices[0].message.content + assert content + + spans = trace_exporter.get_finished_spans() + assert len(spans) == 1 + + span = spans[0] + assert span.name == f"chat {model}" + assert span.kind == SpanKind.CLIENT + assert span.status.status_code == StatusCode.UNSET + + assert dict(span.attributes) == { + GEN_AI_OPERATION_NAME: "chat", + GEN_AI_REQUEST_MODEL: model, + GEN_AI_SYSTEM: "openai", + GEN_AI_RESPONSE_ID: response.id, + GEN_AI_RESPONSE_MODEL: response_model, + GEN_AI_RESPONSE_FINISH_REASONS: ("stop",), + GEN_AI_USAGE_INPUT_TOKENS: response.usage.prompt_tokens, + GEN_AI_USAGE_OUTPUT_TOKENS: response.usage.completion_tokens, + SERVER_ADDRESS: provider.server_address, + SERVER_PORT: provider.server_port, + } + + logs = logs_exporter.get_finished_logs() + assert len(logs) == 2 + log_records = logrecords_from_logs(logs) + user_message, choice = log_records + assert dict(user_message.attributes) == {"gen_ai.system": "openai", "event.name": "gen_ai.user.message"} + assert dict(user_message.body) == {"content": "Answer in up to 3 words: Which ocean contains the falkland islands?"} + + assert_stop_log_record(choice, content) + + operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) + attributes = { + GEN_AI_REQUEST_MODEL: model, + GEN_AI_RESPONSE_MODEL: response_model, + } + assert_operation_duration_metric( + provider, operation_duration_metric, attributes=attributes, min_data_point=MOCK_POSITIVE_FLOAT + ) + assert_token_usage_metric( + provider, + token_usage_metric, + attributes=attributes, + input_data_point=response.usage.prompt_tokens, + output_data_point=response.usage.completion_tokens, + ) + + +test_basic_with_capture_message_content_test_data = [ ( "openai_provider_chat_completions", "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "South Atlantic Ocean.", - "chatcmpl-ASfaC6FMNUKWFqBJmf9rmRluWyRAF", + "chatcmpl-ASfaDugIT60RnKtXL11x7yXKEn7WK", 24, 4, 0.006761051714420319, @@ -1051,7 +998,7 @@ def test_connection_error(provider_str, model, duration, trace_exporter, metrics "unused", "gpt-4-32k", "Atlantic Ocean", - "chatcmpl-ASxkIgV0VKpWeEuyJHsem9UEl4fAt", + "chatcmpl-ASxkJuCwyegZk4W2awEhTKyCzstRr", 24, 2, 0.002889830619096756, @@ -1060,10 +1007,10 @@ def test_connection_error(provider_str, model, duration, trace_exporter, metrics "ollama_provider_chat_completions", "qwen2.5:0.5b", "qwen2.5:0.5b", - "The Atlantic Ocean.", - "chatcmpl-433", + "Atlantic Ocean", + "chatcmpl-913", 46, - 5, + 3, 0.002600736916065216, ), ] @@ -1072,9 +1019,9 @@ def test_connection_error(provider_str, model, duration, trace_exporter, metrics @pytest.mark.vcr() @pytest.mark.parametrize( "provider_str,model,response_model,content,response_id,input_tokens,output_tokens,duration", - test_basic_with_capture_message_content_span_events_test_data, + test_basic_with_capture_message_content_test_data, ) -def test_basic_with_capture_message_content_span_events( +def test_basic_with_capture_message_content( provider_str, model, response_model, @@ -1084,6 +1031,7 @@ def test_basic_with_capture_message_content_span_events( output_tokens, duration, trace_exporter, + logs_exporter, metrics_reader, request, ): @@ -1092,218 +1040,7 @@ def test_basic_with_capture_message_content_span_events( # Redo the instrumentation dance to be affected by the environment variable OpenAIInstrumentor().uninstrument() - with mock.patch.dict( - "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, - ): - OpenAIInstrumentor().instrument() - - messages = [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?", - } - ] - - chat_completion = client.chat.completions.create(model=model, messages=messages) - - assert chat_completion.choices[0].message.content == content - - spans = trace_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.name == f"chat {model}" - assert span.kind == SpanKind.CLIENT - assert span.status.status_code == StatusCode.UNSET - - assert dict(span.attributes) == { - GEN_AI_OPERATION_NAME: "chat", - GEN_AI_REQUEST_MODEL: model, - GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: response_id, - GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: ("stop",), - GEN_AI_USAGE_INPUT_TOKENS: input_tokens, - GEN_AI_USAGE_OUTPUT_TOKENS: output_tokens, - SERVER_ADDRESS: provider.server_address, - SERVER_PORT: provider.server_port, - } - - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} - assert completion_event.name == "gen_ai.content.completion" - assert dict(completion_event.attributes) == { - "gen_ai.completion": '[{"role": "assistant", "content": "' + content + '"}]' - } - - operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) - attributes = { - GEN_AI_REQUEST_MODEL: model, - GEN_AI_RESPONSE_MODEL: response_model, - } - assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=duration - ) - assert_token_usage_metric( - provider, - token_usage_metric, - attributes=attributes, - input_data_point=input_tokens, - output_data_point=output_tokens, - ) - - -@pytest.mark.integration -@pytest.mark.parametrize( - "provider_str,model,response_model", - [ - ( - "openai_provider_chat_completions", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - ) - ], -) -def test_basic_with_capture_message_content_span_events_integration( - provider_str, - model, - response_model, - trace_exporter, - metrics_reader, - request, -): - provider = request.getfixturevalue(provider_str) - - # Redo the instrumentation dance to be affected by the environment variable - OpenAIInstrumentor().uninstrument() - with mock.patch.dict( - "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, - ): - OpenAIInstrumentor().instrument() - - client = provider.get_client() - - messages = [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?", - } - ] - - response = client.chat.completions.create(model=model, messages=messages) - content = response.choices[0].message.content - assert content - - spans = trace_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.name == f"chat {model}" - assert span.kind == SpanKind.CLIENT - assert span.status.status_code == StatusCode.UNSET - - assert dict(span.attributes) == { - GEN_AI_OPERATION_NAME: "chat", - GEN_AI_REQUEST_MODEL: model, - GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: response.id, - GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: ("stop",), - GEN_AI_USAGE_INPUT_TOKENS: response.usage.prompt_tokens, - GEN_AI_USAGE_OUTPUT_TOKENS: response.usage.completion_tokens, - SERVER_ADDRESS: provider.server_address, - SERVER_PORT: provider.server_port, - } - - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} - assert completion_event.name == "gen_ai.content.completion" - assert dict(completion_event.attributes) == { - "gen_ai.completion": '[{"role": "assistant", "content": "' + content + '"}]' - } - - operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) - attributes = { - GEN_AI_REQUEST_MODEL: model, - GEN_AI_RESPONSE_MODEL: response_model, - } - assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=MOCK_POSITIVE_FLOAT - ) - assert_token_usage_metric( - provider, - token_usage_metric, - attributes=attributes, - input_data_point=response.usage.prompt_tokens, - output_data_point=response.usage.completion_tokens, - ) - - -test_basic_with_capture_message_content_test_data = [ - ( - "openai_provider_chat_completions", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "South Atlantic Ocean.", - "chatcmpl-ASfaDugIT60RnKtXL11x7yXKEn7WK", - 24, - 4, - 0.006761051714420319, - ), - ( - "azure_provider_chat_completions", - "unused", - "gpt-4-32k", - "Atlantic Ocean", - "chatcmpl-ASxkJuCwyegZk4W2awEhTKyCzstRr", - 24, - 2, - 0.002889830619096756, - ), - ( - "ollama_provider_chat_completions", - "qwen2.5:0.5b", - "qwen2.5:0.5b", - "Atlantic Ocean", - "chatcmpl-913", - 46, - 3, - 0.002600736916065216, - ), -] - - -@pytest.mark.vcr() -@pytest.mark.parametrize( - "provider_str,model,response_model,content,response_id,input_tokens,output_tokens,duration", - test_basic_with_capture_message_content_test_data, -) -def test_basic_with_capture_message_content( - provider_str, - model, - response_model, - content, - response_id, - input_tokens, - output_tokens, - duration, - trace_exporter, - logs_exporter, - metrics_reader, - request, -): - provider = request.getfixturevalue(provider_str) - client = provider.get_client() - - # Redo the instrumentation dance to be affected by the environment variable - OpenAIInstrumentor().uninstrument() - with mock.patch.dict("os.environ", {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true"}): + with mock.patch.dict("os.environ", {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true"}): OpenAIInstrumentor().instrument() messages = [ @@ -1395,7 +1132,16 @@ def test_basic_with_capture_message_content( @pytest.mark.vcr() @pytest.mark.parametrize("provider_str,model,response_model,content,response_id,duration", test_stream_test_data) def test_stream( - provider_str, model, response_model, content, response_id, duration, trace_exporter, metrics_reader, request + provider_str, + model, + response_model, + content, + response_id, + duration, + trace_exporter, + metrics_reader, + logs_exporter, + request, ): provider = request.getfixturevalue(provider_str) client = provider.get_client() @@ -1430,7 +1176,9 @@ def test_stream( SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, } - assert span.events == () + + logs = logs_exporter.get_finished_logs() + assert len(logs) == 0 (operation_duration_metric,) = get_sorted_metrics(metrics_reader) attributes = { @@ -1484,6 +1232,7 @@ def test_stream_with_include_usage_option( duration, trace_exporter, metrics_reader, + logs_exporter, request, ): provider = request.getfixturevalue(provider_str) @@ -1523,7 +1272,9 @@ def test_stream_with_include_usage_option( SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, } - assert span.events == () + + logs = logs_exporter.get_finished_logs() + assert len(logs) == 0 operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) attributes = { @@ -1554,12 +1305,13 @@ def test_stream_with_include_usage_option( ) ], ) -def test_stream_with_include_usage_option_and_capture_message_content_span_events_integration( +def test_stream_with_include_usage_option_and_capture_message_content_integration( provider_str, model, response_model, trace_exporter, metrics_reader, + logs_exporter, request, ): provider = request.getfixturevalue(provider_str) @@ -1568,186 +1320,28 @@ def test_stream_with_include_usage_option_and_capture_message_content_span_event OpenAIInstrumentor().uninstrument() with mock.patch.dict( "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, + {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true"}, ): OpenAIInstrumentor().instrument() client = provider.get_client() messages = [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?", - } - ] - - response = client.chat.completions.create( - model=model, messages=messages, stream=True, stream_options={"include_usage": True} - ) - chunks = [chunk for chunk in response] - usage = chunks[-1].usage - - chunks_content = [chunk.choices[0].delta.content or "" for chunk in chunks if chunk.choices] - content = "".join(chunks_content) - assert content - - spans = trace_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.name == f"chat {model}" - assert span.kind == SpanKind.CLIENT - assert span.status.status_code == StatusCode.UNSET - - assert dict(span.attributes) == { - GEN_AI_OPERATION_NAME: "chat", - GEN_AI_REQUEST_MODEL: model, - GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: chunks[0].id, - GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: ("stop",), - GEN_AI_USAGE_INPUT_TOKENS: usage.prompt_tokens, - GEN_AI_USAGE_OUTPUT_TOKENS: usage.completion_tokens, - SERVER_ADDRESS: provider.server_address, - SERVER_PORT: provider.server_port, - } - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} - assert completion_event.name == "gen_ai.content.completion" - assert dict(completion_event.attributes) == { - "gen_ai.completion": '[{"role": "assistant", "content": "' + content + '"}]' - } - - operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) - attributes = { - GEN_AI_REQUEST_MODEL: model, - GEN_AI_RESPONSE_MODEL: response_model, - } - assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=MOCK_POSITIVE_FLOAT - ) - assert_token_usage_metric( - provider, - token_usage_metric, - attributes=attributes, - input_data_point=usage.prompt_tokens, - output_data_point=usage.completion_tokens, - ) - - -test_stream_with_tools_and_capture_message_content_span_events_test_data = [ - ( - "openai_provider_chat_completions", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "", - { - "gen_ai.completion": '[{"role": "assistant", "content": "", "tool_calls": [{"function": {"arguments": "{\\"order_id\\":\\"order_12345\\"}", "name": "get_delivery_date"}, "id": "call_RlWXV8zAJhzxsh6JqMHY0HbV", "type": "function"}]}]' - }, - "chatcmpl-ASfaFeOMsHtr0F6UH3Q1faiZxSeMX", - "tool_calls", - 0.006761051714420319, - ), - ( - "azure_provider_chat_completions", - "unused", - "gpt-4-32k", - "", - { - "gen_ai.completion": '[{"role": "assistant", "content": "", "tool_calls": [{"function": {"arguments": "{\\n \\"order_id\\": \\"order_12345\\"\\n}", "name": "get_delivery_date"}, "id": "call_hR2GEOnGJhmLsHHsMgfLuICf", "type": "function"}]}]' - }, - "chatcmpl-ASxkMa2HB9hyfwSNjCqVUwX2txxqr", - "tool_calls", - 0.002889830619096756, - ), - ( - "ollama_provider_chat_completions", - "qwen2.5:0.5b", - "qwen2.5:0.5b", - '\n{"name": "get_delivery_date", "arguments": {"order_id": "order_12345"}}\n', - { - "gen_ai.completion": '[{"role": "assistant", "content": ' - + json.dumps( - '\n{"name": "get_delivery_date", "arguments": {"order_id": "order_12345"}}\n' - ) - + "}]" - }, - "chatcmpl-268", - "stop", - 0.002600736916065216, - ), -] - - -@pytest.mark.vcr() -@pytest.mark.parametrize( - "provider_str,model,response_model,content,completion_content,response_id,finish_reason,duration", - test_stream_with_tools_and_capture_message_content_span_events_test_data, -) -def test_stream_with_tools_and_capture_message_content_span_events( - provider_str, - model, - response_model, - content, - completion_content, - response_id, - finish_reason, - duration, - trace_exporter, - metrics_reader, - request, -): - provider = request.getfixturevalue(provider_str) - client = provider.get_client() - - # Redo the instrumentation dance to be affected by the environment variable - OpenAIInstrumentor().uninstrument() - with mock.patch.dict( - "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, - ): - OpenAIInstrumentor().instrument() - - tools = [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID.", - }, - }, - "required": ["order_id"], - "additionalProperties": False, - }, - }, - } - ] - - messages = [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user.", - }, - {"role": "user", "content": "Hi, can you tell me the delivery date for my order?"}, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?", - }, - {"role": "user", "content": "i think it is order_12345"}, + { + "role": "user", + "content": "Answer in up to 3 words: Which ocean contains the falkland islands?", + } ] - chat_completion = client.chat.completions.create(model=model, messages=messages, tools=tools, stream=True) + response = client.chat.completions.create( + model=model, messages=messages, stream=True, stream_options={"include_usage": True} + ) + chunks = [chunk for chunk in response] + usage = chunks[-1].usage - chunks = [chunk.choices[0].delta.content or "" for chunk in chat_completion if chunk.choices] - assert "".join(chunks) == content + chunks_content = [chunk.choices[0].delta.content or "" for chunk in chunks if chunk.choices] + content = "".join(chunks_content) + assert content spans = trace_exporter.get_finished_spans() assert len(spans) == 1 @@ -1761,27 +1355,38 @@ def test_stream_with_tools_and_capture_message_content_span_events( GEN_AI_OPERATION_NAME: "chat", GEN_AI_REQUEST_MODEL: model, GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: response_id, + GEN_AI_RESPONSE_ID: chunks[0].id, GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: (finish_reason,), + GEN_AI_RESPONSE_FINISH_REASONS: ("stop",), + GEN_AI_USAGE_INPUT_TOKENS: usage.prompt_tokens, + GEN_AI_USAGE_OUTPUT_TOKENS: usage.completion_tokens, SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, } - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} - assert completion_event.name == "gen_ai.content.completion" - assert dict(completion_event.attributes) == completion_content + logs = logs_exporter.get_finished_logs() + assert len(logs) == 2 + log_records = logrecords_from_logs(logs) + user_message, choice = log_records + assert dict(user_message.attributes) == {"gen_ai.system": "openai", "event.name": "gen_ai.user.message"} + assert dict(user_message.body) == {"content": "Answer in up to 3 words: Which ocean contains the falkland islands?"} + + assert_stop_log_record(choice, content) - (operation_duration_metric,) = get_sorted_metrics(metrics_reader) + operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) attributes = { GEN_AI_REQUEST_MODEL: model, GEN_AI_RESPONSE_MODEL: response_model, } assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=duration + provider, operation_duration_metric, attributes=attributes, min_data_point=MOCK_POSITIVE_FLOAT + ) + assert_token_usage_metric( + provider, + token_usage_metric, + attributes=attributes, + input_data_point=usage.prompt_tokens, + output_data_point=usage.completion_tokens, ) @@ -1950,137 +1555,6 @@ def test_stream_with_tools_and_capture_message_content( ) -# Azure is not tested because only gpt-4o version 2024-08-06 supports structured output: -# openai.BadRequestError: Error code: 400 - {'error': {'message': 'Structured output is not allowed.', 'type': 'invalid_request_error', 'param': None, 'code': None}} -test_stream_with_parallel_tools_and_capture_message_content_span_events_test_data = [ - ( - "openai_provider_chat_completions", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "", - { - "gen_ai.completion": '[{"role": "assistant", "content": "", "tool_calls": [{"function": {"arguments": "{\\"location\\": \\"New York City\\"}", "name": "get_weather"}, "id": "call_awpPik83NVMEmnWIARc49DVf", "type": "function"}, {"function": {"arguments": "{\\"location\\": \\"London\\"}", "name": "get_weather"}, "id": "call_LPkfKwdcq3Tqg06fTFVIDcV5", "type": "function"}]}]' - }, - "chatcmpl-ASfaHUbWaDoK0qGijDZO8PwY9efB7", - "tool_calls", - 0.006761051714420319, - ), - ( - "ollama_provider_chat_completions", - "qwen2.5:0.5b", - "qwen2.5:0.5b", - """ -{"name": "get_weather", "arguments": {"location": "New York City"}} - - -{"name": "get_weather", "arguments": {"location": "London"}} -""", - { - "gen_ai.completion": '[{"role": "assistant", "content": "\\n{\\"name\\": \\"get_weather\\", \\"arguments\\": {\\"location\\": \\"New York City\\"}}\\n\\n\\n{\\"name\\": \\"get_weather\\", \\"arguments\\": {\\"location\\": \\"London\\"}}\\n"}]' - }, - "chatcmpl-918", - "stop", - 0.002600736916065216, - ), -] - - -@pytest.mark.vcr() -@pytest.mark.parametrize( - "provider_str,model,response_model,content,completion_content,response_id,finish_reason,duration", - test_stream_with_parallel_tools_and_capture_message_content_span_events_test_data, -) -def test_stream_with_parallel_tools_and_capture_message_content_span_events( - provider_str, - model, - response_model, - content, - completion_content, - response_id, - finish_reason, - duration, - trace_exporter, - metrics_reader, - request, -): - provider = request.getfixturevalue(provider_str) - client = provider.get_client() - - # Redo the instrumentation dance to be affected by the environment variable - OpenAIInstrumentor().uninstrument() - with mock.patch.dict( - "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, - ): - OpenAIInstrumentor().instrument() - - tools = [ - { - "type": "function", - "function": { - "name": "get_weather", - "strict": True, - "parameters": { - "type": "object", - "properties": { - "location": {"type": "string"}, - }, - "required": ["location"], - "additionalProperties": False, - }, - }, - } - ] - - messages = [ - { - "role": "system", - "content": "You are a helpful assistant providing weather updates.", - }, - {"role": "user", "content": "What is the weather in New York City and London?"}, - ] - - chat_completion = client.chat.completions.create(model=model, messages=messages, tools=tools, stream=True) - - chunks = [chunk.choices[0].delta.content or "" for chunk in chat_completion if chunk.choices] - assert "".join(chunks) == content - - spans = trace_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.name == f"chat {model}" - assert span.kind == SpanKind.CLIENT - assert span.status.status_code == StatusCode.UNSET - - assert dict(span.attributes) == { - GEN_AI_OPERATION_NAME: "chat", - GEN_AI_REQUEST_MODEL: model, - GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: response_id, - GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: (finish_reason,), - SERVER_ADDRESS: provider.server_address, - SERVER_PORT: provider.server_port, - } - - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} - assert completion_event.name == "gen_ai.content.completion" - assert dict(completion_event.attributes) == completion_content - - (operation_duration_metric,) = get_sorted_metrics(metrics_reader) - attributes = { - GEN_AI_REQUEST_MODEL: model, - GEN_AI_RESPONSE_MODEL: response_model, - } - assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=duration - ) - - test_stream_with_parallel_tools_and_capture_message_content_test_data = [ ( "openai_provider_chat_completions", @@ -2393,123 +1867,16 @@ def test_tools_with_followup_and_capture_message_content( assert system_message.body == {"content": "You are a helpful assistant providing weather updates."} assert user_message.attributes == {"gen_ai.system": "openai", "event.name": "gen_ai.user.message"} assert user_message.body == {"content": "What is the weather in New York City and London?"} - assert assistant_message.attributes == {"gen_ai.system": "openai", "event.name": "gen_ai.assistant.message"} - assert assistant_message.body == {"tool_calls": previous_message["tool_calls"]} - assert first_tool.attributes == {"gen_ai.system": "openai", "event.name": "gen_ai.tool.message"} - first_tool_response = previous_message["tool_calls"][0] - assert first_tool.body == {"content": "25 degrees and sunny", "id": first_tool_response["id"]} - assert second_tool.attributes == {"gen_ai.system": "openai", "event.name": "gen_ai.tool.message"} - second_tool_response = previous_message["tool_calls"][1] - assert second_tool.body == {"content": "15 degrees and raining", "id": second_tool_response["id"]} - - assert_stop_log_record(choice, second_response.choices[0].message.content) - - operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) - attributes = { - GEN_AI_REQUEST_MODEL: model, - GEN_AI_RESPONSE_MODEL: response_model, - } - assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=duration, count=2 - ) - assert_token_usage_metric( - provider, - token_usage_metric, - attributes=attributes, - input_data_point=[first_response.usage.prompt_tokens, second_response.usage.prompt_tokens], - output_data_point=[first_response.usage.completion_tokens, second_response.usage.completion_tokens], - count=2, - ) - - -test_async_basic_test_data = [ - ( - "openai_provider_chat_completions", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "South Atlantic Ocean.", - "chatcmpl-ASfaN2cUXcaAFQ7uFS83Kuvc0iKdp", - 24, - 4, - 0.006761051714420319, - ), - ( - "azure_provider_chat_completions", - "unused", - "gpt-4-32k", - "Atlantic Ocean", - "chatcmpl-ASxkRs5B2H6Nyi9F1xV78yBVkiBbi", - 24, - 2, - 0.002889830619096756, - ), - ( - "ollama_provider_chat_completions", - "qwen2.5:0.5b", - "qwen2.5:0.5b", - "The Falkland Islands belong to Argentina.", - "chatcmpl-95", - 46, - 9, - 0.002600736916065216, - ), -] - - -@pytest.mark.asyncio -@pytest.mark.vcr() -@pytest.mark.parametrize( - "provider_str,model,response_model,content,response_id,input_tokens,output_tokens,duration", - test_async_basic_test_data, -) -async def test_async_basic( - provider_str, - model, - response_model, - content, - response_id, - input_tokens, - output_tokens, - duration, - trace_exporter, - metrics_reader, - request, -): - provider = request.getfixturevalue(provider_str) - client = provider.get_async_client() - - messages = [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?", - } - ] - - chat_completion = await client.chat.completions.create(model=model, messages=messages) - - assert chat_completion.choices[0].message.content == content - - spans = trace_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.name == f"chat {model}" - assert span.kind == SpanKind.CLIENT - assert span.status.status_code == StatusCode.UNSET + assert assistant_message.attributes == {"gen_ai.system": "openai", "event.name": "gen_ai.assistant.message"} + assert assistant_message.body == {"tool_calls": previous_message["tool_calls"]} + assert first_tool.attributes == {"gen_ai.system": "openai", "event.name": "gen_ai.tool.message"} + first_tool_response = previous_message["tool_calls"][0] + assert first_tool.body == {"content": "25 degrees and sunny", "id": first_tool_response["id"]} + assert second_tool.attributes == {"gen_ai.system": "openai", "event.name": "gen_ai.tool.message"} + second_tool_response = previous_message["tool_calls"][1] + assert second_tool.body == {"content": "15 degrees and raining", "id": second_tool_response["id"]} - assert dict(span.attributes) == { - GEN_AI_OPERATION_NAME: "chat", - GEN_AI_REQUEST_MODEL: model, - GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: response_id, - GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: ("stop",), - GEN_AI_USAGE_INPUT_TOKENS: input_tokens, - GEN_AI_USAGE_OUTPUT_TOKENS: output_tokens, - SERVER_ADDRESS: provider.server_address, - SERVER_PORT: provider.server_port, - } - assert span.events == () + assert_stop_log_record(choice, second_response.choices[0].message.content) operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) attributes = { @@ -2517,24 +1884,25 @@ async def test_async_basic( GEN_AI_RESPONSE_MODEL: response_model, } assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=duration + provider, operation_duration_metric, attributes=attributes, min_data_point=duration, count=2 ) assert_token_usage_metric( provider, token_usage_metric, attributes=attributes, - input_data_point=input_tokens, - output_data_point=output_tokens, + input_data_point=[first_response.usage.prompt_tokens, second_response.usage.prompt_tokens], + output_data_point=[first_response.usage.completion_tokens, second_response.usage.completion_tokens], + count=2, ) -test_async_basic_with_capture_message_content_span_events_test_data = [ +test_async_basic_test_data = [ ( "openai_provider_chat_completions", "gpt-4o-mini", "gpt-4o-mini-2024-07-18", "South Atlantic Ocean.", - "chatcmpl-ASfaOHHT6qOYpFc5M7uzSkgfXnnpJ", + "chatcmpl-ASfaN2cUXcaAFQ7uFS83Kuvc0iKdp", 24, 4, 0.006761051714420319, @@ -2544,7 +1912,7 @@ async def test_async_basic( "unused", "gpt-4-32k", "Atlantic Ocean", - "chatcmpl-ASySeHu4TgKtlulOVp4LU8yTNRvoM", + "chatcmpl-ASxkRs5B2H6Nyi9F1xV78yBVkiBbi", 24, 2, 0.002889830619096756, @@ -2553,10 +1921,10 @@ async def test_async_basic( "ollama_provider_chat_completions", "qwen2.5:0.5b", "qwen2.5:0.5b", - "Antarctica ocean.", - "chatcmpl-816", + "The Falkland Islands belong to Argentina.", + "chatcmpl-95", 46, - 6, + 9, 0.002600736916065216, ), ] @@ -2566,9 +1934,9 @@ async def test_async_basic( @pytest.mark.vcr() @pytest.mark.parametrize( "provider_str,model,response_model,content,response_id,input_tokens,output_tokens,duration", - test_async_basic_with_capture_message_content_span_events_test_data, + test_async_basic_test_data, ) -async def test_async_basic_with_capture_message_content_span_events( +async def test_async_basic( provider_str, model, response_model, @@ -2579,19 +1947,12 @@ async def test_async_basic_with_capture_message_content_span_events( duration, trace_exporter, metrics_reader, + logs_exporter, request, ): provider = request.getfixturevalue(provider_str) client = provider.get_async_client() - # Redo the instrumentation dance to be affected by the environment variable - OpenAIInstrumentor().uninstrument() - with mock.patch.dict( - "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, - ): - OpenAIInstrumentor().instrument() - messages = [ { "role": "user", @@ -2623,14 +1984,9 @@ async def test_async_basic_with_capture_message_content_span_events( SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, } - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} - assert completion_event.name == "gen_ai.content.completion" - assert dict(completion_event.attributes) == { - "gen_ai.completion": ('[{"role": "assistant", "content": "' + content + '"}]') - } + + logs = logs_exporter.get_finished_logs() + assert len(logs) == 0 operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) attributes = { @@ -2888,88 +2244,6 @@ async def test_async_basic_with_capture_message_content_integration( @pytest.mark.asyncio @pytest.mark.parametrize("provider_str,model,response_model,content,response_id,duration", test_async_stream_test_data) async def test_async_stream( - provider_str, model, response_model, content, response_id, duration, trace_exporter, metrics_reader, request -): - provider = request.getfixturevalue(provider_str) - client = provider.get_async_client() - - messages = [ - { - "role": "user", - "content": "Answer in up to 3 words: Which ocean contains the falkland islands?", - } - ] - - chat_completion = await client.chat.completions.create(model=model, messages=messages, stream=True) - - chunks = [chunk.choices[0].delta.content or "" async for chunk in chat_completion if chunk.choices] - assert "".join(chunks) == content - - spans = trace_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.name == f"chat {model}" - assert span.kind == SpanKind.CLIENT - assert span.status.status_code == StatusCode.UNSET - - assert dict(span.attributes) == { - GEN_AI_OPERATION_NAME: "chat", - GEN_AI_REQUEST_MODEL: model, - GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: response_id, - GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: ("stop",), - SERVER_ADDRESS: provider.server_address, - SERVER_PORT: provider.server_port, - } - assert span.events == () - - (operation_duration_metric,) = get_sorted_metrics(metrics_reader) - attributes = { - GEN_AI_REQUEST_MODEL: model, - GEN_AI_RESPONSE_MODEL: response_model, - } - assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=duration - ) - - -test_async_stream_with_capture_message_content_span_events_test_data = [ - ( - "openai_provider_chat_completions", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "South Atlantic Ocean.", - "chatcmpl-ASfaPHhHlSFtYDMa1S0QSWewTPhuS", - 0.006761051714420319, - ), - ( - "azure_provider_chat_completions", - "unused", - "gpt-4-32k", - "Atlantic Ocean", - "chatcmpl-ASxkVWhWg2yeY7IV8yr6Lywa7fke4", - 0.002889830619096756, - ), - ( - "ollama_provider_chat_completions", - "qwen2.5:0.5b", - "qwen2.5:0.5b", - "South America's Atlantic Ocean.", - "chatcmpl-752", - 0.002600736916065216, - ), -] - - -@pytest.mark.vcr() -@pytest.mark.asyncio -@pytest.mark.parametrize( - "provider_str,model,response_model,content,response_id,duration", - test_async_stream_with_capture_message_content_span_events_test_data, -) -async def test_async_stream_with_capture_message_content_span_events( provider_str, model, response_model, @@ -2978,18 +2252,12 @@ async def test_async_stream_with_capture_message_content_span_events( duration, trace_exporter, metrics_reader, + logs_exporter, request, ): provider = request.getfixturevalue(provider_str) client = provider.get_async_client() - # Redo the instrumentation dance to be affected by the environment variable - OpenAIInstrumentor().uninstrument() - with mock.patch.dict( - "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, - ): - OpenAIInstrumentor().instrument() messages = [ { "role": "user", @@ -3020,14 +2288,9 @@ async def test_async_stream_with_capture_message_content_span_events( SERVER_ADDRESS: provider.server_address, SERVER_PORT: provider.server_port, } - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} - assert completion_event.name == "gen_ai.content.completion" - assert dict(completion_event.attributes) == { - "gen_ai.completion": ('[{"role": "assistant", "content": "' + content + '"}]') - } + + logs = logs_exporter.get_finished_logs() + assert len(logs) == 0 (operation_duration_metric,) = get_sorted_metrics(metrics_reader) attributes = { @@ -3147,147 +2410,6 @@ async def test_async_stream_with_capture_message_content( ) -# FIXME: ollama has empty tool_calls -test_async_tools_with_capture_message_content_span_events_test_data = [ - ( - "openai_provider_chat_completions", - "gpt-4o-mini", - "gpt-4o-mini-2024-07-18", - "chatcmpl-ASfaRyXEFFt9GzMooIy1bDXqjYnWV", - "call_fW4XFpzxFZ7Rfj5dsDcZTezg", - 140, - 19, - 0.006761051714420319, - ), - ( - "azure_provider_chat_completions", - "unused", - "gpt-4-32k", - "chatcmpl-ASxkX3IDac2dYI6AB8L4iA7SJaNii", - "call_Lm5cpl4sJy5b1FfEjsnbbjlL", - 144, - 20, - 0.002889830619096756, - ), -] - - -@pytest.mark.vcr() -@pytest.mark.asyncio -@pytest.mark.parametrize( - "provider_str,model,response_model,response_id,function_call_id,input_tokens,output_tokens,duration", - test_async_tools_with_capture_message_content_span_events_test_data, -) -async def test_async_tools_with_capture_message_content_span_events( - provider_str, - model, - response_model, - response_id, - function_call_id, - input_tokens, - output_tokens, - duration, - trace_exporter, - metrics_reader, - request, -): - provider = request.getfixturevalue(provider_str) - client = provider.get_async_client() - - # Redo the instrumentation dance to be affected by the environment variable - OpenAIInstrumentor().uninstrument() - with mock.patch.dict( - "os.environ", - {"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT": "true", "ELASTIC_OTEL_GENAI_EVENTS": "span"}, - ): - OpenAIInstrumentor().instrument() - - tools = [ - { - "type": "function", - "function": { - "name": "get_delivery_date", - "description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'", - "parameters": { - "type": "object", - "properties": { - "order_id": { - "type": "string", - "description": "The customer's order ID.", - }, - }, - "required": ["order_id"], - "additionalProperties": False, - }, - }, - } - ] - - messages = [ - { - "role": "system", - "content": "You are a helpful customer support assistant. Use the supplied tools to assist the user.", - }, - {"role": "user", "content": "Hi, can you tell me the delivery date for my order?"}, - { - "role": "assistant", - "content": "Hi there! I can help with that. Can you please provide your order ID?", - }, - {"role": "user", "content": "i think it is order_12345"}, - ] - - response = await client.chat.completions.create(model=model, messages=messages, tools=tools) - tool_call = response.choices[0].message.tool_calls[0] - assert tool_call.function.name == "get_delivery_date" - assert json.loads(tool_call.function.arguments) == {"order_id": "order_12345"} - - spans = trace_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.name == f"chat {model}" - assert span.kind == SpanKind.CLIENT - assert span.status.status_code == StatusCode.UNSET - - assert dict(span.attributes) == { - GEN_AI_OPERATION_NAME: "chat", - GEN_AI_REQUEST_MODEL: model, - GEN_AI_SYSTEM: "openai", - GEN_AI_RESPONSE_ID: response_id, - GEN_AI_RESPONSE_MODEL: response_model, - GEN_AI_RESPONSE_FINISH_REASONS: ("tool_calls",), - GEN_AI_USAGE_INPUT_TOKENS: input_tokens, - GEN_AI_USAGE_OUTPUT_TOKENS: output_tokens, - SERVER_ADDRESS: provider.server_address, - SERVER_PORT: provider.server_port, - } - - assert len(span.events) == 2 - prompt_event, completion_event = span.events - assert prompt_event.name == "gen_ai.content.prompt" - assert dict(prompt_event.attributes) == {"gen_ai.prompt": json.dumps(messages)} - - assert_tool_call_event( - completion_event, [ToolCall(function_call_id, "get_delivery_date", '{"order_id": "order_12345"}')] - ) - - operation_duration_metric, token_usage_metric = get_sorted_metrics(metrics_reader) - attributes = { - GEN_AI_REQUEST_MODEL: model, - GEN_AI_RESPONSE_MODEL: response_model, - } - assert_operation_duration_metric( - provider, operation_duration_metric, attributes=attributes, min_data_point=duration - ) - assert_token_usage_metric( - provider, - token_usage_metric, - attributes=attributes, - input_data_point=input_tokens, - output_data_point=output_tokens, - ) - - # FIXME: ollama has empty tool_calls test_async_tools_with_capture_message_content_test_data = [ (