-
-
Save ric2b/a0f27478d03a9a617e8f3043e2070cb0 to your computer and use it in GitHub Desktop.
Simplest scrapy extension to send all errors and exceptions to Sentry
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
import sentry_sdk | |
import os | |
from scrapy.exceptions import NotConfigured | |
class SentryLogging(object): | |
""" | |
Send exceptions and errors to Sentry. | |
""" | |
@classmethod | |
def from_crawler(cls, crawler): | |
if os.getenv('SENTRY_DSN', None) is None: | |
raise NotConfigured | |
sentry_sdk.init() | |
# return the extension object | |
return cls() |
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
sentry-sdk |
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
# Add the following lines to your settings.py file: | |
# ... | |
# Enable or disable extensions | |
# See https://doc.scrapy.org/en/latest/topics/extensions.html | |
EXTENSIONS = { | |
'myproject.extensions.SentryLogging': -1, # Load SentryLogging extension before others | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment