diff --git a/ddtrace/contrib/internal/langchain/patch.py b/ddtrace/contrib/internal/langchain/patch.py index 78738e11281..6fcf9ea53a3 100644 --- a/ddtrace/contrib/internal/langchain/patch.py +++ b/ddtrace/contrib/internal/langchain/patch.py @@ -320,10 +320,13 @@ def _on_span_started(span: Span): integration.record_instance(instance, span) def _on_span_finished(span: Span, streamed_chunks): - joined_chunks = streamed_chunks[0] - for chunk in streamed_chunks[1:]: - joined_chunks += chunk # base message types support __add__ for concatenation kwargs["_dd.identifying_params"] = instance._identifying_params + if len(streamed_chunks): + joined_chunks = streamed_chunks[0] + for chunk in streamed_chunks[1:]: + joined_chunks += chunk # base message types support __add__ for concatenation + else: + joined_chunks = [] integration.llmobs_set_tags(span, args=args, kwargs=kwargs, response=joined_chunks, operation="chat") return shared_stream( diff --git a/releasenotes/notes/langchain-early-stream-end-fix-af9ca6475b3aaf00.yaml b/releasenotes/notes/langchain-early-stream-end-fix-af9ca6475b3aaf00.yaml new file mode 100644 index 00000000000..f77bdb64881 --- /dev/null +++ b/releasenotes/notes/langchain-early-stream-end-fix-af9ca6475b3aaf00.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + langchain: Fixes an issue where streamed responses that end before the first chunk is received would result in an ``IndexError``. diff --git a/tests/contrib/langchain/test_langchain.py b/tests/contrib/langchain/test_langchain.py index dc4e482ca5e..5e202c30a50 100644 --- a/tests/contrib/langchain/test_langchain.py +++ b/tests/contrib/langchain/test_langchain.py @@ -539,3 +539,17 @@ def circumference_tool(radius: float) -> float: ) calculator.invoke("2", config={"unserializable": object()}) + + +@pytest.mark.snapshot(ignores=["meta.error.stack", "meta.error.message"]) +def test_streamed_chat_model_with_no_output(langchain_openai, openai_url): + from openai import APITimeoutError + + chat_model = langchain_openai.ChatOpenAI(base_url=openai_url, timeout=0.0001) + + result = chat_model.stream("Hello, my name is") + try: + next(result) + except Exception as e: + if not isinstance(e, APITimeoutError): + assert False, f"Expected APITimeoutError, got {e}" diff --git a/tests/llmobs/llmobs_cassettes/openai/openai_chat_completions_post_0fdef9ab.yaml b/tests/llmobs/llmobs_cassettes/openai/openai_chat_completions_post_0fdef9ab.yaml new file mode 100644 index 00000000000..9fc3505943a --- /dev/null +++ b/tests/llmobs/llmobs_cassettes/openai/openai_chat_completions_post_0fdef9ab.yaml @@ -0,0 +1,154 @@ +interactions: +- request: + body: '{"messages":[{"content":"Hello, my name is","role":"user"}],"model":"gpt-3.5-turbo","n":1,"stream":true,"temperature":0.7}' + headers: + ? !!python/object/apply:multidict._multidict.istr + - Accept + : - application/json + ? !!python/object/apply:multidict._multidict.istr + - Accept-Encoding + : - gzip, deflate + ? !!python/object/apply:multidict._multidict.istr + - Connection + : - keep-alive + Content-Length: + - '122' + ? !!python/object/apply:multidict._multidict.istr + - Content-Type + : - application/json + ? !!python/object/apply:multidict._multidict.istr + - User-Agent + : - OpenAI/Python 1.109.1 + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Arch + : - arm64 + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Async + : - 'false' + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Lang + : - python + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-OS + : - MacOS + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Package-Version + : - 1.109.1 + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Runtime + : - CPython + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Runtime-Version + : - 3.10.13 + ? !!python/object/apply:multidict._multidict.istr + - x-stainless-read-timeout + : - '0.0001' + ? !!python/object/apply:multidict._multidict.istr + - x-stainless-retry-count + : - '0' + method: POST + uri: https://api.openai.com/v1/chat/completions + response: + body: + string: 'data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"role":"assistant","content":"","refusal":null},"logprobs":null,"finish_reason":null}],"obfuscation":"dDINu"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"Assistant"},"logprobs":null,"finish_reason":null}],"obfuscation":"1yL6DImc2cky67"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"."},"logprobs":null,"finish_reason":null}],"obfuscation":"kyn0dy"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + How"},"logprobs":null,"finish_reason":null}],"obfuscation":"zF8"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + can"},"logprobs":null,"finish_reason":null}],"obfuscation":"ZOA"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + I"},"logprobs":null,"finish_reason":null}],"obfuscation":"yPnQN"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + assist"},"logprobs":null,"finish_reason":null}],"obfuscation":""} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + you"},"logprobs":null,"finish_reason":null}],"obfuscation":"nG8"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + today"},"logprobs":null,"finish_reason":null}],"obfuscation":"a"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"?"},"logprobs":null,"finish_reason":null}],"obfuscation":"KxSued"} + + + data: {"id":"chatcmpl-CTDgKS9E25YxCQOhLhNmhfOPiznNk","object":"chat.completion.chunk","created":1761080140,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}],"obfuscation":"Q"} + + + data: [DONE] + + + ' + headers: + CF-RAY: + - 9923a83a5cd9081d-IAD + Connection: + - keep-alive + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 21 Oct 2025 20:55:40 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=o7TNYeatXbBOlFxeMlhl.8fe7kXVRNTm_dL98zIje8M-1761080140-1.0.1.1-FRpu._KCnEk.aGZG5YQ75Od_Ucq8okx9WLNY3JjdbbK3P7mwxS21FIvTtyY6GlllpujKEYLWkFHG6VIIw4zZmwH0yDL04t_gvEzyjWwc1qc; + path=/; expires=Tue, 21-Oct-25 21:25:40 GMT; domain=.api.openai.com; HttpOnly; + Secure; SameSite=None + - _cfuvid=bZiyEgtQ9lNlCOG2DaVgkJLkXs33574MrsoVFl0iIf4-1761080140438-0.0.1.1-604800000; + path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Transfer-Encoding: + - chunked + X-Content-Type-Options: + - nosniff + access-control-expose-headers: + - X-Request-ID + alt-svc: + - h3=":443"; ma=86400 + cf-cache-status: + - DYNAMIC + openai-organization: + - datadog-staging + openai-processing-ms: + - '151' + openai-project: + - proj_gt6TQZPRbZfoY2J9AQlEJMpd + openai-version: + - '2020-10-01' + x-envoy-upstream-service-time: + - '174' + x-openai-proxy-wasm: + - v0.1 + x-ratelimit-limit-requests: + - '10000' + x-ratelimit-limit-tokens: + - '50000000' + x-ratelimit-remaining-requests: + - '9999' + x-ratelimit-remaining-tokens: + - '49999993' + x-ratelimit-reset-requests: + - 6ms + x-ratelimit-reset-tokens: + - 0s + x-request-id: + - req_c9c685c9da2e4684b4613cefd4af98e8 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/llmobs/llmobs_cassettes/openai/openai_chat_completions_post_eb4ba851.yaml b/tests/llmobs/llmobs_cassettes/openai/openai_chat_completions_post_eb4ba851.yaml new file mode 100644 index 00000000000..7703a1fe8be --- /dev/null +++ b/tests/llmobs/llmobs_cassettes/openai/openai_chat_completions_post_eb4ba851.yaml @@ -0,0 +1,154 @@ +interactions: +- request: + body: '{"messages":[{"content":"Hello, my name is","role":"user"}],"model":"gpt-3.5-turbo","stream":true}' + headers: + ? !!python/object/apply:multidict._multidict.istr + - Accept + : - application/json + ? !!python/object/apply:multidict._multidict.istr + - Accept-Encoding + : - gzip, deflate, zstd + ? !!python/object/apply:multidict._multidict.istr + - Connection + : - keep-alive + Content-Length: + - '98' + ? !!python/object/apply:multidict._multidict.istr + - Content-Type + : - application/json + ? !!python/object/apply:multidict._multidict.istr + - User-Agent + : - OpenAI/Python 1.109.1 + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Arch + : - arm64 + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Async + : - 'false' + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Lang + : - python + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-OS + : - MacOS + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Package-Version + : - 1.109.1 + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Runtime + : - CPython + ? !!python/object/apply:multidict._multidict.istr + - X-Stainless-Runtime-Version + : - 3.10.13 + ? !!python/object/apply:multidict._multidict.istr + - x-stainless-read-timeout + : - '0.0001' + ? !!python/object/apply:multidict._multidict.istr + - x-stainless-retry-count + : - '0' + method: POST + uri: https://api.openai.com/v1/chat/completions + response: + body: + string: 'data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"role":"assistant","content":"","refusal":null},"logprobs":null,"finish_reason":null}],"obfuscation":"GHVuj"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"Assistant"},"logprobs":null,"finish_reason":null}],"obfuscation":"x2EMmcLlO3ecwG"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"."},"logprobs":null,"finish_reason":null}],"obfuscation":"TQ802v"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + How"},"logprobs":null,"finish_reason":null}],"obfuscation":"XKe"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + can"},"logprobs":null,"finish_reason":null}],"obfuscation":"kcL"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + I"},"logprobs":null,"finish_reason":null}],"obfuscation":"iYfTx"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + assist"},"logprobs":null,"finish_reason":null}],"obfuscation":""} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + you"},"logprobs":null,"finish_reason":null}],"obfuscation":"3qp"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":" + today"},"logprobs":null,"finish_reason":null}],"obfuscation":"Q"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{"content":"?"},"logprobs":null,"finish_reason":null}],"obfuscation":"rxGZdS"} + + + data: {"id":"chatcmpl-CTDgOzn7iu7WvRbPx6d7DKv4jisZ1","object":"chat.completion.chunk","created":1761080144,"model":"gpt-3.5-turbo-0125","service_tier":"default","system_fingerprint":null,"choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}],"obfuscation":"q"} + + + data: [DONE] + + + ' + headers: + CF-RAY: + - 9923a8557c58310c-IAD + Connection: + - keep-alive + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 21 Oct 2025 20:55:44 GMT + Server: + - cloudflare + Set-Cookie: + - __cf_bm=BNW6cRDCKHu3RmqDR.YwTVZBl0oaF1KmyP7rFJOVJh8-1761080144-1.0.1.1-Em.1pj_MusLdRZAzfxs.tpO51tHRIUprKfWcjhgW3dWoSXLap2PB6YRiem.DU.MG8NVyMIQkwW6W_JUxa_NnHFenF.ejDJXGieRs0VvP6cs; + path=/; expires=Tue, 21-Oct-25 21:25:44 GMT; domain=.api.openai.com; HttpOnly; + Secure; SameSite=None + - _cfuvid=ue2PaSkW.MPXEVwGniK0_bY41_Ri3BTQdhJbM_FzhWo-1761080144466-0.0.1.1-604800000; + path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Transfer-Encoding: + - chunked + X-Content-Type-Options: + - nosniff + access-control-expose-headers: + - X-Request-ID + alt-svc: + - h3=":443"; ma=86400 + cf-cache-status: + - DYNAMIC + openai-organization: + - datadog-staging + openai-processing-ms: + - '134' + openai-project: + - proj_gt6TQZPRbZfoY2J9AQlEJMpd + openai-version: + - '2020-10-01' + x-envoy-upstream-service-time: + - '151' + x-openai-proxy-wasm: + - v0.1 + x-ratelimit-limit-requests: + - '10000' + x-ratelimit-limit-tokens: + - '50000000' + x-ratelimit-remaining-requests: + - '9999' + x-ratelimit-remaining-tokens: + - '49999993' + x-ratelimit-reset-requests: + - 6ms + x-ratelimit-reset-tokens: + - 0s + x-request-id: + - req_396d9ab42a15454bbc29de5853e2bad7 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/snapshots/tests.contrib.langchain.test_langchain.test_streamed_chat_model_with_no_output.json b/tests/snapshots/tests.contrib.langchain.test_langchain.test_streamed_chat_model_with_no_output.json new file mode 100644 index 00000000000..e6f9c47e260 --- /dev/null +++ b/tests/snapshots/tests.contrib.langchain.test_langchain.test_streamed_chat_model_with_no_output.json @@ -0,0 +1,32 @@ +[[ + { + "name": "langchain.request", + "service": "tests.contrib.langchain", + "resource": "langchain_openai.chat_models.base.ChatOpenAI", + "trace_id": 0, + "span_id": 1, + "parent_id": 0, + "type": "", + "error": 1, + "meta": { + "_dd.p.dm": "-0", + "_dd.p.tid": "68ff826100000000", + "error.message": "Request timed out.", + "error.stack": "Traceback (most recent call last):\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpx/_transports/default.py\", line 101, in map_httpcore_exceptions\n yield\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpx/_transports/default.py\", line 250, in handle_request\n resp = self._pool.handle_request(req)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py\", line 256, in handle_request\n raise exc from None\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py\", line 236, in handle_request\n response = connection.handle_request(\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_sync/connection.py\", line 103, in handle_request\n return self._connection.handle_request(request)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_sync/http11.py\", line 136, in handle_request\n raise exc\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_sync/http11.py\", line 106, in handle_request\n ) = self._receive_response_headers(**kwargs)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_sync/http11.py\", line 177, in _receive_response_headers\n event = self._receive_event(timeout=timeout)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_sync/http11.py\", line 217, in _receive_event\n data = self._network_stream.read(\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_backends/sync.py\", line 126, in read\n with map_exceptions(exc_map):\n File \"/Users/sam.brenner/.pyenv/versions/3.10.13/lib/python3.10/contextlib.py\", line 153, in __exit__\n self.gen.throw(typ, value, traceback)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpcore/_exceptions.py\", line 14, in map_exceptions\n raise to_exc(exc) from exc\nhttpcore.ReadTimeout: timed out\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/openai/_base_client.py\", line 982, in request\n response = self._client.send(\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpx/_client.py\", line 914, in send\n response = self._send_handling_auth(\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpx/_client.py\", line 942, in _send_handling_auth\n response = self._send_handling_redirects(\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpx/_client.py\", line 979, in _send_handling_redirects\n response = self._send_single_request(request)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpx/_client.py\", line 1014, in _send_single_request\n response = transport.handle_request(request)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpx/_transports/default.py\", line 249, in handle_request\n with map_httpcore_exceptions():\n File \"/Users/sam.brenner/.pyenv/versions/3.10.13/lib/python3.10/contextlib.py\", line 153, in __exit__\n self.gen.throw(typ, value, traceback)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/httpx/_transports/default.py\", line 118, in map_httpcore_exceptions\n raise mapped_exc(message) from exc\nhttpx.ReadTimeout: timed out\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/Users/sam.brenner/dd/dd-trace-py/ddtrace/llmobs/_integrations/base_stream_handler.py\", line 152, in __next__\n chunk = self._self_stream_iter.__next__()\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py\", line 249, in stream\n raise e\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py\", line 229, in stream\n for chunk in self._stream(messages, stop=stop, **kwargs):\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/langchain_openai/chat_models/base.py\", line 480, in _stream\n with self.client.create(messages=message_dicts, **params) as response:\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/openai/_utils/_utils.py\", line 286, in wrapper\n return func(*args, **kwargs)\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/openai/resources/chat/completions/completions.py\", line 1147, in create\n return self._post(\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/openai/_base_client.py\", line 1259, in post\n return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n File \"/Users/sam.brenner/dd/dd-trace-py/.riot/venv_py31013_1d20b7813b162e46/lib/python3.10/site-packages/openai/_base_client.py\", line 1000, in request\n raise APITimeoutError(request=request) from err\nopenai.APITimeoutError: Request timed out.\n", + "error.type": "openai.APITimeoutError", + "langchain.request.model": "gpt-3.5-turbo", + "langchain.request.provider": "openai-chat", + "langchain.request.stream": "True", + "language": "python", + "runtime-id": "a88172c22f794f34aef48ae5702559f7" + }, + "metrics": { + "_dd.measured": 1, + "_dd.top_level": 1, + "_dd.tracer_kr": 1.0, + "_sampling_priority_v1": 1, + "process_id": 25191 + }, + "duration": 1359034000, + "start": 1761575521237281000 + }]]