Fix tornado server (request) duration metric calculation#3679
Fix tornado server (request) duration metric calculation#3679xrmx merged 6 commits intoopen-telemetry:mainfrom
Conversation
|
Thank you for this fix. Please could you also add/update the tests?: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/74536f1a92a357c9a25fccba057ce5766d5a8f27/instrumentation/opentelemetry-instrumentation-tornado/tests/test_metrics_instrumentation.py |
@tammy-baylis-swi Can you think of a good way to test this race condition? I think we'd have to be able start two concurrent fetches, where one hits |
I'm not actually familiar with Tornado but generally the checks for values resulting from concurrent fetches with predictable times would be helpful, if it's possible. Hmm. Would it make sense to make_app with any new routes as needed, then also use tornado.httpclient.AsyncHTTPClient to do two concurrent fetches and check resulting metrics in memory? |
Thanks @tammy-baylis-swi I think I found the test approach. Just need to iron out CI test failures that didn't happen locally. |
|
Should be ready for review again. Tests are passing. |
tammy-baylis-swi
left a comment
There was a problem hiding this comment.
Nice, thank you for the commented new tests and updated OP. This lgtm; the Maintainers will also have to have a look.
…try#3679) * Fix `opentelemetry-instrumentation-tornado` server (request) duration metric calculation (open-telemetry#3486) * Update changelog * Linting * Add tornado metrics test_metrics_concurrent_requests test * Fix tornado test ms to sec conversion --------- Co-authored-by: Riccardo Magliocchetti <[email protected]>
Description
Fix the tornado instrumenter to track a request's elapsed time in an async-safe way so concurrent requests calculate their own elapsed time for the
HTTP_SERVER_DURATIONmetric properly. This changes the tornado instrumentation to track state (like request start time used to calculate request duration) on the per-request handler instance and not on the more globalserver_histogramobject that is shared between requests.Fixes #3486
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
test_metrics_concurrent_requeststestWithout the fix, the test run errors with:

Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.