Skip to content

Commit 8a482c4

Browse files
committed
Merge branch 'log_batcher' of github.com:getsentry/sentry-python into log_batcher
2 parents e589594 + 709d504 commit 8a482c4

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

sentry_sdk/_log_batcher.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import json
21
import os
32
import random
43
import threading
54
from datetime import datetime, timezone
65
from typing import Optional, List, Callable, TYPE_CHECKING, Any
76

8-
from sentry_sdk.utils import format_timestamp
7+
from sentry_sdk.utils import format_timestamp, safe_repr
98
from sentry_sdk.envelope import Envelope
109

1110
if TYPE_CHECKING:
@@ -110,7 +109,7 @@ def format_attribute(key, val):
110109
return {"key": key, "value": {"doubleValue": val}}
111110
if isinstance(val, str):
112111
return {"key": key, "value": {"stringValue": val}}
113-
return {"key": key, "value": {"stringValue": json.dumps(val)}}
112+
return {"key": key, "value": {"stringValue": safe_repr(val)}}
114113

115114
otel_log = {
116115
"severityText": log["severity_text"],

sentry_sdk/integrations/anthropic.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ def new_iterator():
184184
input_tokens, output_tokens, content_blocks = _collect_ai_data(
185185
event, input_tokens, output_tokens, content_blocks
186186
)
187-
if event.type != "message_stop":
188-
yield event
187+
yield event
189188

190189
_add_ai_data_to_span(
191190
span, integration, input_tokens, output_tokens, content_blocks
@@ -202,8 +201,7 @@ async def new_iterator_async():
202201
input_tokens, output_tokens, content_blocks = _collect_ai_data(
203202
event, input_tokens, output_tokens, content_blocks
204203
)
205-
if event.type != "message_stop":
206-
yield event
204+
yield event
207205

208206
_add_ai_data_to_span(
209207
span, integration, input_tokens, output_tokens, content_blocks

sentry_sdk/integrations/logging.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ def _capture_log_from_record(client, record):
365365
if isinstance(record.args, tuple):
366366
for i, arg in enumerate(record.args):
367367
attrs[f"sentry.message.parameters.{i}"] = (
368-
arg if isinstance(arg, str) else safe_repr(arg)
368+
arg
369+
if isinstance(arg, str)
370+
or isinstance(arg, float)
371+
or isinstance(arg, int)
372+
or isinstance(arg, bool)
373+
else safe_repr(arg)
369374
)
370375
if record.lineno:
371376
attrs["code.line.number"] = record.lineno

sentry_sdk/logger.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ def _capture_log(severity_text, severity_number, template, **kwargs):
1818
if "attributes" in kwargs:
1919
attrs.update(kwargs.pop("attributes"))
2020
for k, v in kwargs.items():
21-
attrs[f"sentry.message.parameters.{k}"] = (
21+
attrs[f"sentry.message.parameters.{k}"] = v
22+
23+
attrs = {
24+
k: (
2225
v
2326
if (
2427
isinstance(v, str)
@@ -28,6 +31,8 @@ def _capture_log(severity_text, severity_number, template, **kwargs):
2831
)
2932
else safe_repr(v)
3033
)
34+
for (k, v) in attrs.items()
35+
}
3136

3237
# noinspection PyProtectedMember
3338
client._capture_experimental_log(

0 commit comments

Comments
 (0)