Skip to content

Commit 8166ed6

Browse files
authored
feat: Allow using kwargs as breadcrumb (#27)
1 parent 1b2e140 commit 8166ed6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,25 @@ anywhere in your system ends up as a breadcrumb, see [the logging
8181
docs](./docs/logging.md) for more information. You can, however, also create
8282
breadcrumbs manually:
8383

84-
sentry_sdk.add_breadcrumb({
84+
sentry_sdk.add_breadcrumb(
85+
# ty="log",
86+
# level="debug",
87+
# category="myapp.models",
88+
message="hi"
89+
})
90+
91+
You can also pass a callback to `add_breadcrumb` like so:
92+
93+
sentry_sdk.add_breadcrumb(lambda: {
8594
# "ty": "log",
8695
# "level": "debug",
8796
# "category": "myapp.models",
8897
"message": "hi"
8998
})
9099

100+
The callback will only be called if a sentry client is configured.
101+
102+
91103
## Concurrency
92104

93105
* Sentry-Python currently does not support gevent-based setups.

sentry_sdk/hub.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,17 @@ def capture_internal_exception(self, error=None):
152152
itself."""
153153
pass
154154

155-
def add_breadcrumb(self, crumb):
155+
def add_breadcrumb(self, *args, **kwargs):
156156
"""Adds a breadcrumb."""
157157
client, scope = self._stack[-1]
158158
if client is None:
159159
return
160-
if callable(crumb):
161-
crumb = crumb()
160+
161+
if not kwargs and len(args) == 1 and callable(args[0]):
162+
crumb = args[0]()
163+
else:
164+
crumb = dict(*args, **kwargs)
165+
162166
if crumb is not None:
163167
scope._breadcrumbs.append(crumb)
164168
while len(scope._breadcrumbs) >= client.options["max_breadcrumbs"]:

0 commit comments

Comments
 (0)