New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log statements are not grouped to parent request in App Engine Standard P3 #110
Comments
I'm also seeing this, no matter what I try. Looks like it's the default with google-cloud-logging on App Engine Standard: the built in Python root logger sends to Cloud Logging, with resource type I first noticed this change when I migrated to App Engine Python 3 a while back. I managed to fix it for google-cloud-logging 1.x with the code below, which I found here:
... but this no longer works with google-cloud-logging 2.0. I've tried a bunch of variants, including no manual setup at all (ie relying on the default integration on App Engine), but no luck so far. |
Thanks the the report. We're working on improving the cross-platform tests to make sure everything's consistent across GCP platforms, and this bug should be fixed by that effort. I'll try to bump of the priority of this one though, and see if I can fix it a bit earlier What framework are you using for your web server to handle these requests? |
Thank you @daniel-sanche! Sounds good. I'll also try downgrading to 1.x in the meantime to see if that fixes it. I'm on webapp2 (don't judge 😆), v3.0.0b1 for Python 3 support. My app is open source. Here's its current google-cloud-logging setup code. |
@MeLight Here's the doumentation for how grouping works from the go library. The parent should be created automatically for you on AppEngine. Is the trace id being set properly in your logs? It should be set automatically using flask and django, but it may not be set if you're using a different web framework |
Unfortunately I don't think we can fully support webapp2 going forward. They only officially support Python 2, and that's been dropped by GCP libraries going forward. I don't think we can justify maintaining tests/integrations for a library that doesn't officially support Python 3 yet. What I will do though, is make sure you have a way to manually set the trace id on your logs. I'll work on that today |
@daniel-sanche thanks for the reply. I'm using Flask. I'm not sure it's set correctly. Where do I check/how do I set the trace? |
If it's set properly, you should see a trace field as part of your Log Entry payload. Your payload structure should look something like mine from my image. It would be helpful if you could attach a screenshot of your current logs Currently the trace is set automatically for the library, but I'm working on a feature to let users manually override the value |
@daniel-sanche nope, no |
Thanks again for looking at this! Any progress so far? Let me know if there's anything I can do to help. |
Hmm, and you said you're using flask on App Engine Standard? And you ran The root of your issue is that the trace ids aren't being added. If we can solve that, you should start seeing the grouping work as expected |
I opened two PRs around this (#120, #129), when they are merged, you will be able to add traces manually:
Unfortunately with the holidays coming up, we're going to be on a release freeze soon, so I likely won't be able to push the release until January |
Thanks @daniel-sanche! I tried this just now, using your sample code, but it didn't seem to work. Log browser (legacy) screenshot below, app log entry above, HTTP request below. I see the trace id in the HTTP request, and I emitted the trace id attached in Here's my from google.cloud.logging.handlers import AppEngineHandler, setup_logging
setup_logging(AppEngineHandler(logging_client, name='stdout'),
log_level=logging.DEBUG) |
(I installed your PR with |
This reverts commit 13e29b9. ...temporarily, until we figure out googleapis/python-logging#110.
...temporarily, until we figure out googleapis/python-logging#110.
...temporarily, until we figure out googleapis/python-logging#110.
...temporarily, until we figure out googleapis/python-logging#110.
...temporarily, until we figure out googleapis/python-logging#110.
I've downgraded to 1.15.1 for now. We can figure out explicit trace id in the new year! |
...temporarily, until we figure out googleapis/python-logging#110.
Fwiw, I just noticed that this is also tracked (I guess?) in https://issuetracker.google.com/issues/118770775. |
…e id makes log lines attach to their HTTP request and show grouped in cloud console log browser. google-cloud-logging used to do this automatically for webapp2, based on the X-Cloud-Trace-Context header, but it dropped webapp2 as of google-cloud-logging 2.0. background: googleapis/python-logging#110 (comment) googleapis/python-logging#149 (comment) also note that AppEngineHandler is evidently deprecated, so I may need to port that whole class into webutil eventually. :( googleapis/python-logging#202
Figured out my problem. I was still using I'll also plug @oittaa's #149 (comment) for lifting |
Here's the shim log handler class I added that extracts the trace header from webapp2: class Webapp2TraceHandler(AppEngineHandler):
"""Log handler that adds trace id based on webapp2 request header.
https://github.com/googleapis/python-logging/issues/110#issuecomment-745534629
https://github.com/googleapis/python-logging/issues/149#issuecomment-782693201
Also note that AppEngineHandler is evidently deprecated, so I may need to
port that whole class into webutil eventually. :(
https://github.com/googleapis/python-logging/issues/202
"""
def emit(self, record):
try:
import webapp2
trace = webapp2.get_request().headers.get('X-Cloud-Trace-Context')
if trace:
trace_id = trace.split('/', 1)[0]
record.trace = f'projects/{APP_ID}/traces/{trace_id}'
except (ImportError, AssertionError):
pass
return super().emit(record) |
Environment details
Steps to reproduce
Code example
Result:
As you can see every statement is on it's own line, as opposed to what's expected - the statements should be grouped under one log like in App Engine Standard Python2
How to group the statements to the parent request?
The text was updated successfully, but these errors were encountered: