Skip to content
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(transport): Use correct data category for transaction events #826

Merged
merged 12 commits into from
Sep 21, 2020

Conversation

untitaker
Copy link
Member

@untitaker untitaker commented Sep 18, 2020

While working on #825 I found a bug that caused us to use the "default" item type for transaction events. The bug happened because there were mismatched expectations as to what Item.get_event should return if the content is a transaction event.

Will add an explicit test later.

@untitaker
Copy link
Member Author

untitaker commented Sep 18, 2020

My current suspicion is that this bug did not go noticed because transaction events were counted as data_category=default while errors were data_category=error. And if the server returns a data_category=transaction when rate-limiting events we'd simply not honor the rate limit anyway, which also "works".

@untitaker untitaker self-assigned this Sep 18, 2020
Copy link
Contributor

@rhcarvalho rhcarvalho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least one bug found :)

Thanks for fixing this!

sentry_sdk/envelope.py Outdated Show resolved Hide resolved
sentry_sdk/envelope.py Outdated Show resolved Hide resolved
tests/test_transport.py Outdated Show resolved Hide resolved
untitaker and others added 3 commits September 18, 2020 17:32
Co-authored-by: Rodolfo Carvalho <rodolfo.carvalho@sentry.io>
@@ -726,3 +727,37 @@ def test_init_string_types(dsn, sentry_init):
Hub.current.client.dsn
== "http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2"
)


def test_envelope_types():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we document what behavior this is supposed to test?

@@ -132,8 +132,14 @@ def check_string_keys(map):
check_string_keys(event)
validate_event_schema(event)

def check_envelope(envelope):
# Perhaps one day
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A TODO: ... would be more helpful for a future maintainer (ourselves included).

@@ -208,7 +204,9 @@ def _send_event(
self, event # type: Event
):
# type: (...) -> None
if self._check_disabled(get_event_data_category(event)):
assert event.get("type") != "transaction"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suspicious use of assert here. Feels like over reacting to the bug?

It is also weird to assert what the type is NOT, rather than what it should be, judging from the next line, it should be of "error" type. For example, it would be equally a mistake to send a "session" through this method and have a call _check_disabled("error") for a session.

Comment on lines 70 to 71
"""This gets invoked with an envelope when a transaction or session should
be sent to sentry.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: document what the method does, not who calls it. The latter requires frequent updates when code evolves and gets of sync easily.

To know who calls the method and when we can use "grep" or other tools.

Suggested change
"""This gets invoked with an envelope when a transaction or session should
be sent to sentry.
"""Sends an envelope to Sentry.

We can also document that capture_event is for legacy error events going straight as JSON into the /store endpoint, while capture_envelope can deal with more payload types.

sentry_sdk/envelope.py Outdated Show resolved Hide resolved
untitaker and others added 2 commits September 21, 2020 13:26
Co-authored-by: Rodolfo Carvalho <rodolfo.carvalho@sentry.io>
@untitaker untitaker merged commit 93f6d33 into master Sep 21, 2020
@untitaker untitaker deleted the fix/transport-item-types branch September 21, 2020 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants