From 219e16f8e500a1a04af032d40644cde6294418fa Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 6 Sep 2020 16:12:17 +0200 Subject: [PATCH] *: use direct sentry Hub for start_span --- docker/gunicorn.conf.py | 12 ++---------- passbook/flows/planner.py | 6 +++--- passbook/lib/expression/evaluator.py | 4 ++-- passbook/policies/engine.py | 4 ++-- passbook/policies/process.py | 4 ++-- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/docker/gunicorn.conf.py b/docker/gunicorn.conf.py index 43c35c14d..2141431b2 100644 --- a/docker/gunicorn.conf.py +++ b/docker/gunicorn.conf.py @@ -36,15 +36,7 @@ logconfig_dict = { "console": {"class": "logging.StreamHandler", "formatter": "json_formatter"}, }, "loggers": { - "uvicorn": { - "handlers": ["console"], - "level": "WARNING", - "propagate": False, - }, - "gunicorn": { - "handlers": ["console"], - "level": "INFO", - "propagate": False, - }, + "uvicorn": {"handlers": ["console"], "level": "WARNING", "propagate": False}, + "gunicorn": {"handlers": ["console"], "level": "INFO", "propagate": False}, }, } diff --git a/passbook/flows/planner.py b/passbook/flows/planner.py index b32f8d666..8cd2e1be9 100644 --- a/passbook/flows/planner.py +++ b/passbook/flows/planner.py @@ -4,7 +4,7 @@ from typing import Any, Dict, List, Optional from django.core.cache import cache from django.http import HttpRequest -from sentry_sdk import start_span +from sentry_sdk.hub import Hub from sentry_sdk.tracing import Span from structlog import get_logger @@ -96,7 +96,7 @@ class FlowPlanner: ) -> FlowPlan: """Check each of the flows' policies, check policies for each stage with PolicyBinding and return ordered list""" - with start_span(op="flow.planner.plan") as span: + with Hub.current.start_span(op="flow.planner.plan") as span: span: Span span.set_data("flow", self.flow) span.set_data("request", request) @@ -146,7 +146,7 @@ class FlowPlanner: ) -> FlowPlan: """Build flow plan by checking each stage in their respective order and checking the applied policies""" - with start_span(op="flow.planner.build_plan") as span: + with Hub.current.start_span(op="flow.planner.build_plan") as span: span: Span span.set_data("flow", self.flow) span.set_data("user", user) diff --git a/passbook/lib/expression/evaluator.py b/passbook/lib/expression/evaluator.py index 29973947a..a106c22cd 100644 --- a/passbook/lib/expression/evaluator.py +++ b/passbook/lib/expression/evaluator.py @@ -5,7 +5,7 @@ from typing import Any, Dict, Iterable, Optional from django.core.exceptions import ValidationError from requests import Session -from sentry_sdk import start_span +from sentry_sdk.hub import Hub from sentry_sdk.tracing import Span from structlog import get_logger @@ -76,7 +76,7 @@ class BaseEvaluator: """Parse and evaluate expression. If the syntax is incorrect, a SyntaxError is raised. If any exception is raised during execution, it is raised. The result is returned without any type-checking.""" - with start_span(op="lib.evaluator.evaluate") as span: + with Hub.current.start_span(op="lib.evaluator.evaluate") as span: span: Span span.set_data("expression", expression_source) param_keys = self._context.keys() diff --git a/passbook/policies/engine.py b/passbook/policies/engine.py index 2da684862..3aa2868ba 100644 --- a/passbook/policies/engine.py +++ b/passbook/policies/engine.py @@ -5,7 +5,7 @@ from typing import List, Optional from django.core.cache import cache from django.http import HttpRequest -from sentry_sdk import start_span +from sentry_sdk.hub import Hub from sentry_sdk.tracing import Span from structlog import get_logger @@ -73,7 +73,7 @@ class PolicyEngine: def build(self) -> "PolicyEngine": """Build wrapper which monitors performance""" - with start_span(op="policy.engine.build") as span: + with Hub.current.start_span(op="policy.engine.build") as span: span: Span span.set_data("pbm", self.__pbm) span.set_data("request", self.request) diff --git a/passbook/policies/process.py b/passbook/policies/process.py index d925c249d..a578a4b2a 100644 --- a/passbook/policies/process.py +++ b/passbook/policies/process.py @@ -4,7 +4,7 @@ from multiprocessing.connection import Connection from typing import Optional from django.core.cache import cache -from sentry_sdk import start_span +from sentry_sdk.hub import Hub from sentry_sdk.tracing import Span from structlog import get_logger @@ -48,7 +48,7 @@ class PolicyProcess(Process): def execute(self) -> PolicyResult: """Run actual policy, returns result""" - with start_span(op="policy.process.execute",) as span: + with Hub.current.start_span(op="policy.process.execute",) as span: span: Span span.set_data("policy", self.binding.policy) span.set_data("request", self.request)