Skip to content

Commit 10ee99e

Browse files
respect data collection
1 parent 736164f commit 10ee99e

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

‎sentry_sdk/integrations/boto3/_services/bedrock.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import json
22
from typing import TYPE_CHECKING
33

4+
import sentry_sdk
45
from sentry_sdk.consts import OP, SPANDATA
56
from sentry_sdk.integrations.boto3._services.base import _ServiceExtension
7+
from sentry_sdk.utils import has_data_collection_enabled
68

79
if TYPE_CHECKING:
810
from typing import Any, Optional
@@ -96,6 +98,11 @@ def get_request_attributes(self, ctx: "AwsCallContext") -> "Attributes":
9698
if top_p is not None:
9799
attributes[SPANDATA.GEN_AI_REQUEST_TOP_P] = top_p
98100

101+
client_options = sentry_sdk.get_client().options
102+
if has_data_collection_enabled(client_options):
103+
if not client_options["data_collection"]["gen_ai"]["inputs"]:
104+
return attributes
105+
99106
tool_config = ctx.params.get("toolConfig")
100107
if not isinstance(tool_config, dict):
101108
return attributes

‎tests/integrations/boto3/test_bedrock.py‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,33 @@ def raise_client_error(**kwargs):
225225
assert span["status"] == "internal_error"
226226

227227

228+
@pytest.mark.parametrize("data_collection", [True, False])
228229
@pytest.mark.parametrize("span_streaming", [True, False])
229230
@pytest.mark.parametrize("stream_gen_ai_spans", [True, False])
230231
def test_converse_tool_definitions(
231232
sentry_init,
232233
capture_items,
233234
capture_events,
235+
data_collection,
234236
span_streaming,
235237
stream_gen_ai_spans,
236238
converse_response,
237239
):
238-
sentry_init(
239-
traces_sample_rate=1.0,
240-
integrations=[Boto3Integration()],
241-
stream_gen_ai_spans=stream_gen_ai_spans,
242-
trace_lifecycle="stream" if span_streaming else "static",
243-
)
240+
if data_collection:
241+
sentry_init(
242+
traces_sample_rate=1.0,
243+
integrations=[Boto3Integration()],
244+
data_collection={"gen_ai": {"inputs": True}},
245+
stream_gen_ai_spans=stream_gen_ai_spans,
246+
trace_lifecycle="stream" if span_streaming else "static",
247+
)
248+
else:
249+
sentry_init(
250+
traces_sample_rate=1.0,
251+
integrations=[Boto3Integration()],
252+
stream_gen_ai_spans=stream_gen_ai_spans,
253+
trace_lifecycle="stream" if span_streaming else "static",
254+
)
244255

245256
tools: list = [
246257
{
@@ -514,21 +525,32 @@ def raise_client_error(**kwargs):
514525
assert span["status"] == "internal_error"
515526

516527

528+
@pytest.mark.parametrize("data_collection", [True, False])
517529
@pytest.mark.parametrize("span_streaming", [True, False])
518530
@pytest.mark.parametrize("stream_gen_ai_spans", [True, False])
519531
def test_converse_stream_tool_definitions(
520532
sentry_init,
521533
capture_items,
522534
capture_events,
535+
data_collection,
523536
span_streaming,
524537
stream_gen_ai_spans,
525538
):
526-
sentry_init(
527-
traces_sample_rate=1.0,
528-
integrations=[Boto3Integration()],
529-
stream_gen_ai_spans=stream_gen_ai_spans,
530-
trace_lifecycle="stream" if span_streaming else "static",
531-
)
539+
if data_collection:
540+
sentry_init(
541+
traces_sample_rate=1.0,
542+
integrations=[Boto3Integration()],
543+
data_collection={"gen_ai": {"inputs": True}},
544+
stream_gen_ai_spans=stream_gen_ai_spans,
545+
trace_lifecycle="stream" if span_streaming else "static",
546+
)
547+
else:
548+
sentry_init(
549+
traces_sample_rate=1.0,
550+
integrations=[Boto3Integration()],
551+
stream_gen_ai_spans=stream_gen_ai_spans,
552+
trace_lifecycle="stream" if span_streaming else "static",
553+
)
532554

533555
tools: list = [
534556
{

0 commit comments

Comments
 (0)