Skip to content

Commit

Permalink
fix flask undefined client (elastic#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
DougDK authored and beniwohli committed Sep 14, 2021
1 parent 9bab416 commit dd6c8b3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions elasticapm/contrib/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit dd6c8b3

Please sign in to comment.