diff --git a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/__init__.py b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/__init__.py index 7a6076666..ba9b42071 100644 --- a/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/__init__.py +++ b/packages/opentelemetry-instrumentation-openai/opentelemetry/instrumentation/openai/shared/__init__.py @@ -166,5 +166,9 @@ def is_streaming_response(response): def model_as_dict(model): if version("pydantic") < "2.0.0": return model.dict() - - return model.model_dump() + if hasattr(model, "model_dump"): + return model.model_dump() + elif hasattr(model, "parse"): # Raw API response + return model_as_dict(model.parse()) + else: + return model diff --git a/packages/opentelemetry-instrumentation-openai/tests/cassettes/test_embeddings/test_embeddings_with_raw_response.yaml b/packages/opentelemetry-instrumentation-openai/tests/cassettes/test_embeddings/test_embeddings_with_raw_response.yaml new file mode 100644 index 000000000..3e07d3314 --- /dev/null +++ b/packages/opentelemetry-instrumentation-openai/tests/cassettes/test_embeddings/test_embeddings_with_raw_response.yaml @@ -0,0 +1,226 @@ +interactions: +- request: + body: '{"input": "Tell me a joke about opentelemetry", "model": "text-embedding-ada-002"}' + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + connection: + - keep-alive + content-length: + - '82' + content-type: + - application/json + host: + - api.openai.com + user-agent: + - OpenAI/Python 1.12.0 + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 1.12.0 + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.5 + method: POST + uri: https://api.openai.com/v1/embeddings + response: + body: + string: !!binary | + H4sIAAAAAAAAA4xZzc5dtw3c5yk+eJ0aHA5/8ypdJbVRuGjTRbMIkJcvdL8mzRkZSLzwQpaPJHI4 + nOH95Zu3tw///uEfn//204fv3j7888t/fvrw7Vn79P1P33/47u2v37y9vb398vr7sfPzv374/OnT + lx///tr++scvP376/POH797st5X/b/r1S+ePf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 + 7Gh2AVcfD5nA+RVXWw5s6ubPDqM+1qoPG5uRPulT9jUe64m9K6vzjjloGJojn4gpHE7ySNGbUcKP + SDayjG175YnxNIEfnzcf9VFVo6u2jSSABtFHj2DFY9hksHyHWixS0JgpgBTU/8hbCowRr7ZLGmJ2 + 3pYI2H1XQMuyUogfkhdLG1fD1yVZMBki/8k6hoFdF7Ze0o0OkthNC+09FDRwCv86goks3HiAKiMA + mazmEqRHpy9OL9/OEhkHYfogVL7jRKHt4BmLpqOiynlUuUcislQ1TdSZAci+jXn/4k/7v3/88OnT + T/h9b79++/L1l7cfP719//rv7+9ff/3r1y9f/vbbz++fv3x+b83e9m/61z8///z17cdP/9n/89vv + //j26+/f//L929+//vbPtx8/3Z/D2/dv3z//8n+//AP+oD9++C8AAAD//wMA/xI2E7qCAAA= + headers: + CF-Cache-Status: + - DYNAMIC + CF-RAY: + - 85467261f9bf09b9-HFA + Connection: + - keep-alive + Content-Encoding: + - gzip + Content-Type: + - application/json + Date: + - Mon, 12 Feb 2024 17:10:45 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=c.wE2paVa1wZBGZX9QN_Bgp5GQ5BmgR.0hsURPOborU-1707757845-1-ASv1nnc5Kenzo5F5Bl9JGE07aZH76ribQNSCEuQc5exCUQDZF7qm0HqsovPVdsN19YoMFbP/Hd9qJtR63pa6zak=; + path=/; expires=Mon, 12-Feb-24 17:40:45 GMT; domain=.api.openai.com; HttpOnly; + Secure; SameSite=None + - _cfuvid=xlElcL1Z7pHVsTISWi3.h0RNMzgSIhjdG0kUTUVBfW8-1707757845077-0-604800000; + path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None + Transfer-Encoding: + - chunked + access-control-allow-origin: + - '*' + alt-svc: + - h3=":443"; ma=86400 + openai-model: + - text-embedding-ada-002 + openai-organization: + - traceloop + openai-processing-ms: + - '38' + openai-version: + - '2020-10-01' + strict-transport-security: + - max-age=15724800; includeSubDomains + x-ratelimit-limit-requests: + - '5000' + x-ratelimit-limit-tokens: + - '5000000' + x-ratelimit-remaining-requests: + - '4999' + x-ratelimit-remaining-tokens: + - '4999992' + x-ratelimit-reset-requests: + - 12ms + x-ratelimit-reset-tokens: + - 0s + x-request-id: + - req_4fad3b3b59c5267c18907a65346c45a3 + status: + code: 200 + message: OK +version: 1 diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_chat.py b/packages/opentelemetry-instrumentation-openai/tests/test_chat.py index 796d64206..3b974b626 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_chat.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_chat.py @@ -9,7 +9,7 @@ def test_chat_streaming(exporter, openai_client, vcr): stream=True, ) - for part in response: + for _ in response: pass spans = exporter.get_finished_spans() diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_completions.py b/packages/opentelemetry-instrumentation-openai/tests/test_completions.py index 8f64e11e9..0277acf73 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_completions.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_completions.py @@ -68,7 +68,7 @@ def test_completion_streaming(exporter, openai_client): stream=True, ) - for part in response: + for _ in response: pass spans = exporter.get_finished_spans() diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_embeddings.py b/packages/opentelemetry-instrumentation-openai/tests/test_embeddings.py index c21e8f3b1..add12d419 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_embeddings.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_embeddings.py @@ -23,6 +23,30 @@ def test_embeddings(exporter, openai_client): assert open_ai_span.attributes["openai.api_base"] == "https://api.openai.com/v1/" +@pytest.mark.vcr +def test_embeddings_with_raw_response(exporter, openai_client): + response = openai_client.embeddings.with_raw_response.create( + input="Tell me a joke about opentelemetry", + model="text-embedding-ada-002", + ) + spans = exporter.get_finished_spans() + assert [span.name for span in spans] == [ + "openai.embeddings", + ] + open_ai_span = spans[0] + assert ( + open_ai_span.attributes["llm.prompts.0.content"] + == "Tell me a joke about opentelemetry" + ) + + assert open_ai_span.attributes["llm.request.model"] == "text-embedding-ada-002" + assert open_ai_span.attributes["llm.usage.prompt_tokens"] == 8 + assert open_ai_span.attributes["openai.api_base"] == "https://api.openai.com/v1/" + + parsed_response = response.parse() + assert parsed_response.data[0] + + @pytest.mark.vcr def test_azure_openai_embeddings(exporter): api_key = "redacted" diff --git a/packages/opentelemetry-instrumentation-openai/tests/test_vision.py b/packages/opentelemetry-instrumentation-openai/tests/test_vision.py index 419214d97..6bf18b035 100644 --- a/packages/opentelemetry-instrumentation-openai/tests/test_vision.py +++ b/packages/opentelemetry-instrumentation-openai/tests/test_vision.py @@ -22,7 +22,7 @@ def test_vision(exporter, openai_client): ], ) - for part in response: + for _ in response: pass spans = exporter.get_finished_spans()