|
7 | 7 | from httpx import Client as HTTPXClient |
8 | 8 |
|
9 | 9 | import sentry_sdk |
10 | | -from sentry_sdk import start_transaction |
11 | 10 | from sentry_sdk.consts import SPANDATA |
12 | 11 | from sentry_sdk.integrations.cohere import CohereIntegration |
13 | 12 |
|
@@ -46,12 +45,11 @@ def test_nonstreaming_chat( |
46 | 45 | ) |
47 | 46 | items = capture_items("span") |
48 | 47 |
|
49 | | - with start_transaction(name="cohere tx"): |
50 | | - response = client.chat( |
51 | | - model="some-model", |
52 | | - chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
53 | | - message="hello", |
54 | | - ).text |
| 48 | + response = client.chat( |
| 49 | + model="some-model", |
| 50 | + chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
| 51 | + message="hello", |
| 52 | + ).text |
55 | 53 |
|
56 | 54 | assert response == "the model response" |
57 | 55 | sentry_sdk.flush() |
@@ -128,15 +126,14 @@ def test_streaming_chat( |
128 | 126 | ) |
129 | 127 | items = capture_items("span") |
130 | 128 |
|
131 | | - with start_transaction(name="cohere tx"): |
132 | | - responses = list( |
133 | | - client.chat_stream( |
134 | | - model="some-model", |
135 | | - chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
136 | | - message="hello", |
137 | | - ) |
| 129 | + responses = list( |
| 130 | + client.chat_stream( |
| 131 | + model="some-model", |
| 132 | + chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
| 133 | + message="hello", |
138 | 134 | ) |
139 | | - response_string = responses[-1].response.text |
| 135 | + ) |
| 136 | + response_string = responses[-1].response.text |
140 | 137 |
|
141 | 138 | assert response_string == "the model response" |
142 | 139 | sentry_sdk.flush() |
@@ -202,9 +199,8 @@ def test_span_status_error(sentry_init, capture_items): |
202 | 199 | HTTPXClient.request = mock.Mock( |
203 | 200 | side_effect=httpx.HTTPError("API rate limit reached") |
204 | 201 | ) |
205 | | - with start_transaction(name="test"): |
206 | | - with pytest.raises(httpx.HTTPError): |
207 | | - client.chat(model="some-model", message="hello") |
| 202 | + with pytest.raises(httpx.HTTPError): |
| 203 | + client.chat(model="some-model", message="hello") |
208 | 204 |
|
209 | 205 | sentry_sdk.flush() |
210 | 206 |
|
@@ -249,8 +245,7 @@ def test_embed( |
249 | 245 | ) |
250 | 246 | items = capture_items("span") |
251 | 247 |
|
252 | | - with start_transaction(name="cohere tx"): |
253 | | - response = client.embed(texts=["hello"], model="text-embedding-3-large") |
| 248 | + response = client.embed(texts=["hello"], model="text-embedding-3-large") |
254 | 249 |
|
255 | 250 | assert len(response.embeddings[0]) == 3 |
256 | 251 | sentry_sdk.flush() |
@@ -293,12 +288,11 @@ def test_span_origin_chat(sentry_init, capture_items): |
293 | 288 | ) |
294 | 289 | ) |
295 | 290 |
|
296 | | - with start_transaction(name="cohere tx"): |
297 | | - client.chat( |
298 | | - model="some-model", |
299 | | - chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
300 | | - message="hello", |
301 | | - ).text |
| 291 | + client.chat( |
| 292 | + model="some-model", |
| 293 | + chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
| 294 | + message="hello", |
| 295 | + ).text |
302 | 296 |
|
303 | 297 | sentry_sdk.flush() |
304 | 298 | (span,) = (item.payload for item in items) |
@@ -332,8 +326,7 @@ def test_span_origin_embed(sentry_init, capture_items): |
332 | 326 | ) |
333 | 327 | ) |
334 | 328 |
|
335 | | - with start_transaction(name="cohere tx"): |
336 | | - client.embed(texts=["hello"], model="text-embedding-3-large") |
| 329 | + client.embed(texts=["hello"], model="text-embedding-3-large") |
337 | 330 |
|
338 | 331 | sentry_sdk.flush() |
339 | 332 | (span,) = (item.payload for item in items) |
@@ -465,13 +458,12 @@ def test_nonstreaming_chat_data_collection( |
465 | 458 | ) |
466 | 459 | items = capture_items("span") |
467 | 460 |
|
468 | | - with start_transaction(name="cohere tx"): |
469 | | - client.chat( |
470 | | - model="some-model", |
471 | | - chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
472 | | - message="hello", |
473 | | - preamble="be concise", |
474 | | - ) |
| 461 | + client.chat( |
| 462 | + model="some-model", |
| 463 | + chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
| 464 | + message="hello", |
| 465 | + preamble="be concise", |
| 466 | + ) |
475 | 467 | sentry_sdk.flush() |
476 | 468 | assert len(items) == 1 |
477 | 469 | attributes = items[0].payload["attributes"] |
@@ -556,15 +548,14 @@ def test_streaming_chat_data_collection( |
556 | 548 | ) |
557 | 549 | items = capture_items("span") |
558 | 550 |
|
559 | | - with start_transaction(name="cohere tx"): |
560 | | - list( |
561 | | - client.chat_stream( |
562 | | - model="some-model", |
563 | | - chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
564 | | - message="hello", |
565 | | - preamble="be concise", |
566 | | - ) |
| 551 | + list( |
| 552 | + client.chat_stream( |
| 553 | + model="some-model", |
| 554 | + chat_history=[ChatMessage(role="SYSTEM", message="some context")], |
| 555 | + message="hello", |
| 556 | + preamble="be concise", |
567 | 557 | ) |
| 558 | + ) |
568 | 559 | sentry_sdk.flush() |
569 | 560 | assert len(items) == 1 |
570 | 561 | attributes = items[0].payload["attributes"] |
@@ -629,8 +620,7 @@ def test_embed_data_collection( |
629 | 620 | ) |
630 | 621 | items = capture_items("span") |
631 | 622 |
|
632 | | - with start_transaction(name="cohere tx"): |
633 | | - client.embed(texts=["hello"], model="text-embedding-3-large") |
| 623 | + client.embed(texts=["hello"], model="text-embedding-3-large") |
634 | 624 | sentry_sdk.flush() |
635 | 625 | assert len(items) == 1 |
636 | 626 | attributes = items[0].payload["attributes"] |
|
0 commit comments