Skip to content

fix(transport): Use correct data category for transaction events#826

Merged
untitaker merged 12 commits intomasterfrom
fix/transport-item-types
Sep 21, 2020
Merged

fix(transport): Use correct data category for transaction events#826
untitaker merged 12 commits intomasterfrom
fix/transport-item-types

Conversation

@untitaker
Copy link
Copy Markdown
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 untitaker requested a review from mitsuhiko September 18, 2020 14:56
@untitaker
Copy link
Copy Markdown
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
Copy Markdown
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!

Comment thread sentry_sdk/envelope.py Outdated
Comment thread sentry_sdk/envelope.py Outdated
Comment thread tests/test_transport.py Outdated
@untitaker untitaker force-pushed the fix/transport-item-types branch from 0c13dd6 to 14bbe82 Compare September 21, 2020 07:41
Comment thread tests/test_client.py
)


def test_envelope_types():
Copy link
Copy Markdown
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?

Comment thread tests/conftest.py Outdated
validate_event_schema(event)

def check_envelope(envelope):
# Perhaps one day
Copy link
Copy Markdown
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).

Comment thread sentry_sdk/transport.py Outdated
):
# type: (...) -> None
if self._check_disabled(get_event_data_category(event)):
assert event.get("type") != "transaction"
Copy link
Copy Markdown
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 thread sentry_sdk/transport.py Outdated
Comment on lines +70 to +71
"""This gets invoked with an envelope when a transaction or session should
be sent to sentry.
Copy link
Copy Markdown
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.

Comment thread sentry_sdk/envelope.py Outdated
@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.

2 participants