Skip to content

Commit d00f21b

Browse files
chore(cohere): Remove include_prompts parameter (#7681)
The parameter allowed users to opt out of collecting GenAI attributes while keeping `send_default_pii=True`. It is ignored when data collection is used, and the major release drops `send_default_pii` in favor of data collection.
1 parent 0b709cf commit d00f21b

2 files changed

Lines changed: 24 additions & 44 deletions

File tree

‎sentry_sdk/integrations/cohere.py‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ class CohereIntegration(Integration):
8080
identifier = "cohere"
8181
origin = f"auto.ai.{identifier}"
8282

83-
def __init__(self: "CohereIntegration", include_prompts: bool = True) -> None:
84-
self.include_prompts = include_prompts
85-
8683
@staticmethod
8784
def setup_once() -> None:
8885
version = parse_version(COHERE_VERSION)
@@ -93,12 +90,12 @@ def setup_once() -> None:
9390
BaseCohere.chat_stream = _wrap_chat(BaseCohere.chat_stream, streaming=True)
9491

9592

96-
def _should_record(integration: "CohereIntegration", category: str) -> bool:
93+
def _should_record(category: str) -> bool:
9794
client = sentry_sdk.get_client()
9895
if has_data_collection_enabled(client.options):
9996
return bool(client.options["data_collection"]["gen_ai"][category])
10097

101-
return should_send_default_pii() and integration.include_prompts
98+
return should_send_default_pii()
10299

103100

104101
def _capture_exception(exc: "Any") -> None:
@@ -180,7 +177,7 @@ def new_chat(*args: "Any", **kwargs: "Any") -> "Any":
180177
reraise(*exc_info)
181178

182179
with capture_internal_exceptions():
183-
if _should_record(integration, "inputs"):
180+
if _should_record("inputs"):
184181
set_data_normalized(
185182
span,
186183
SPANDATA.AI_INPUT_MESSAGES,
@@ -216,7 +213,7 @@ def new_iterator() -> "Iterator[StreamedChatResponse]":
216213
collect_chat_response_fields(
217214
span,
218215
x.response,
219-
include_pii=_should_record(integration, "outputs"),
216+
include_pii=_should_record("outputs"),
220217
)
221218
yield x
222219
span.end()
@@ -226,7 +223,7 @@ def new_iterator() -> "Iterator[StreamedChatResponse]":
226223
collect_chat_response_fields(
227224
span,
228225
res,
229-
include_pii=_should_record(integration, "outputs"),
226+
include_pii=_should_record("outputs"),
230227
)
231228
span.end()
232229
else:
@@ -251,7 +248,7 @@ def new_embed(*args: "Any", **kwargs: "Any") -> "Any":
251248
"sentry.origin": CohereIntegration.origin,
252249
},
253250
) as span:
254-
if "texts" in kwargs and _should_record(integration, "inputs"):
251+
if "texts" in kwargs and _should_record("inputs"):
255252
if isinstance(kwargs["texts"], str):
256253
set_data_normalized(span, SPANDATA.AI_TEXTS, [kwargs["texts"]])
257254
elif (

‎tests/integrations/cohere/test_cohere.py‎

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212

1313

1414
@pytest.mark.parametrize(
15-
"send_default_pii, include_prompts",
16-
[(True, True), (True, False), (False, True), (False, False)],
15+
"send_default_pii",
16+
[True, False],
1717
)
1818
def test_nonstreaming_chat(
1919
sentry_init,
2020
capture_items,
2121
send_default_pii,
22-
include_prompts,
2322
):
2423
sentry_init(
25-
integrations=[CohereIntegration(include_prompts=include_prompts)],
24+
integrations=[CohereIntegration()],
2625
traces_sample_rate=1.0,
2726
send_default_pii=send_default_pii,
2827
)
@@ -59,7 +58,7 @@ def test_nonstreaming_chat(
5958
assert span["attributes"]["sentry.op"] == "ai.chat_completions.create.cohere"
6059
assert span["attributes"][SPANDATA.AI_MODEL_ID] == "some-model"
6160

62-
if send_default_pii and include_prompts:
61+
if send_default_pii:
6362
assert (
6463
'{"role": "system", "content": "some context"}'
6564
in span["attributes"][SPANDATA.AI_INPUT_MESSAGES]
@@ -80,17 +79,16 @@ def test_nonstreaming_chat(
8079

8180
# noinspection PyTypeChecker
8281
@pytest.mark.parametrize(
83-
"send_default_pii, include_prompts",
84-
[(True, True), (True, False), (False, True), (False, False)],
82+
"send_default_pii",
83+
[True, False],
8584
)
8685
def test_streaming_chat(
8786
sentry_init,
8887
capture_items,
8988
send_default_pii,
90-
include_prompts,
9189
):
9290
sentry_init(
93-
integrations=[CohereIntegration(include_prompts=include_prompts)],
91+
integrations=[CohereIntegration()],
9492
traces_sample_rate=1.0,
9593
send_default_pii=send_default_pii,
9694
)
@@ -142,7 +140,7 @@ def test_streaming_chat(
142140
assert span["attributes"]["sentry.op"] == "ai.chat_completions.create.cohere"
143141
assert span["attributes"][SPANDATA.AI_MODEL_ID] == "some-model"
144142

145-
if send_default_pii and include_prompts:
143+
if send_default_pii:
146144
assert (
147145
'{"role": "system", "content": "some context"}'
148146
in span["attributes"][SPANDATA.AI_INPUT_MESSAGES]
@@ -206,17 +204,16 @@ def test_span_status_error(sentry_init, capture_items):
206204

207205

208206
@pytest.mark.parametrize(
209-
"send_default_pii, include_prompts",
210-
[(True, True), (True, False), (False, True), (False, False)],
207+
"send_default_pii",
208+
[True, False],
211209
)
212210
def test_embed(
213211
sentry_init,
214212
capture_items,
215213
send_default_pii,
216-
include_prompts,
217214
):
218215
sentry_init(
219-
integrations=[CohereIntegration(include_prompts=include_prompts)],
216+
integrations=[CohereIntegration()],
220217
traces_sample_rate=1.0,
221218
send_default_pii=send_default_pii,
222219
)
@@ -249,7 +246,7 @@ def test_embed(
249246
span = items[0].payload
250247

251248
assert span["attributes"]["sentry.op"] == "ai.embeddings.create.cohere"
252-
if send_default_pii and include_prompts:
249+
if send_default_pii:
253250
assert "hello" in span["attributes"][SPANDATA.AI_INPUT_MESSAGES]
254251
else:
255252
assert SPANDATA.AI_INPUT_MESSAGES not in span["attributes"]
@@ -326,28 +323,25 @@ def test_span_origin_embed(sentry_init, capture_items):
326323
assert span["attributes"]["sentry.origin"] == "auto.ai.cohere"
327324

328325

329-
# data_collection config, send_default_pii, include_prompts, expect_inputs, expect_outputs
326+
# data_collection config, send_default_pii, expect_inputs, expect_outputs
330327
DATA_COLLECTION_CASES = [
331328
pytest.param(
332329
{"gen_ai": {"inputs": True, "outputs": True}},
333330
False,
334-
False,
335331
True,
336332
True,
337333
id="gen-ai-inputs-and-outputs-enabled-override-legacy-off",
338334
),
339335
pytest.param(
340336
{"gen_ai": {"inputs": False, "outputs": False}},
341337
True,
342-
True,
343338
False,
344339
False,
345340
id="gen-ai-inputs-and-outputs-disabled-override-legacy-on",
346341
),
347342
pytest.param(
348343
{"gen_ai": {"inputs": True, "outputs": False}},
349344
False,
350-
False,
351345
True,
352346
False,
353347
id="gen-ai-inputs-enabled-outputs-disabled",
@@ -356,14 +350,12 @@ def test_span_origin_embed(sentry_init, capture_items):
356350
{"gen_ai": {"inputs": False, "outputs": True}},
357351
False,
358352
False,
359-
False,
360353
True,
361354
id="gen-ai-outputs-enabled-inputs-disabled",
362355
),
363356
pytest.param(
364357
{"gen_ai": {}},
365358
False,
366-
False,
367359
True,
368360
True,
369361
id="gen-ai-inputs-and-outputs-omitted-default-to-enabled",
@@ -373,13 +365,11 @@ def test_span_origin_embed(sentry_init, capture_items):
373365
True,
374366
True,
375367
True,
376-
True,
377-
id="no-gen-ai-config-legacy-pii-and-include-prompts-enabled",
368+
id="no-gen-ai-config-legacy-pii",
378369
),
379370
pytest.param(
380371
None,
381372
False,
382-
True,
383373
False,
384374
False,
385375
id="no-gen-ai-config-legacy-pii-disabled",
@@ -391,10 +381,9 @@ def _init_with_data_collection(
391381
sentry_init,
392382
data_collection,
393383
send_default_pii,
394-
include_prompts,
395384
):
396385
kwargs = dict(
397-
integrations=[CohereIntegration(include_prompts=include_prompts)],
386+
integrations=[CohereIntegration()],
398387
traces_sample_rate=1.0,
399388
send_default_pii=send_default_pii,
400389
)
@@ -405,23 +394,21 @@ def _init_with_data_collection(
405394

406395

407396
@pytest.mark.parametrize(
408-
"data_collection, send_default_pii, include_prompts, expect_inputs, expect_outputs",
397+
"data_collection, send_default_pii, expect_inputs, expect_outputs",
409398
DATA_COLLECTION_CASES,
410399
)
411400
def test_nonstreaming_chat_data_collection(
412401
sentry_init,
413402
capture_items,
414403
data_collection,
415404
send_default_pii,
416-
include_prompts,
417405
expect_inputs,
418406
expect_outputs,
419407
):
420408
_init_with_data_collection(
421409
sentry_init,
422410
data_collection,
423411
send_default_pii,
424-
include_prompts,
425412
)
426413

427414
client = Client(api_key="z")
@@ -483,23 +470,21 @@ def test_nonstreaming_chat_data_collection(
483470

484471

485472
@pytest.mark.parametrize(
486-
"data_collection, send_default_pii, include_prompts, expect_inputs, expect_outputs",
473+
"data_collection, send_default_pii, expect_inputs, expect_outputs",
487474
DATA_COLLECTION_CASES,
488475
)
489476
def test_streaming_chat_data_collection(
490477
sentry_init,
491478
capture_items,
492479
data_collection,
493480
send_default_pii,
494-
include_prompts,
495481
expect_inputs,
496482
expect_outputs,
497483
):
498484
_init_with_data_collection(
499485
sentry_init,
500486
data_collection,
501487
send_default_pii,
502-
include_prompts,
503488
)
504489

505490
client = Client(api_key="z")
@@ -574,23 +559,21 @@ def test_streaming_chat_data_collection(
574559

575560

576561
@pytest.mark.parametrize(
577-
"data_collection, send_default_pii, include_prompts, expect_inputs, expect_outputs",
562+
"data_collection, send_default_pii, expect_inputs, expect_outputs",
578563
DATA_COLLECTION_CASES,
579564
)
580565
def test_embed_data_collection(
581566
sentry_init,
582567
capture_items,
583568
data_collection,
584569
send_default_pii,
585-
include_prompts,
586570
expect_inputs,
587571
expect_outputs,
588572
):
589573
_init_with_data_collection(
590574
sentry_init,
591575
data_collection,
592576
send_default_pii,
593-
include_prompts,
594577
)
595578

596579
client = Client(api_key="z")

0 commit comments

Comments
 (0)