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

Enable a fastify/pino logger integration to add request pino logs to sentry as breadcrumbs #627

Open
GlenTiki opened this issue Sep 11, 2023 · 6 comments

Comments

@GlenTiki
Copy link

Just an idea I had as I'm working through adding this to a project.

@dnlup
Copy link
Contributor

dnlup commented Sep 14, 2023

Hi @GlenTiki , thank you for the suggestion. It seems interesting but I am not sure I understand correctly . Can you share a poc implementation or an event screenshot that shows what you are working on?

@tomasstrejcek
Copy link
Contributor

we have a solution for this BUT we didn't figure out a way how to have request specific logs in breadcrumbs only, so even though you have logs, its not super useful

i have whipped up a quick gist for inspiration - its a new version I am currently evaluating so its not battle tested yet https://gist.github.com/tomasstrejcek/dfd37ff6efaf88477affcadd8775b81c

@GlenTiki
Copy link
Author

I think @tomasstrejcek is onto something here, I'll need to return focus to this issue soon to try it as I've since moved onto some other stuff.

@dnlup The idea here is when you look at an issue in sentry, it auto-captures console.log messages as breadcrumbs to this section (Seen here)
Screenshot 2023-09-14 at 12 11 36

But, if you're not using console as your logger, and leaning into fastifys built-in pino logger, the log messages you put in your handlers don't end up on sentry issues.

So ideally, I would have a server in fastify with a handler like below:

app.get("/", async (req, res) => {
  req.log.info({foo: "bar"}, "some message") // or app.log.info()
  //....
})

And in sentry, if this handler throws an error, I would see a breadcrumb for this log message (Like I would if I used the default sentry module, used console as my logger, and captured exceptions with that)

ARGUABLY: this is an upstream sentry module issue - they could improve pino support themselves to benefit us/others - getsentry/sentry-javascript#4192

But since this is closed upstream, I've come downstream to the sentry lib I'm using 😄

@GlenTiki GlenTiki changed the title Enable a fastify/pino logger intergration to add request pino logs to sentry as breadcrumbs Enable a fastify/pino logger integration to add request pino logs to sentry as breadcrumbs Sep 18, 2023
@dnlup
Copy link
Contributor

dnlup commented Sep 19, 2023

Thank you @GlenTiki and @tomasstrejcek for the detailed description, I see the use case for this but I am not sure if it should be implemented in this plugin though. We can leave this open and discuss more about it, we could find a solution.

@Lilja
Copy link

Lilja commented Sep 26, 2023

I've made some work on this some time ago: https://github.com/Lilja/pino-sentry-breadcrumbs. Not sure if it will help

@mickdekkers
Copy link

A basic solution to get fastify/pino logs to show up in sentry is to make pino emit logs to the console log methods, which sentry does instrument. I've just shared a code snippet for this in the upstream sentry issue: getsentry/sentry-javascript#4192 (comment)

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