Skip to content

Commit 1ad9ea9

Browse files
committed
fix(openai-v2): accept APITimeoutError in bad-endpoint tests for Windows
On Windows, connecting to localhost:4242 with timeout=0.1s raises APITimeoutError (TCP SYN retries) instead of APIConnectionError (immediate ECONNREFUSED on Unix). Both indicate unreachable endpoint. Made-with: Cursor
1 parent d5536eb commit 1ad9ea9

3 files changed

Lines changed: 15 additions & 18 deletions

File tree

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_async_chat_completions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ async def test_async_chat_completion_bad_endpoint(
128128
spans[0], llm_model_value, server_address="localhost"
129129
)
130130
assert 4242 == spans[0].attributes[ServerAttributes.SERVER_PORT]
131-
assert (
132-
"APIConnectionError" == spans[0].attributes[ErrorAttributes.ERROR_TYPE]
131+
assert spans[0].attributes[ErrorAttributes.ERROR_TYPE] in (
132+
"APIConnectionError",
133+
"APITimeoutError",
133134
)
134135

135136

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_chat_completions.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ def test_chat_completion_bad_endpoint(
176176
spans[0], llm_model_value, server_address="localhost"
177177
)
178178
assert 4242 == spans[0].attributes[ServerAttributes.SERVER_PORT]
179-
assert (
180-
"APIConnectionError" == spans[0].attributes[ErrorAttributes.ERROR_TYPE]
179+
assert spans[0].attributes[ErrorAttributes.ERROR_TYPE] in (
180+
"APIConnectionError",
181+
"APITimeoutError",
181182
)
182183

183184
metrics = metric_reader.get_metrics_data().resource_metrics
@@ -194,12 +195,9 @@ def test_chat_completion_bad_endpoint(
194195
)
195196
assert duration_metric is not None
196197
assert duration_metric.data.data_points[0].sum > 0
197-
assert (
198-
duration_metric.data.data_points[0].attributes[
199-
ErrorAttributes.ERROR_TYPE
200-
]
201-
== "APIConnectionError"
202-
)
198+
assert duration_metric.data.data_points[0].attributes[
199+
ErrorAttributes.ERROR_TYPE
200+
] in ("APIConnectionError", "APITimeoutError")
203201

204202

205203
@pytest.mark.vcr()

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_embeddings.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ def test_embeddings_bad_endpoint(
214214
server_address="localhost",
215215
)
216216
assert 4242 == spans[0].attributes[ServerAttributes.SERVER_PORT]
217-
assert (
218-
"APIConnectionError" == spans[0].attributes[ErrorAttributes.ERROR_TYPE]
217+
assert spans[0].attributes[ErrorAttributes.ERROR_TYPE] in (
218+
"APIConnectionError",
219+
"APITimeoutError",
219220
)
220221

221222
# Verify metrics
@@ -233,12 +234,9 @@ def test_embeddings_bad_endpoint(
233234
)
234235
assert duration_metric is not None
235236
assert duration_metric.data.data_points[0].sum > 0
236-
assert (
237-
duration_metric.data.data_points[0].attributes[
238-
ErrorAttributes.ERROR_TYPE
239-
]
240-
== "APIConnectionError"
241-
)
237+
assert duration_metric.data.data_points[0].attributes[
238+
ErrorAttributes.ERROR_TYPE
239+
] in ("APIConnectionError", "APITimeoutError")
242240

243241

244242
@pytest.mark.vcr()

0 commit comments

Comments
 (0)