Skip to content

Commit 72136d6

Browse files
format
1 parent 7fdf90c commit 72136d6

File tree

2 files changed

+10
-5
lines changed
  • instrumentation/opentelemetry-instrumentation-flask

2 files changed

+10
-5
lines changed

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,16 @@ def response_hook(span: Span, status: str, response_headers: List):
272272
_excluded_urls_from_env = get_excluded_urls("FLASK")
273273

274274
if package_version.parse(flask.__version__) >= package_version.parse("2.2.0"):
275+
275276
def _request_ctx_ref() -> weakref.ReferenceType:
276277
return weakref.ref(flask.globals.request_ctx._get_current_object())
278+
277279
else:
280+
278281
def _request_ctx_ref() -> weakref.ReferenceType:
279282
return weakref.ref(flask._request_ctx_stack.top)
280283

284+
281285
def get_default_span_name():
282286
try:
283287
span_name = flask.request.url_rule.rule
@@ -447,7 +451,9 @@ def _teardown_request(exc):
447451

448452
activation = flask.request.environ.get(_ENVIRON_ACTIVATION_KEY)
449453

450-
original_reqctx_ref = flask.request.environ.get(_ENVIRON_REQCTX_REF_KEY)
454+
original_reqctx_ref = flask.request.environ.get(
455+
_ENVIRON_REQCTX_REF_KEY
456+
)
451457
current_reqctx_ref = _request_ctx_ref()
452458
if not activation or original_reqctx_ref != current_reqctx_ref:
453459
# This request didn't start a span, maybe because it was created in

instrumentation/opentelemetry-instrumentation-flask/tests/base_test.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,17 @@ def _sqlcommenter_endpoint():
4040

4141
@staticmethod
4242
def _copy_context_endpoint():
43-
4443
@flask.copy_current_request_context
4544
def _extract_header():
46-
return flask.request.headers['x-req']
45+
return flask.request.headers["x-req"]
4746

4847
# Despite `_extract_header` copying the request context,
4948
# calling it shouldn't detach the parent Flask span's contextvar
5049
request_header = _extract_header()
5150

5251
return {
53-
'span_name': trace.get_current_span().name,
54-
'request_header': request_header
52+
"span_name": trace.get_current_span().name,
53+
"request_header": request_header,
5554
}
5655

5756
@staticmethod

0 commit comments

Comments
 (0)