Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ def _fill_sample_rand(self):
)
return

self.dynamic_sampling_context["sample_rand"] = f"{sample_rand:.6f}" # noqa: E231
self.dynamic_sampling_context["sample_rand"] = (
f"{sample_rand:.6f}" # noqa: E231
)

def _sample_rand(self):
# type: () -> Optional[str]
Expand Down Expand Up @@ -1030,27 +1032,21 @@ def _get_input_attributes(template, send_pii, args, kwargs):
"top_k": (SPANDATA.GEN_AI_REQUEST_TOP_K, int),
}

def _set_from_key(key, value):
# type: (str, Any) -> None
if key in mapping:
(attribute, data_type) = mapping[key]
if value is not None and isinstance(value, data_type):
attributes[attribute] = value

for key, value in list(kwargs.items()):
for key, value in kwargs.items():
if key == "prompt" and isinstance(value, str):
attributes.setdefault(SPANDATA.GEN_AI_REQUEST_MESSAGES, []).append(
{"role": "user", "content": value}
)
messages = attributes.setdefault(SPANDATA.GEN_AI_REQUEST_MESSAGES, [])
messages.append({"role": "user", "content": value})
continue

if key == "system_prompt" and isinstance(value, str):
attributes.setdefault(SPANDATA.GEN_AI_REQUEST_MESSAGES, []).append(
{"role": "system", "content": value}
)
messages = attributes.setdefault(SPANDATA.GEN_AI_REQUEST_MESSAGES, [])
messages.append({"role": "system", "content": value})
continue

_set_from_key(key, value)
if key in mapping:
attribute, data_type = mapping[key]
if value is not None and isinstance(value, data_type):
attributes[attribute] = value

if template == SPANTEMPLATE.AI_TOOL and send_pii:
attributes[SPANDATA.GEN_AI_TOOL_INPUT] = safe_repr(
Expand Down