Skip to content

Commit 28f8fa0

Browse files
authored
Merge pull request #11 from instana/better_faster_stronger_flask
Better, faster, stronger Flask initialization
2 parents 805265b + 3f4007c commit 28f8fa0

File tree

8 files changed

+25
-15
lines changed

8 files changed

+25
-15
lines changed

instana/django.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import opentracing as ot
33
from instana import tracer, options
44
import opentracing.ext.tags as ext
5+
import os
56

67

78
DJ_INSTANA_MIDDLEWARE = 'instana.django.InstanaMiddleware'
@@ -38,6 +39,11 @@ def __call__(self, request):
3839

3940
def hook(module):
4041
""" Hook method to install the Instana middleware into Django """
42+
if "INSTANA_DEV" in os.environ:
43+
print("==============================================================")
44+
print("Instana: Running django hook")
45+
print("==============================================================")
46+
4147
if DJ_INSTANA_MIDDLEWARE in module.settings.MIDDLEWARE:
4248
return
4349

instana/flaskana.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
from __future__ import print_function
12
from instana import wsgi
2-
from flask.cli import ScriptInfo
3+
import wrapt
4+
import os
35

46

5-
def wrap_load_app(func):
6-
def wrapper(self, *args):
7-
app = func(self, *args)
8-
app.wsgi_app = wsgi.iWSGIMiddleware(app.wsgi_app)
9-
return app
10-
return wrapper
7+
def wrapper(wrapped, instance, args, kwargs):
8+
rv = wrapped(*args, **kwargs)
9+
instance.wsgi_app = wsgi.iWSGIMiddleware(instance.wsgi_app)
10+
return rv
1111

1212

1313
def hook(module):
1414
""" Hook method to install the Instana middleware into Flask """
15-
ScriptInfo.load_app = wrap_load_app(ScriptInfo.load_app)
15+
if "INSTANA_DEV" in os.environ:
16+
print("==============================================================")
17+
print("Instana: Running flask hook")
18+
print("==============================================================")
19+
wrapt.wrap_function_wrapper('flask', 'Flask.__init__', wrapper)

instana/meter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def to_dict(self):
106106

107107
class Meter(object):
108108
SNAPSHOT_PERIOD = 600
109-
snapshot_countdown = 25
109+
snapshot_countdown = 35
110110
sensor = None
111111
last_usage = None
112112
last_collect = None

instana/runtime.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ def hook(module):
88
""" Hook method to install the Instana middleware into Flask """
99
if os.environ["AUTOWRAPT_BOOTSTRAP"] == "runtime":
1010
if "INSTANA_DEV" in os.environ:
11+
print("==========================================================")
12+
print("Instana: Running runtime hook")
13+
print("==========================================================")
1114
level = logging.DEBUG
1215
else:
1316
level = logging.WARN
17+
1418
opts = options.Options(log_level=level)
1519
ot.global_tracer = tracer.InstanaTracer(opts)

instana/span.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
HTTP_CLIENT = "g.hc"
2-
HTTP_SERVER = "g.http"
3-
41
class InstanaSpan(object):
52
t = 0
63
p = None

instana/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def id_to_header(id):
3232
return ""
3333

3434
byteString = struct.pack('>q', id)
35-
return binascii.hexlify(byteString).decode('UTF-8').lstrip('0')
35+
return str(binascii.hexlify(byteString).decode('UTF-8').lstrip('0'))
3636

3737

3838
def header_to_id(header):

instana/wsgi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import opentracing as ot
32
from instana import tracer, options
43
import opentracing.ext.tags as ext

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'psutil>=5.1.3'],
2020
entry_points={'django': ['django.core.handlers.base = instana.django:hook'],
2121
'django19': ['django.core.handlers.base = instana.django19:hook'],
22-
'flask': ['flask.cli = instana.flaskana:hook'],
22+
'flask': ['flask = instana.flaskana:hook'],
2323
'runtime': ['string = instana.runtime:hook']},
2424
test_suite='nose.collector',
2525
keywords=['performance', 'opentracing', 'metrics', 'monitoring'],

0 commit comments

Comments
 (0)