Skip to content
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

Configurable message and labels #31

Open
akurdyukov opened this issue Jul 20, 2024 · 6 comments
Open

Configurable message and labels #31

akurdyukov opened this issue Jul 20, 2024 · 6 comments

Comments

@akurdyukov
Copy link

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 added a commit to akurdyukov/pino-loki that referenced this issue Jul 20, 2024
@akurdyukov
Copy link
Author

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

@akurdyukov
Copy link
Author

Working solution implemented, please check

@dmvinson
Copy link

dmvinson commented Aug 1, 2024

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

@DomiiBunn
Copy link

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

@momsse
Copy link

momsse commented Aug 30, 2024

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

@Julien-R44
Copy link
Owner

Julien-R44 commented Nov 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants