nest-raven icon indicating copy to clipboard operation
nest-raven copied to clipboard

Capture Additional data (req) when console.error occurs

Open bugb opened this issue 4 years ago • 4 comments

Package + Version

  • [ ] @sentry/node
  • [ ] other: nest-raven

Version:

latest

Description

When my code throw error, I can get the ADDITIONAL DATA with req field as you can see it here:

image

But when my code does not throw anything and it use console.error instead, it only show something like this:

image

My Sentry setup: image

Could you please give me an approach get the ADDITIONAL DATA with req field like the first image?

bugb avatar Nov 07 '19 03:11 bugb

Hmm, that looks like it's related to #22. Which means that nest-raven doesn't expose ADDITIONAL DATA to exceptions not captured by nest-raven itself. When you use console.error this isn't handled by nest-raven so no additional data is provided.

mentos1386 avatar Nov 13 '19 10:11 mentos1386

@mentos1386 Do you have a plan to fix this issue, I can use sample a hack like this:

// Inside a controller
try {
  something();
} catch (e) {
  console.error(e.message, req); // here req is the request that is sent
}

But it seem it is not a good idea, what do you think?

bugb avatar Nov 14 '19 01:11 bugb

The plan is for this to be fixed with #22.

Otherwise. It's a good practice to throw/faill when error happens. And not just logging it to stdout/stderr. Then you can handle that exception with exception filter https://docs.nestjs.com/exception-filters.

mentos1386 avatar Nov 14 '19 10:11 mentos1386

@mentos1386 Thank you for your plan. Throw error is a good practice but for me I am maintaining a project that has many messy code with no document, sometimes I just want to capture events when something occur with console.warn and console.error instead of throw error, imagine you have an app solving vehicle routing problem with time windows, it is has many situations and results.

bugb avatar Nov 14 '19 10:11 bugb

@bugb Hi new integrations.CaptureConsole({....}) is you definiton or where you found it? I cant find in in source code. Thanks

bendadaniel avatar Nov 11 '22 13:11 bendadaniel

@bendadaniel that is provided by @sentry/integrations package. You can read more here https://getsentry.github.io/sentry-javascript/classes/_sentry_integrations.CaptureConsole.html.

Closing this as original issue would be addressed by #22.

mentos1386 avatar Feb 23 '24 09:02 mentos1386