|
4 | 4 | from typing import Any, TYPE_CHECKING |
5 | 5 |
|
6 | 6 | import sentry_sdk |
7 | | -from sentry_sdk.utils import safe_repr, capture_internal_exceptions |
| 7 | +from sentry_sdk.utils import format_attribute, safe_repr, capture_internal_exceptions |
8 | 8 |
|
9 | 9 | if TYPE_CHECKING: |
10 | 10 | from sentry_sdk._types import Attributes, Log |
@@ -34,29 +34,27 @@ def _capture_log( |
34 | 34 | ) -> None: |
35 | 35 | body = template |
36 | 36 |
|
37 | | - attrs: "Attributes" = {} |
| 37 | + attributes: "Attributes" = {} |
38 | 38 |
|
39 | 39 | if "attributes" in kwargs: |
40 | | - attrs.update(kwargs.pop("attributes")) |
| 40 | + for attribute, value in kwargs["attributes"] or {}: |
| 41 | + attributes[attribute] = format_attribute(value) |
41 | 42 |
|
42 | 43 | for k, v in kwargs.items(): |
43 | | - attrs[f"sentry.message.parameter.{k}"] = v |
| 44 | + attributes[f"sentry.message.parameter.{k}"] = format_attribute(v) |
44 | 45 |
|
45 | 46 | if kwargs: |
46 | 47 | # only attach template if there are parameters |
47 | | - attrs["sentry.message.template"] = template |
| 48 | + attributes["sentry.message.template"] = format_attribute(template) |
48 | 49 |
|
49 | 50 | with capture_internal_exceptions(): |
50 | 51 | body = template.format_map(_dict_default_key(kwargs)) |
51 | 52 |
|
52 | | - for k, v in attrs.items(): |
53 | | - attrs[k] = v if isinstance(v, (str, int, bool, float)) else safe_repr(v) |
54 | | - |
55 | 53 | sentry_sdk.get_current_scope()._capture_log( |
56 | 54 | { |
57 | 55 | "severity_text": severity_text, |
58 | 56 | "severity_number": severity_number, |
59 | | - "attributes": attrs, |
| 57 | + "attributes": attributes, |
60 | 58 | "body": body, |
61 | 59 | "time_unix_nano": time.time_ns(), |
62 | 60 | "trace_id": None, |
|
0 commit comments