Skip to content

Commit 649b648

Browse files
committed
Add support for Flask 2.2
* Keeps backwards compatibility with 2.1, 2.0, 1.x Signed-off-by: Ferenc Géczi <[email protected]>
1 parent 25e01e0 commit 649b648

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

instana/instrumentation/flask/common.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414

1515
@wrapt.patch_function_wrapper('flask', 'templating._render')
1616
def render_with_instana(wrapped, instance, argv, kwargs):
17-
ctx = argv[1]
18-
1917
# If we're not tracing, just return
20-
if not hasattr(ctx['g'], 'scope'):
18+
if not (hasattr(flask, 'g') and hasattr(flask.g, 'scope')):
2119
return wrapped(*argv, **kwargs)
2220

23-
with tracer.start_active_span("render", child_of=ctx['g'].scope.span) as rscope:
21+
parent_span = flask.g.scope.span
22+
23+
with tracer.start_active_span("render", child_of=parent_span) as rscope:
2424
try:
25-
template = argv[0]
25+
flask_version = tuple(map(int, flask.__version__.split('.')))
26+
template = argv[1] if flask_version >= (2, 2, 0) else argv[0]
2627

2728
rscope.span.set_tag("type", "template")
2829
if template.name is None:

tests/requirements-310.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ celery>=5.0.5
1414
coverage>=5.5
1515
Django>=3.2.10
1616
fastapi>=0.65.1
17-
flask>=2.0.0
18-
markupsafe>=2.1.0
17+
flask>=1.1.4,<2.0.0
1918
grpcio>=1.37.1
2019
google-cloud-pubsub<=2.1.0
2120
google-cloud-storage>=1.24.0
2221
lxml>=4.6.3
2322
mock>=4.0.3
24-
25-
# We have to increase the minimum moto version so we can keep markupsafe on the required minimum
26-
moto>=2.0
23+
moto>=1.3.16,<2.0
2724
mysqlclient>=2.0.3
2825
nose>=1.3.7
2926
PyMySQL[rsa]>=1.0.2
@@ -45,7 +42,7 @@ pytest-celery
4542
redis>=3.5.3
4643
requests-mock
4744
responses<=0.17.0
48-
sanic>=19.0.0,<21.9.0
45+
sanic==21.6.2
4946
sqlalchemy>=1.4.15
5047
spyne>=2.13.16
5148
suds-jurko>=0.6

0 commit comments

Comments
 (0)