Skip to content

Dedupe triggers on dropped events #371

Closed
@Prillan

Description

@Prillan

The dedupe integration drops events that were never sent before.

  1. An error is triggered.
  2. before_send drops the event.
  3. Another event is triggered based on the same error somewhere else.
  4. dedupe drops the event.
  5. (before_send would have accepted the event)

Ideally, dedupe would run after before_send or there should be a possibility to hook into the event processing earlier. A third option would be to bring back the option to ignore specific loggers from raven.

Example code:

from flask import Flask
import logging
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration


# Drop logging based messages from inside a third-party library
def before_send_hook(event, hint):
    if event['level'] == 'error' and 'logger' in event:
        if event['logger'] == 'internal-logger':
            return None

    return event


app = Flask(__name__)
sentry_sdk.init(
    # RANDOM DSN
    'https://d8e8fca2dc0f896fd7cb4cb0031ba249@sentry.io/1234567',
    integrations=[FlaskIntegration()],
    before_send=before_send_hook,
    debug=True,
)


# This function is hidden inside a third-party library
def complex_internal_function():
    class InternalError(Exception):
        def __init__(self, original):
            super().__init__()
            self.original = original

    try:
        raise ValueError('Oh noes!')
    except Exception as ex:
        logger = logging.getLogger('internal-logger')
        e = InternalError(ex)
        logger.error('ERROR!', exc_info=e)
        raise e


@app.route('/')
def index():
    try:
        complex_internal_function()
    except Exception as ex:
        sentry_sdk.capture_exception(ex)
        return 'error', 500

    return 'ok'

if __name__ == '__main__':
    app.run()

Output from the flask server:

ERROR!
Traceback (most recent call last):
  File "example.py", line 32, in complex_internal_function
    raise ValueError('Oh noes!')
ValueError: Oh noes!
 [sentry] INFO: before send dropped event ({'level': 'error', 'exception': ...})
 [sentry] INFO: event processor (<function DedupeIntegration.setup_once.<locals>.processor at 0x7f8a88b10ea0>) dropped event ({'level': 'error', 'exception': ...})
127.0.0.1 - - [21/May/2019 16:09:01] "GET / HTTP/1.1" 500 -

Metadata

Metadata

Assignees

No one assigned

    Labels

    TriagedHas been looked at recently during old issue triage

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions