Make sentry_sdk (and distro) optional dependencies #4182
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Optional
sentry_sdk
This PR moves all code that depends on the
sentry_sdk
module into a newclasses.sentry
, and locally attempts toimport sentry_sdk as sdk
if available. If not,sdk
is set toNone
.The
sentry_sdk
methodsset_tag
,set_user
, andset_context
are mirrored intoclasses.sentry
. They are safe to call from other code, and will silently do nothing ifsentry.sdk
isNone
.sentry.init_tracing()
andsentry.disable_tracing()
offer the same protections.Any other
sentry_sdk
methods can be used as needed, but those calls should take the form:The Sentry init is moved just slightly later in the
launch.py
initialization, because there's really no point in initializing it just to exit after showing the command-line--help
or similar. (Also, importing multiple modules before adjustingsys.path()
has been problematic in the past.)Optional
distro
Additionally, the
distro
module is made optional inclasses.sentry
(as it's not a standard Python module), and is also (optionally) used inclasses.metrics
(in place of the long-since-deprecatedplatform.linux_distribution()
).Secure Google Analytics metrics
Additionally-additionally, the URLs to deliver Google Analytics metrics are made
https://
, sincesentry_sdk
is using HTTPS so it seems that train has sailed.Fixes: #3953
cc: @jonoomph
Fixes: #4194