Appengine Logging with Pyramid, need to get current request

20 views
Skip to first unread message

jdavi...@gmail.com

unread,
Nov 8, 2020, 10:36:10 PM11/8/20
to pylons-discuss
Trying to get appengine logging working under Pyramid. 

Log entries are appearing, but they aren't grouped in the same request. Not only are they not grouped in the same request, but I'm getting a duplicate as well.

chrome_hZKb2p0Zdr.png

For those that aren't familiar with googles Logging system, the top line should have the blue icon indicating the request contains an INFO log, and clicking on it should expand to show all of the logging calls that were made during that request. For example:

chrome_LiowoZYVa5.png

As you can see there, that particular request contains 2 logging entries, so we see them there when that line is expanded.

In order for log entries to be grouped together, the api needs to know what request its a part of. Both django and flask appear to have methods available to determine what the current request is, and look for a particular header within that request. 

Here is the place where I think needs an addition for Pyramid to be supported here.   


I see that pyramid has "pyramid.threadlocal.get_current_request()" but the documentation seems to indicate that that maybe shouldn't be used.

Can anyone point me in the right direction?

jdavi...@gmail.com

unread,
Nov 8, 2020, 10:55:12 PM11/8/20
to pylons-discuss
Using get_current_request, it does seem to end up working, sort of.

I still get a duplicate, I imagined to somehow get it down to just 1:

chrome_P3YiTNWlNu.png

I'm not getting the root log entry to show the log level though, which makes filtering by error or warning certainly a nightmare. Part of that, I think, is that it's emitting a log entry on each call to `logging`, rather than pooling them and emitting at the end of the request. Clicking that parent log entry, there are no children entries, but after about a second, that one^ pops in, as if it's querying for any matching trace IDs. This isn't how appengine Standard appears to work. Child log entries seem to exist on the parent as a whole/no querying needed.

Given that I am able to "group" these, maybe this is less a Pyramid issue and more a google one. Looking further into get_current_request, it seems to do basically the same thing as django and flask so I suppose for the purposes of logging, it's good enough?

Jonathan Vanasco

unread,
Nov 10, 2020, 2:57:17 PM11/10/20
to pylons-discuss
I don't use Google's platform, but from what I can tell:

1. Their platform adds in the header "X_CLOUD_TRACE_CONTEXT"
2. There are middleware tools for aggregating logs based on that
3. I don't know if the software you linked is using the middleware, but the popular libraries seem to be:

https://github.com/christophski/django-gcp-log-groups

I could be wrong.

IMHO, for a variety of reasons `get_current_request` is the wrong approach here.  If you need to create the header - and it's not part of google's platform - then you'd be best off writing middleware or a tween to add header using a UUID.

BUT it looks like your best option would be to fork the flask/django middleware project and adapt it to Pyramid.  



Reply all
Reply to author
Forward
0 new messages