Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit f7c23c4

Browse files
author
Olivier Gambier
committed
Move bugsnag and newrelic code
... away from the main source to the extras subfolder Docker-DCO-1.1-Signed-off-by: Olivier Gambier <[email protected]> (github: dmp42)
1 parent 024e194 commit f7c23c4

File tree

5 files changed

+34
-28
lines changed

5 files changed

+34
-28
lines changed

docker_registry/app.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import logging
44
import logging.handlers
5-
import os
65
import platform
76
import sys
87

98
from . import toolkit
9+
from .extras import bugsnag
1010
from .lib import config
1111
from .server import __version__
1212
import flask
@@ -59,22 +59,6 @@ def root():
5959
return toolkit.response(cfg.issue)
6060

6161

62-
def bugsnag(application, api_key, flavor, version):
63-
# Configure bugsnag
64-
if api_key:
65-
import bugsnag
66-
import bugsnag.flask
67-
68-
root_path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
69-
bugsnag.configure(api_key=api_key,
70-
project_root=root_path,
71-
release_stage=flavor,
72-
notify_release_stages=[flavor],
73-
app_version=version
74-
)
75-
bugsnag.flask.handle_exceptions(application)
76-
77-
7862
def init():
7963
# Configure the email exceptions
8064
info = cfg.email_exceptions
@@ -95,7 +79,7 @@ def init():
9579
secure=secure_args)
9680
mail_handler.setLevel(logging.ERROR)
9781
app.logger.addHandler(mail_handler)
98-
bugsnag(app, cfg.bugsnag, cfg.flavor, __version__)
82+
bugsnag.boot(app, cfg.bugsnag, cfg.flavor, __version__)
9983
# Configure flask_cors
10084
for i in cfg.cors.keys():
10185
app.config['CORS_%s' % i.upper()] = cfg.cors[i]

docker_registry/extras/__init__.py

Whitespace-only changes.

docker_registry/extras/bugsnag.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
5+
6+
def boot(application, api_key, flavor, version):
7+
# Configure bugsnag
8+
if api_key:
9+
import bugsnag
10+
import bugsnag.flask
11+
12+
root_path = os.path.abspath(
13+
os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
14+
bugsnag.configure(api_key=api_key,
15+
project_root=root_path,
16+
release_stage=flavor,
17+
notify_release_stages=[flavor],
18+
app_version=version
19+
)
20+
bugsnag.flask.handle_exceptions(application)

docker_registry/extras/newrelic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
def boot(ini, stage):
5+
if ini:
6+
try:
7+
import newrelic.agent
8+
newrelic.agent.initialize(ini, stage)
9+
except Exception as e:
10+
raise Exception('Failed to init new relic agent %s' % e)

docker_registry/wsgi.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@
33

44
import logging
55

6+
from .extras import newrelic
67
from .server import env
7-
8-
_new_relic_ini = env.source('NEW_RELIC_INI')
9-
if _new_relic_ini:
10-
try:
11-
import newrelic.agent
12-
newrelic.agent.initialize(
13-
_new_relic_ini,
14-
env.source('NEW_RELIC_STAGE'))
15-
except Exception as e:
16-
raise(Exception('Failed to init new relic agent %s' % e))
8+
newrelic.boot(env.source('NEW_RELIC_INI'), env.source('NEW_RELIC_STAGE'))
179

1810
from .extensions import factory
1911
factory.boot()

0 commit comments

Comments
 (0)