Skip to content

log_struct severity isn't captured as expected #190

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

Closed
daniel-sanche opened this issue Feb 18, 2021 · 2 comments
Closed

log_struct severity isn't captured as expected #190

daniel-sanche opened this issue Feb 18, 2021 · 2 comments
Assignees
Labels
api: logging Issues related to the googleapis/python-logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@daniel-sanche
Copy link
Contributor

What is the issue:

On using Python client library for Cloud Logging, log_struct is used to send structured logs to Cloud Logging. In structured logging, the log message and metadata are stored in Python dictionary and it is passed to the 1st argument of the method. However, the severity field is not handled as expected because severity needs to be assigned as named argument, which is not explicit from the library document.

Link to friction log:

https://docs.google.com/document/d/19Glb2LC1jXyARXLlJbdRjY1d7I2GolCntI5hck5PuGU/edit?usp=sharing

How bad is it on a scale of 1-5 (1=Minor Annoyance; 5=Total Work Blocker)

4

What were you trying to do?

This issue was originally reported by the customer (TV Asahi), and I reproduced it.

I tried to send structured logs to Cloud Logging with its Python client library.

##What did you expect to happen?

The 1st argument of log_struct accept the dictionary with whole metadata valid for LogEntry and handle the log severity stored in that dictionary.

That is, expecting this code:

logdata = {
    "service": service,
    "message": message,
    "messageId": context.event_id,
    "timepublished": context.timestamp,
    "severity": "warning"
}

vplogger.log_struct(logdata)

is treated as WARNING level log in Cloud Logging.

What actually happened?

It was treated as DEBUG level log.

@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/python-logging API. label Feb 18, 2021
@daniel-sanche daniel-sanche self-assigned this Feb 18, 2021
@daniel-sanche daniel-sanche added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Feb 18, 2021
@daniel-sanche daniel-sanche added this to the v3 Update 1 milestone Feb 18, 2021
@ecotner
Copy link

ecotner commented Mar 1, 2021

hey, I'm not sure if this is 100% correct, but my understanding is that the first argument to log_struct is supposed to be the JSON payload itself; you're supposed to add metadata as additional kwargs, e.g. you could do something like

vplogger.log_struct(logdata, severity="WARNING")

or

vplogger.log_struct(logdata, severity=logdata["severity"])

this is what I do to specify the log severity, and it works for me

@daniel-sanche
Copy link
Contributor Author

Thanks, that was how I thought it might work. I think it would be more friendly if the library would extract the severity from the JSON if it's not passed as a parameter. But this seems like an API-breaking change, so it will have to wait for the next major release

@daniel-sanche daniel-sanche modified the milestones: v3 Update 1, v3.0.0 Breaking May 24, 2021
@daniel-sanche daniel-sanche added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/python-logging API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants