Skip to content

Commit 42f1fb8

Browse files
committed
Fixed boolValue
1 parent 176f45e commit 42f1fb8

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

sentry_sdk/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,14 +909,14 @@ def capture_log(self, scope, severity_text, severity_number, template, **kwargs)
909909

910910
def format_attribute(key, val):
911911
# type: (str, int | float | str | bool) -> Any
912+
if isinstance(val, bool):
913+
return {"key": key, "value": {"boolValue": val}}
912914
if isinstance(val, int):
913915
return {"key": key, "value": {"intValue": str(val)}}
914-
if isinstance(val, str):
915-
return {"key": key, "value": {"stringValue": val}}
916916
if isinstance(val, float):
917917
return {"key": key, "value": {"doubleValue": val}}
918-
if isinstance(val, bool):
919-
return {"key": key, "value": {"boolValue": val}}
918+
if isinstance(val, str):
919+
return {"key": key, "value": {"stringValue": val}}
920920
return {"key": key, "value": {"stringValue": json.dumps(val)}}
921921

922922
otel_log = {

tests/test_sentry_logs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import random
21
from unittest import mock
32

43
import sentry_sdk
@@ -102,7 +101,7 @@ def test_logs_attributes(sentry_init, capture_envelopes):
102101

103102
assert log_item["attributes"][1] == {"key": "attr_int", "value": {"intValue": "1"}} # TODO: this is strange.
104103
assert log_item["attributes"][2] == {"key": "attr_float", "value": {"doubleValue": 2.0}}
105-
assert log_item["attributes"][3] == {"key": "attr_bool", "value": {"intValue": "True"}} # TODO: this is strange.
104+
assert log_item["attributes"][3] == {"key": "attr_bool", "value": {"boolValue": True}}
106105
assert log_item["attributes"][4] == {"key": "attr_string", "value": {"stringValue": "string attribute"}}
107106
assert log_item["attributes"][5] == {"key": "sentry.environment", "value": {"stringValue": "production"}}
108107
assert log_item["attributes"][6] == {"key": "sentry.release", "value": {"stringValue": mock.ANY}}
@@ -128,7 +127,7 @@ def test_logs_message_params(sentry_init, capture_envelopes):
128127
assert envelopes[1].items[0].payload.json["attributes"][-1] == {"key": "sentry.message.parameters.float_var", "value": {'doubleValue': 2.0}}
129128

130129
assert envelopes[2].items[0].payload.json["body"]["stringValue"] == "The recorded value was 'False'"
131-
assert envelopes[2].items[0].payload.json["attributes"][-1] == {"key": "sentry.message.parameters.bool_var", "value": {'intValue': "False"}} # TODO: this is strange.
130+
assert envelopes[2].items[0].payload.json["attributes"][-1] == {"key": "sentry.message.parameters.bool_var", "value": {'boolValue': False}}
132131

133132
assert envelopes[3].items[0].payload.json["body"]["stringValue"] == "The recorded value was 'some string value'"
134133
assert envelopes[3].items[0].payload.json["attributes"][-1] == {"key": "sentry.message.parameters.string_var", "value": {'stringValue': "some string value"}}

0 commit comments

Comments
 (0)