-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sentry): add Sentry watcher (#120)
* Add dependency Sentry * Add and initialize Sentry * Add Sentry configuration info to .env.example
- Loading branch information
Showing
8 changed files
with
156 additions
and
2 deletions.
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import logging | ||
|
||
import sentry_sdk | ||
from sentry_sdk.integrations.logging import LoggingIntegration | ||
|
||
|
||
class Watcher: | ||
""" | ||
A class to configure and initialize Sentry integration for a Python application. | ||
Attributes: | ||
----------- | ||
dns : str | ||
The Sentry DSN (Data Source Name) pointing to the Sentry project. | ||
level : int | ||
The minimum logging level at which logs should be captured. | ||
event_level : int | ||
The minimum logging level at which logs should be sent as events to Sentry. | ||
trace_sample_rate : float | ||
The rate at which traces should be sampled and sent to Sentry. Range [0.0, 1.0]. | ||
Methods: | ||
-------- | ||
initialize(): | ||
Initializes the Sentry SDK with the provided configuration. | ||
get_config() -> dict[str, str]: | ||
Returns the current Sentry configuration. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
dsn: str, | ||
environment: str, | ||
level: str = 'ERROR', | ||
event_level: str = 'ERROR', | ||
trace_sample_rate: float = 0.1 | ||
) -> None: | ||
self.dsn = dsn | ||
self.level = logging.getLevelName(level) | ||
self.event_level = logging.getLevelName(event_level) | ||
self.trace_sample_rate = trace_sample_rate | ||
self.environment = environment | ||
|
||
def initialize(self) -> None: | ||
sentry_logging = LoggingIntegration( | ||
level=self.level, | ||
event_level=self.event_level | ||
) | ||
|
||
sentry_sdk.init( | ||
dsn=self.dsn, | ||
integrations=[sentry_logging], | ||
traces_sample_rate=self.trace_sample_rate, | ||
environment=self.environment | ||
) | ||
|
||
def get_config(self) -> dict[str, str]: | ||
return { | ||
"dsn": self.dsn, | ||
"level": self.level, | ||
"event_level": self.event_level, | ||
"trace_sample_rate": self.trace_sample_rate | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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