Skip to content

Commit 14246d6

Browse files
committed
Rename import to sentry_sdk.logger, export Log type
1 parent 8b40aa0 commit 14246d6

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

sentry_sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"start_transaction",
4646
"trace",
4747
"monitor",
48-
"_experimental_logger",
48+
"logger",
4949
]
5050

5151
# Initialize the debug support after everything is loaded

sentry_sdk/_experimental_logger.py renamed to sentry_sdk/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def _capture_log(severity_text, severity_number, template, **kwargs):
1717
if "attributes" in kwargs:
1818
attrs.update(kwargs.pop("attributes"))
1919
for k, v in kwargs.items():
20-
attrs[f"sentry.message.parameters.{k}"] = v
20+
attrs[f"sentry.message.parameters.{k}"] = v if isinstance(v, str) else repr(v)
2121

2222
# noinspection PyProtectedMember
2323
client._capture_experimental_log(
@@ -36,6 +36,6 @@ def _capture_log(severity_text, severity_number, template, **kwargs):
3636
trace = functools.partial(_capture_log, "trace", 1)
3737
debug = functools.partial(_capture_log, "debug", 5)
3838
info = functools.partial(_capture_log, "info", 9)
39-
warn = functools.partial(_capture_log, "warn", 13)
39+
warning = functools.partial(_capture_log, "warning", 13)
4040
error = functools.partial(_capture_log, "error", 17)
4141
fatal = functools.partial(_capture_log, "fatal", 21)

sentry_sdk/types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import TYPE_CHECKING
1212

1313
if TYPE_CHECKING:
14-
from sentry_sdk._types import Event, EventDataCategory, Hint
14+
from sentry_sdk._types import Event, EventDataCategory, Hint, Log
1515
else:
1616
from typing import Any
1717

@@ -20,5 +20,6 @@
2020
Event = Any
2121
EventDataCategory = Any
2222
Hint = Any
23+
Log = Any
2324

24-
__all__ = ("Event", "EventDataCategory", "Hint")
25+
__all__ = ("Event", "EventDataCategory", "Hint", "Log")

tests/test_logs.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66

77
import sentry_sdk
8-
from sentry_sdk import _experimental_logger as sentry_logger
98
from sentry_sdk.integrations.logging import LoggingIntegration
109

1110
minimum_python_37 = pytest.mark.skipif(
@@ -25,12 +24,12 @@ def test_logs_disabled_by_default(sentry_init, capture_envelopes):
2524

2625
envelopes = capture_envelopes()
2726

28-
sentry_logger.trace("This is a 'trace' log.")
29-
sentry_logger.debug("This is a 'debug' log...")
30-
sentry_logger.info("This is a 'info' log...")
31-
sentry_logger.warn("This is a 'warn' log...")
32-
sentry_logger.error("This is a 'error' log...")
33-
sentry_logger.fatal("This is a 'fatal' log...")
27+
sentry_sdk.logger.trace("This is a 'trace' log.")
28+
sentry_sdk.logger.debug("This is a 'debug' log...")
29+
sentry_sdk.logger.info("This is a 'info' log...")
30+
sentry_sdk.logger.warning("This is a 'warn' log...")
31+
sentry_sdk.logger.error("This is a 'error' log...")
32+
sentry_sdk.logger.fatal("This is a 'fatal' log...")
3433
python_logger.warning("sad")
3534

3635
assert len(envelopes) == 0
@@ -41,12 +40,12 @@ def test_logs_basics(sentry_init, capture_envelopes):
4140
sentry_init(_experiments={"enable_sentry_logs": True})
4241
envelopes = capture_envelopes()
4342

44-
sentry_logger.trace("This is a 'trace' log...")
45-
sentry_logger.debug("This is a 'debug' log...")
46-
sentry_logger.info("This is a 'info' log...")
47-
sentry_logger.warn("This is a 'warn' log...")
48-
sentry_logger.error("This is a 'error' log...")
49-
sentry_logger.fatal("This is a 'fatal' log...")
43+
sentry_sdk.logger.trace("This is a 'trace' log...")
44+
sentry_sdk.logger.debug("This is a 'debug' log...")
45+
sentry_sdk.logger.info("This is a 'info' log...")
46+
sentry_sdk.logger.warning("This is a 'warn' log...")
47+
sentry_sdk.logger.error("This is a 'error' log...")
48+
sentry_sdk.logger.fatal("This is a 'fatal' log...")
5049

5150
assert (
5251
len(envelopes) == 6
@@ -96,12 +95,12 @@ def _before_log(record, hint):
9695
)
9796
envelopes = capture_envelopes()
9897

99-
sentry_logger.trace("This is a 'trace' log...")
100-
sentry_logger.debug("This is a 'debug' log...")
101-
sentry_logger.info("This is a 'info' log...")
102-
sentry_logger.warn("This is a 'warn' log...")
103-
sentry_logger.error("This is a 'error' log...")
104-
sentry_logger.fatal("This is a 'fatal' log...")
98+
sentry_sdk.logger.trace("This is a 'trace' log...")
99+
sentry_sdk.logger.debug("This is a 'debug' log...")
100+
sentry_sdk.logger.info("This is a 'info' log...")
101+
sentry_sdk.logger.warning("This is a 'warn' log...")
102+
sentry_sdk.logger.error("This is a 'error' log...")
103+
sentry_sdk.logger.fatal("This is a 'fatal' log...")
105104

106105
assert len(envelopes) == 4
107106

@@ -126,7 +125,7 @@ def test_logs_attributes(sentry_init, capture_envelopes):
126125
"attr_string": "string attribute",
127126
}
128127

129-
sentry_logger.warn(
128+
sentry_sdk.logger.warning(
130129
"The recorded value was '{my_var}'", my_var="some value", attributes=attrs
131130
)
132131

@@ -151,10 +150,10 @@ def test_logs_message_params(sentry_init, capture_envelopes):
151150
sentry_init(_experiments={"enable_sentry_logs": True})
152151
envelopes = capture_envelopes()
153152

154-
sentry_logger.warn("The recorded value was '{int_var}'", int_var=1)
155-
sentry_logger.warn("The recorded value was '{float_var}'", float_var=2.0)
156-
sentry_logger.warn("The recorded value was '{bool_var}'", bool_var=False)
157-
sentry_logger.warn(
153+
sentry_sdk.logger.warning("The recorded value was '{int_var}'", int_var=1)
154+
sentry_sdk.logger.warning("The recorded value was '{float_var}'", float_var=2.0)
155+
sentry_sdk.logger.warning("The recorded value was '{bool_var}'", bool_var=False)
156+
sentry_sdk.logger.warning(
158157
"The recorded value was '{string_var}'", string_var="some string value"
159158
)
160159

@@ -200,7 +199,7 @@ def test_logs_tied_to_transactions(sentry_init, capture_envelopes):
200199
envelopes = capture_envelopes()
201200

202201
with sentry_sdk.start_transaction(name="test-transaction") as trx:
203-
sentry_logger.warn("This is a log tied to a transaction")
202+
sentry_sdk.logger.warning("This is a log tied to a transaction")
204203

205204
log_entry = envelopes[0].items[0].payload.json
206205
assert log_entry["attributes"][-1] == {
@@ -219,7 +218,7 @@ def test_logs_tied_to_spans(sentry_init, capture_envelopes):
219218

220219
with sentry_sdk.start_transaction(name="test-transaction"):
221220
with sentry_sdk.start_span(description="test-span") as span:
222-
sentry_logger.warn("This is a log tied to a span")
221+
sentry_sdk.logger.warning("This is a log tied to a span")
223222

224223
attrs = otel_attributes_to_dict(envelopes[0].items[0].payload.json["attributes"])
225224
assert attrs["sentry.trace.parent_span_id"] == {"stringValue": span.span_id}

0 commit comments

Comments
 (0)