From 89e1368831e377cc4d857711fa89eb538d6f1464 Mon Sep 17 00:00:00 2001 From: Douglas Costa Rossi Date: Tue, 13 Apr 2021 21:13:59 -0300 Subject: [PATCH] fix flask undefined client --- elasticapm/contrib/flask/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/elasticapm/contrib/flask/__init__.py b/elasticapm/contrib/flask/__init__.py index 361dca01c..17bf4c4dd 100644 --- a/elasticapm/contrib/flask/__init__.py +++ b/elasticapm/contrib/flask/__init__.py @@ -88,17 +88,9 @@ def __init__(self, app=None, client=None, client_cls=Client, logging=False, **de self.app = app self.logging = logging self.client = client or get_client() + self.client_cls = client_cls if app: - if not self.client: - config = app.config.get("ELASTIC_APM", {}) - - if "framework_name" not in defaults: - defaults["framework_name"] = "flask" - defaults["framework_version"] = getattr(flask, "__version__", "<0.7") - - self.client = client_cls(config, **defaults) - self.init_app(app, **defaults) def handle_exception(self, *args, **kwargs): @@ -123,6 +115,14 @@ def handle_exception(self, *args, **kwargs): def init_app(self, app, **defaults): self.app = app + if not self.client: + config = self.app.config.get("ELASTIC_APM", {}) + + if "framework_name" not in defaults: + defaults["framework_name"] = "flask" + defaults["framework_version"] = getattr(flask, "__version__", "<0.7") + + self.client = self.client_cls(config, **defaults) # 0 is a valid log level (NOTSET), so we need to check explicitly for it if self.logging or self.logging is logging.NOTSET: