|
7 | 7 |
|
8 | 8 | import sentry_sdk
|
9 | 9 | from sentry_sdk._functools import wraps
|
10 |
| -from sentry_sdk.hub import Hub |
| 10 | +from sentry_sdk.hub import Hub, _should_send_default_pii |
11 | 11 | from sentry_sdk.integrations import DidNotEnable, Integration
|
12 | 12 | from sentry_sdk.utils import logger, capture_internal_exceptions, event_from_exception
|
13 | 13 |
|
@@ -149,12 +149,14 @@ def new_chat_completion(*args, **kwargs):
|
149 | 149 | raise e from None
|
150 | 150 |
|
151 | 151 | with capture_internal_exceptions():
|
152 |
| - span.set_data("messages", messages) |
| 152 | + if _should_send_default_pii(): |
| 153 | + span.set_data("messages", messages) |
153 | 154 | span.set_data("model", model)
|
154 | 155 | span.set_data("streaming", streaming)
|
155 | 156 |
|
156 | 157 | 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) |
158 | 160 | _calculate_chat_completion_usage(messages, res, span)
|
159 | 161 | span.__exit__(None, None, None)
|
160 | 162 | elif hasattr(res, "_iterator"):
|
@@ -182,7 +184,8 @@ def new_iterator():
|
182 | 184 | all_responses = list(
|
183 | 185 | map(lambda chunk: "".join(chunk), data_buf)
|
184 | 186 | )
|
185 |
| - span.set_data("responses", all_responses) |
| 187 | + if _should_send_default_pii(): |
| 188 | + span.set_data("responses", all_responses) |
186 | 189 | _calculate_chat_completion_usage(
|
187 | 190 | messages, res, span, all_responses
|
188 | 191 | )
|
|
0 commit comments