Skip to content

Commit 2a47ca5

Browse files
committed
PII gate the request and response
1 parent 51b20bb commit 2a47ca5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sentry_sdk/integrations/openai.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import sentry_sdk
99
from sentry_sdk._functools import wraps
10-
from sentry_sdk.hub import Hub
10+
from sentry_sdk.hub import Hub, _should_send_default_pii
1111
from sentry_sdk.integrations import DidNotEnable, Integration
1212
from sentry_sdk.utils import logger, capture_internal_exceptions, event_from_exception
1313

@@ -149,12 +149,14 @@ def new_chat_completion(*args, **kwargs):
149149
raise e from None
150150

151151
with capture_internal_exceptions():
152-
span.set_data("messages", messages)
152+
if _should_send_default_pii():
153+
span.set_data("messages", messages)
153154
span.set_data("model", model)
154155
span.set_data("streaming", streaming)
155156

156157
if hasattr(res, "choices"):
157-
span.set_data("response", res.choices[0].message)
158+
if _should_send_default_pii():
159+
span.set_data("response", res.choices[0].message)
158160
_calculate_chat_completion_usage(messages, res, span)
159161
span.__exit__(None, None, None)
160162
elif hasattr(res, "_iterator"):
@@ -182,7 +184,8 @@ def new_iterator():
182184
all_responses = list(
183185
map(lambda chunk: "".join(chunk), data_buf)
184186
)
185-
span.set_data("responses", all_responses)
187+
if _should_send_default_pii():
188+
span.set_data("responses", all_responses)
186189
_calculate_chat_completion_usage(
187190
messages, res, span, all_responses
188191
)

0 commit comments

Comments
 (0)