pino-loki icon indicating copy to clipboard operation
pino-loki copied to clipboard

Configurable message and labels

Open akurdyukov opened this issue 1 year ago • 6 comments

Using pino-loki in projects like NestJS leads to not-so-friendly messages in Grafana. Please see example loki-unfriendly

Currently there's not way to configure pino-loki to make message look like this: loki-friendly

akurdyukov avatar Jul 20 '24 08:07 akurdyukov

Sorry, my method does not work in a real app because pino is executed in a Worker. Need to find another solution.

akurdyukov avatar Jul 20 '24 14:07 akurdyukov

Working solution implemented, please check

akurdyukov avatar Jul 22 '24 07:07 akurdyukov

That fix looks great, would be interested in seeing this merged to master

dmvinson avatar Aug 01 '24 16:08 dmvinson

Hate to piggy back on this. But would really love to see the better formatter as an option

DomiiBunn avatar Aug 27 '24 22:08 DomiiBunn

Would love too. It seems that loki provide the third elements of values to be the log metadata =>

"values": [
    [ "<unix epoch in nanoseconds>", "<log line>", {"trace_id": "0242ac120002", "user_id": "superUser123"}]
]

https://grafana.com/docs/loki/latest/reference/loki-http-api/#ingest-logs

momsse avatar Aug 30 '24 15:08 momsse

Sorry for the late reply!

Have you considered formatting your logs directly in Grafana/LogQL?

{application="my-app"} | json | line_format "{{.msg}}"

This should give you the exact same result. You can even create a custom grafana dashboard with this default LogQL query, so you don't have to type it every time manually.

The solution proposed in #32 seems a bit "fragile" to me, because with Pino, it's possible to log without a msg, which will throw an error when the log is sent if used with PR #32. For example, consider the following log:

logger.info(['hello', 'world']) // Will throw an error since we don't have a `msg`

Reference: https://getpino.io/#/docs/api?id=logging-method-parameters

Happy to discuss about that feature if you guys have better ideas.

Julien-R44 avatar Nov 28 '24 16:11 Julien-R44

Closing since no answers. Feel free to re-open if needed

Julien-R44 avatar Jun 01 '25 19:06 Julien-R44