-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix test_breadcrumbs #3788
Merged
Merged
Fix test_breadcrumbs #3788
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from unittest import mock | ||
|
||
import sentry_sdk | ||
from sentry_sdk.consts import OP | ||
|
||
|
||
def test_breadcrumbs(sentry_init, capture_events): | ||
|
@@ -26,7 +25,7 @@ def test_breadcrumbs(sentry_init, capture_events): | |
}, | ||
} | ||
|
||
with sentry_sdk.start_transaction(name="trx-breadcrumbs"): | ||
with sentry_sdk.start_span(name="trx-breadcrumbs"): | ||
sentry_sdk.add_breadcrumb(message="breadcrumb0", **add_breadcrumbs_kwargs) | ||
|
||
with sentry_sdk.start_span(name="span1", op="function"): | ||
|
@@ -37,41 +36,25 @@ def test_breadcrumbs(sentry_init, capture_events): | |
message="breadcrumb2", **add_breadcrumbs_kwargs | ||
) | ||
|
||
# Spans that create breadcrumbs automatically | ||
with sentry_sdk.start_span(name="span3", op=OP.DB_REDIS) as span3: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these were outdated @antonpirker since we don't auto-create breadcrumbs from spans now |
||
span3.set_data("span3_data", "data on the redis span") | ||
span3.set_tag("span3_tag", "tag on the redis span") | ||
|
||
with sentry_sdk.start_span(name="span4", op=OP.HTTP_CLIENT) as span4: | ||
span4.set_data("span4_data", "data on the http.client span") | ||
span4.set_tag("span4_tag", "tag on the http.client span") | ||
|
||
with sentry_sdk.start_span(name="span5", op=OP.SUBPROCESS) as span5: | ||
span5.set_data("span5_data", "data on the subprocess span") | ||
span5.set_tag("span5_tag", "tag on the subprocess span") | ||
|
||
with sentry_sdk.start_span(name="span6", op="function") as span6: | ||
# This data on the span is not added to custom breadcrumbs. | ||
# Data from the span is only added to automatic breadcrumbs shown above | ||
span6.set_data("span6_data", "data on span6") | ||
span6.set_tag("span6_tag", "tag on the span6") | ||
with sentry_sdk.start_span(name="span3", op="function"): | ||
sentry_sdk.add_breadcrumb( | ||
message="breadcrumb6", **add_breadcrumbs_kwargs | ||
message="breadcrumb3", **add_breadcrumbs_kwargs | ||
) | ||
|
||
try: | ||
1 / 0 | ||
except ZeroDivisionError as ex: | ||
sentry_sdk.capture_exception(ex) | ||
|
||
(error,) = events | ||
assert len(events) == 2 | ||
error = events[0] | ||
|
||
breadcrumbs = error["breadcrumbs"]["values"] | ||
|
||
for crumb in breadcrumbs: | ||
print(crumb) | ||
|
||
assert len(breadcrumbs) == 7 | ||
assert len(breadcrumbs) == 4 | ||
|
||
# Check for my custom breadcrumbs | ||
for i in range(0, 3): | ||
|
@@ -88,53 +71,16 @@ def test_breadcrumbs(sentry_init, capture_events): | |
} | ||
assert breadcrumbs[i]["timestamp"] == mock.ANY | ||
|
||
# Check automatic redis breadcrumbs | ||
assert breadcrumbs[3]["message"] == "span3" | ||
assert breadcrumbs[3]["type"] == "redis" | ||
assert breadcrumbs[3]["category"] == "redis" | ||
assert "level" not in breadcrumbs[3] | ||
assert "origin" not in breadcrumbs[3] | ||
# Check for custom breadcrumbs on span3 | ||
assert breadcrumbs[3]["message"] == "breadcrumb3" | ||
assert breadcrumbs[3]["type"] == "navigation" | ||
assert breadcrumbs[3]["category"] == "unit_tests.breadcrumbs" | ||
assert breadcrumbs[3]["level"] == "fatal" | ||
assert breadcrumbs[3]["origin"] == "unit-tests" | ||
assert breadcrumbs[3]["data"] == { | ||
"span3_tag": "tag on the redis span", | ||
} | ||
assert breadcrumbs[3]["timestamp"] == mock.ANY | ||
|
||
# Check automatic http.client breadcrumbs | ||
assert "message" not in breadcrumbs[4] | ||
assert breadcrumbs[4]["type"] == "http" | ||
assert breadcrumbs[4]["category"] == "httplib" | ||
assert "level" not in breadcrumbs[4] | ||
assert "origin" not in breadcrumbs[4] | ||
assert breadcrumbs[4]["data"] == { | ||
"thread.id": mock.ANY, | ||
"thread.name": mock.ANY, | ||
"span4_data": "data on the http.client span", | ||
} | ||
assert breadcrumbs[4]["timestamp"] == mock.ANY | ||
|
||
# Check automatic subprocess breadcrumbs | ||
assert breadcrumbs[5]["message"] == "span5" | ||
assert breadcrumbs[5]["type"] == "subprocess" | ||
assert breadcrumbs[5]["category"] == "subprocess" | ||
assert "level" not in breadcrumbs[5] | ||
assert "origin" not in breadcrumbs[5] | ||
assert breadcrumbs[5]["data"] == { | ||
"thread.id": mock.ANY, | ||
"thread.name": mock.ANY, | ||
"span5_data": "data on the subprocess span", | ||
} | ||
assert breadcrumbs[5]["timestamp"] == mock.ANY | ||
|
||
# Check for custom breadcrumbs on span6 | ||
assert breadcrumbs[6]["message"] == "breadcrumb6" | ||
assert breadcrumbs[6]["type"] == "navigation" | ||
assert breadcrumbs[6]["category"] == "unit_tests.breadcrumbs" | ||
assert breadcrumbs[6]["level"] == "fatal" | ||
assert breadcrumbs[6]["origin"] == "unit-tests" | ||
assert breadcrumbs[6]["data"] == { | ||
"string": "foobar", | ||
"number": 4.2, | ||
"array": [1, 2, 3], | ||
"dict": {"foo": "bar"}, | ||
} | ||
assert breadcrumbs[6]["timestamp"] == mock.ANY | ||
assert breadcrumbs[3]["timestamp"] == mock.ANY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throws
if none