Skip to content

Commit 8abce47

Browse files
committed
feat(ai) adding unpack parameter to set_data_normalized to control whether to automatically unpack single elements in lists
1 parent 115af46 commit 8abce47

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

sentry_sdk/ai/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from sentry_sdk.utils import logger
88

99

10-
def _normalize_data(data):
11-
# type: (Any) -> Any
10+
def _normalize_data(data, unpack=True):
11+
# type: (Any, bool) -> Any
1212

1313
# convert pydantic data (e.g. OpenAI v1+) to json compatible format
1414
if hasattr(data, "model_dump"):
@@ -18,7 +18,7 @@ def _normalize_data(data):
1818
logger.warning("Could not convert pydantic data to JSON: %s", e)
1919
return data
2020
if isinstance(data, list):
21-
if len(data) == 1:
21+
if unpack and len(data) == 1:
2222
return _normalize_data(data[0]) # remove empty dimensions
2323
return list(_normalize_data(x) for x in data)
2424
if isinstance(data, dict):
@@ -27,9 +27,9 @@ def _normalize_data(data):
2727
return data
2828

2929

30-
def set_data_normalized(span, key, value):
31-
# type: (Span, str, Any) -> None
32-
normalized = _normalize_data(value)
30+
def set_data_normalized(span, key, value, unpack=True):
31+
# type: (Span, str, Any, bool) -> None
32+
normalized = _normalize_data(value, unpack=unpack)
3333
if isinstance(normalized, (int, float, bool, str)):
3434
span.set_data(key, normalized)
3535
else:

0 commit comments

Comments
 (0)