@@ -239,7 +239,6 @@ def response_hook(span: Span, status: str, response_headers: List):
239
239
---
240
240
"""
241
241
from logging import getLogger
242
- from threading import get_ident
243
242
from time import time_ns
244
243
from timeit import default_timer
245
244
from typing import Collection
@@ -265,7 +264,7 @@ def response_hook(span: Span, status: str, response_headers: List):
265
264
_ENVIRON_STARTTIME_KEY = "opentelemetry-flask.starttime_key"
266
265
_ENVIRON_SPAN_KEY = "opentelemetry-flask.span_key"
267
266
_ENVIRON_ACTIVATION_KEY = "opentelemetry-flask.activation_key"
268
- _ENVIRON_THREAD_ID_KEY = "opentelemetry-flask.thread_id_key "
267
+ _ENVIRON_REQUEST_ID_KEY = "opentelemetry-flask.request_id_key "
269
268
_ENVIRON_TOKEN = "opentelemetry-flask.token"
270
269
271
270
_excluded_urls_from_env = get_excluded_urls ("FLASK" )
@@ -399,7 +398,7 @@ def _before_request():
399
398
activation = trace .use_span (span , end_on_exit = True )
400
399
activation .__enter__ () # pylint: disable=E1101
401
400
flask_request_environ [_ENVIRON_ACTIVATION_KEY ] = activation
402
- flask_request_environ [_ENVIRON_THREAD_ID_KEY ] = get_ident ( )
401
+ flask_request_environ [_ENVIRON_REQUEST_ID_KEY ] = id ( flask . request )
403
402
flask_request_environ [_ENVIRON_SPAN_KEY ] = span
404
403
flask_request_environ [_ENVIRON_TOKEN ] = token
405
404
@@ -439,8 +438,8 @@ def _teardown_request(exc):
439
438
return
440
439
441
440
activation = flask .request .environ .get (_ENVIRON_ACTIVATION_KEY )
442
- thread_id = flask .request .environ .get (_ENVIRON_THREAD_ID_KEY )
443
- if not activation or thread_id != get_ident ( ):
441
+ request_id = flask .request .environ .get (_ENVIRON_REQUEST_ID_KEY )
442
+ if not activation or request_id != id ( flask . request ):
444
443
# This request didn't start a span, maybe because it was created in
445
444
# a way that doesn't run `before_request`, like when it is created
446
445
# with `app.test_request_context`.
0 commit comments