[PATCH 4 of 4 sentry] Drop initialization from pyramid "includeme()"

Arthur Lutz arthur.lutz at logilab.fr
Fri Sep 13 15:43:26 CEST 2019


Series looks good to me. Thanks for the contribution.

Could we have a usecase where pyramid is not used but present in the
python libraries and then sentry would not initialize ?

Arthur

On 13/09/2019 15:25, Philippe Pepiot wrote:
> # HG changeset patch
> # User Philippe Pepiot <philippe.pepiot at logilab.fr>
> # Date 1568380708 -7200
> #      Fri Sep 13 15:18:28 2019 +0200
> # Node ID 2d7a6ffe35b3c9bc7f17a8fad34d287454ab24bb
> # Parent  9abbf4ab792f6a41a2f017dbd819c82ca71cd637
> # Available At https://hg.logilab.org/review/cubes/sentry
> #              hg pull https://hg.logilab.org/review/cubes/sentry -r 2d7a6ffe35b3
> Drop initialization from pyramid "includeme()"
>
> Otherwise sentry will be initialized twice because registration_callback from
> entities.py is called as well when starting pyramid.
>
> Always initialize sentry with PyramidIntegration when pyramid is available.
>
> diff --git a/cubicweb_sentry/__init__.py b/cubicweb_sentry/__init__.py
> --- a/cubicweb_sentry/__init__.py
> +++ b/cubicweb_sentry/__init__.py
> @@ -3,10 +3,16 @@ import optparse
>  
>  import sentry_sdk
>  from sentry_sdk.integrations.logging import LoggingIntegration
> -from sentry_sdk.integrations.pyramid import PyramidIntegration
> +try:
> +    import pyramid  # noqa
> +except ImportError:
> +    HAS_PYRAMID = False
> +else:
> +    HAS_PYRAMID = True
> +    from sentry_sdk.integrations.pyramid import PyramidIntegration
>  
>  
> -def init_sdk(cwconfig, *integrations):
> +def init_sdk(cwconfig):
>      """Initialize `sentry_sdk` from cubicweb configuration."""
>      try:
>          dsn = cwconfig['sentry-dsn']
> @@ -16,7 +22,9 @@ def init_sdk(cwconfig, *integrations):
>          return
>      release = cwconfig.cube_version(cwconfig.cubes()[0])
>      log_level = cwconfig['sentry-log-level']
> -    integrations = list(integrations)
> +    integrations = []
> +    if HAS_PYRAMID:
> +        integrations.append(PyramidIntegration())
>      if log_level is not None:
>          integrations.append(LoggingIntegration(
>              level=logging.DEBUG,  # Capture debug and above as breadcrumbs
> @@ -28,8 +36,3 @@ def init_sdk(cwconfig, *integrations):
>          integrations=integrations,
>      )
>      return sentry_sdk
> -
> -
> -def includeme(config):
> -    cwconfig = config.registry['cubicweb.config']
> -    init_sdk(cwconfig, PyramidIntegration())



More information about the cubicweb-devel mailing list