forked from adfinis/document-merge-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
378 additions
and
261 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,3 +85,9 @@ If either `EMAIL_HOST_USER` or `EMAIL_HOST_PASSWORD` is empty, Django won't atte | |
## Email error handler | ||
* `ENABLE_ADMIN_EMAIL_LOGGING`: enable Django to send email to admins on errors (default: `False`) | ||
* `ADMINS`: list of people who will get code error notifications. Items in the list should follow this example: `Test Example <[email protected]>,Test2 <[email protected]>` | ||
|
||
## Sentry | ||
* `SENTRY_DSN`: identifier (data source name) for where to send events to. If no value is provided, sentry won't be activated (default: ") | ||
* `SENTRY_ENVIRONMENT`: which app environment sent an event to sentry (default: `development`) | ||
* `SENTRY_TRACES_SAMPLE_RATE`: percentage chance a given transaction will be sent to Sentry (default: `1.0`) | ||
* `SENTRY_SEND_DEFAULT_PII`: enable send PII data that associates users to errors (default: `True`) |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
from pathlib import Path | ||
|
||
import pytest | ||
import sentry_sdk | ||
from django.core.cache import cache | ||
from pytest_factoryboy import register | ||
from rest_framework.test import APIClient | ||
|
@@ -11,6 +12,7 @@ | |
from document_merge_service.api.data import django_file | ||
|
||
from .api.authentication import AnonymousUser | ||
from .sentry import sentry_init | ||
|
||
register(factories.TemplateFactory) | ||
|
||
|
@@ -94,3 +96,15 @@ def dms_test_bin(): | |
def loadtest_data(): | ||
base = Path(__file__).parent.absolute() | ||
return Path(base, "api", "data", "loadtest") | ||
|
||
|
||
@pytest.fixture | ||
def sentry_mock(monkeypatch, mocker): | ||
sentry_init("https://[email protected]/0", "test", 0.01, False) | ||
sentry_client = sentry_sdk.Hub.current.client | ||
transport = mocker.MagicMock() | ||
monkeypatch.setattr(sentry_client, "transport", transport) | ||
try: | ||
yield transport | ||
finally: | ||
sentry_sdk.Hub.current.bind_client(None) |
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,21 @@ | ||
import logging | ||
|
||
import sentry_sdk | ||
from sentry_sdk.integrations.django import DjangoIntegration | ||
from sentry_sdk.integrations.logging import LoggingIntegration | ||
|
||
|
||
def sentry_init(dsn, env, traces_sample_rate, send_default_pii): | ||
sentry_sdk.init( | ||
dsn=dsn, | ||
environment=env, | ||
send_default_pii=send_default_pii, | ||
traces_sample_rate=traces_sample_rate, | ||
integrations=[ | ||
DjangoIntegration(), | ||
LoggingIntegration(level=logging.INFO, event_level=logging.ERROR), | ||
# the `level` kwarg defaults to INFO and instructs sentry to include log messages of that level or higher in | ||
# the message sent to sentry when triggered by an event of level specified in event_level kwarg as | ||
# breadcrumbs. | ||
], | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import sentry_sdk | ||
|
||
|
||
def test_sentry(sentry_mock): | ||
assert len(sentry_mock.method_calls) == 0 | ||
sentry_sdk.capture_exception(Exception("test_sentry_exc")) | ||
assert len(sentry_mock.method_calls) == 1 | ||
sentry_mock.record_lost_event.assert_not_called() | ||
assert ( | ||
sentry_mock.method_calls[0].args[0]["exception"]["values"][0]["value"] | ||
== "test_sentry_exc" | ||
) |
Oops, something went wrong.