Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,25 @@ anywhere in your system ends up as a breadcrumb, see [the logging
docs](./docs/logging.md) for more information. You can, however, also create
breadcrumbs manually:

sentry_sdk.add_breadcrumb({
sentry_sdk.add_breadcrumb(
# ty="log",
# level="debug",
# category="myapp.models",
message="hi"
})

You can also pass a callback to `add_breadcrumb` like so:

sentry_sdk.add_breadcrumb(lambda: {
# "ty": "log",
# "level": "debug",
# "category": "myapp.models",
"message": "hi"
})

The callback will only be called if a sentry client is configured.


## Concurrency

* Sentry-Python currently does not support gevent-based setups.
Expand Down
10 changes: 7 additions & 3 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,17 @@ def capture_internal_exception(self, error=None):
itself."""
pass

def add_breadcrumb(self, crumb):
def add_breadcrumb(self, *args, **kwargs):
"""Adds a breadcrumb."""
client, scope = self._stack[-1]
if client is None:
return
if callable(crumb):
crumb = crumb()

if not kwargs and len(args) == 1 and callable(args[0]):
crumb = args[0]()
else:
crumb = dict(*args, **kwargs)

if crumb is not None:
scope._breadcrumbs.append(crumb)
while len(scope._breadcrumbs) >= client.options["max_breadcrumbs"]:
Expand Down