gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

LogRecords should not format variables into message

Open fdemmer opened this issue 2 years ago • 3 comments

The msg of logging calls should be format strings and not include variables.

msg – The event description message, possibly a format string with placeholders for variable data.

https://docs.python.org/3/library/logging.html#logrecord-objects

One example is at https://github.com/benoitc/gunicorn/blob/cf55d2cec277f220ebd605989ce78ad1bb553c46/gunicorn/workers/ggevent.py#L113

Pre-formatting variables into the msg prevents aggregation of logs in tools/services like sentry.

fdemmer avatar May 20 '22 09:05 fdemmer

I don't understand how this change is related to the issue. How it is preventing aggregation with sentry?

benoitc avatar Aug 06 '22 16:08 benoitc

I don't understand how this change is related to the issue. How it is preventing aggregation with sentry?

Sentry treats each error as a separate issue since it has a different message.

+1 on this issue, I also experience it.

danlamanna avatar Aug 06 '22 16:08 danlamanna

Sentry treats each error as a separate issue since it has a different message.

Exactly that.

fdemmer avatar Aug 06 '22 18:08 fdemmer

Yes. This would make investigating Gunicorn timeouts for everyone that uses Sentry way easier.

antonpirker avatar Mar 07 '23 10:03 antonpirker

A patch for it would be accepted.

benoitc avatar May 07 '23 16:05 benoitc

here is my pr: https://github.com/benoitc/gunicorn/pull/2802

fdemmer avatar May 07 '23 20:05 fdemmer

I missed that sorry. Committed. Thanks!

benoitc avatar May 07 '23 22:05 benoitc