Skip to content

Commit 3773f3d

Browse files
authored
feat: allow sentry to receive extra params (#248)
Set the variable EOX_CORE_SENTRY_EXTRA_OPTIONS to any custom param that sentry accepts
1 parent 3def8af commit 3773f3d

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,24 @@ The plugin offers some integrations listed below:
189189
190190
EOX_CORE_SENTRY_INTEGRATION_DSN: <your DSN value>
191191
EOX_CORE_SENTRY_IGNORED_ERRORS: [] # optional
192+
EOX_CORE_SENTRY_EXTRA_OPTIONS: {} # optional
192193
193194
By default, **EOX_CORE_SENTRY_INTEGRATION_DSN** setting is None, which disables the sentry integration.
194195
**EOX_CORE_SENTRY_IGNORED_ERRORS** is optional. It is a list of the exceptions you want to ignore. For instance, it can be defined as:
196+
**EOX_CORE_SENTRY_EXTRA_OPTIONS** is optional. It is a dictionary with extra options to be passed to the sentry client. For instance, it can be defined as:
195197

196198
.. code-block:: yaml
197199
198200
EOX_CORE_SENTRY_IGNORED_ERRORS: [
199201
'xmodule.exceptions.NotFoundError',
200202
'openedx.core.djangoapps.user_authn.exceptions.AuthFailedError',
201203
]
204+
EOX_CORE_SENTRY_EXTRA_OPTIONS:
205+
experiments:
206+
profiles_sample_rate: 0.5
207+
another_client_parameter: 'value'
208+
209+
202210
203211
EOX core migration notes
204212
========================

eox_core/settings/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def plugin_settings(settings):
7676
# regex, the exception is ignored if any of the regex matches the traceback text.
7777
settings.EOX_CORE_SENTRY_IGNORED_ERRORS = []
7878
settings.EOX_CORE_SENTRY_ENVIRONMENT = None
79+
settings.EOX_CORE_SENTRY_EXTRA_OPTIONS = {}
7980

8081
if find_spec('eox_audit_model') and EOX_AUDIT_MODEL_APP not in settings.INSTALLED_APPS:
8182
settings.INSTALLED_APPS.append(EOX_AUDIT_MODEL_APP)

eox_core/settings/production.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,31 @@ def plugin_settings(settings): # pylint: disable=function-redefined
131131
'EOX_CORE_SENTRY_ENVIRONMENT',
132132
settings.EOX_CORE_SENTRY_ENVIRONMENT
133133
)
134+
sentry_extra_options = getattr(settings, 'ENV_TOKENS', {}).get(
135+
'EOX_CORE_SENTRY_EXTRA_OPTIONS',
136+
settings.EOX_CORE_SENTRY_EXTRA_OPTIONS
137+
)
134138

135139
if sentry_sdk is not None and sentry_integration_dsn is not None:
136140
from eox_core.integrations.sentry import ExceptionFilterSentry # pylint: disable=import-outside-toplevel
137-
sentry_sdk.init(
138-
before_send=ExceptionFilterSentry(),
139-
dsn=sentry_integration_dsn,
140-
environment=sentry_environment,
141-
integrations=[
142-
DjangoIntegration(),
143-
],
144-
145-
# If you wish to associate users to errors (assuming you are using
146-
# django.contrib.auth) you may enable sending PII data.
147-
send_default_pii=True
148-
)
141+
try:
142+
sentry_sdk.init(
143+
before_send=ExceptionFilterSentry(),
144+
dsn=sentry_integration_dsn,
145+
environment=sentry_environment,
146+
integrations=[
147+
DjangoIntegration(),
148+
],
149+
send_default_pii=True,
150+
**sentry_extra_options
151+
)
152+
except TypeError:
153+
sentry_sdk.init(
154+
before_send=ExceptionFilterSentry(),
155+
dsn=sentry_integration_dsn,
156+
environment=sentry_environment,
157+
integrations=[
158+
DjangoIntegration(),
159+
],
160+
send_default_pii=True
161+
)

0 commit comments

Comments
 (0)