Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing web request globally in Tornado

Tags:

python

tornado

I need to be able to access the currently executing web request in Tornado deep within my application without passing it down through all of my methods. When the request is first received I want to assign a trace id to it and then every time a message gets logged I want to include it in the logging information.

Is there some global information somewhere that I can use in Tornado to identify the current request that's being processed?

Thanks!

like image 520
Micah Avatar asked May 15 '13 18:05

Micah


1 Answers

Tornado's StackContext is the way to do this.

Here's an example: https://gist.github.com/simon-weber/7755289.

like image 131
Simon Weber Avatar answered Oct 16 '22 19:10

Simon Weber