Skip to content

Commit 9cc4218

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 614c4fa commit 9cc4218

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ celery>=5.0.5
55
coverage>=5.5
66
Django>=3.2.10
77
fastapi>=0.65.1
8-
flask>=1.1.4,<2.0.0
8+
flask>=2.2.0
9+
markupsafe>=2.1.0
910
grpcio>=1.37.1
1011
google-cloud-pubsub<=2.1.0
1112
google-cloud-storage>=1.24.0
1213
lxml>=4.6.3
1314
mock>=4.0.3
14-
moto>=1.3.16,<2.0
15+
# We have to increase the minimum moto version so we can keep markupsafe on the required minimum
16+
# TODO: This appears to break 'test_get_secret_value' in test_boto3_secretsmanager.py
17+
moto>=2.0
1518
mysqlclient>=2.0.3
1619
nose>=1.3.7
1720
PyMySQL[rsa]>=1.0.2

0 commit comments

Comments
 (0)