Sentry-javascript: node integrations not work

Created on 8 Nov 2018  路  9Comments  路  Source: getsentry/sentry-javascript

Package + Version

  • [ ] @sentry/browser
  • [x] @sentry/node
  • [ ] raven-js
  • [ ] raven-node _(raven for node)_
  • [ ] other:

Version:

4.2.4

Description

I use the code in docs in my project:

const Sentry = require('@sentry/node')
if (conf.sentry_dsn) Sentry.init({
  dsn: conf.sentry_dsn,
  debug: true,
})

and the output shows console integration installed

Sentry Logger [Log]: Integration installed: Dedupe               
Sentry Logger [Log]: Integration installed: InboundFilters       
Sentry Logger [Log]: Integration installed: FunctionToString     
Sentry Logger [Log]: Integration installed: Console              
Sentry Logger [Log]: Integration installed: Http                 
Sentry Logger [Log]: Integration installed: OnUncaughtException  
Sentry Logger [Log]: Integration installed: OnUnhandledRejection 
Sentry Logger [Log]: Integration installed: LinkedErrors         

but I use each ways of Http / OnUncaughtException / OnUnhandledRejection / Console won't send error to sentry.

When I am using console.log(new Error('error')) / console.error(new Error('error)) or throw new Error('error') I guess it can send an error.

I tried to use Sentry.captureException(new Error('error')) and it can send error correctly. Is my usage wrong?

Blocked Needs Reproduction

Most helpful comment

So the integrations just capture those message as breadcrumbs but not create an error and I must call Sentry.captureException every time?

Yes, because it's a console log, not an exception, thrown error or rejected promise. Logs are logs, errors are errors. Console calls are rarely used in production, thus they are not captured in any way other than logged as breadcrumbs.

Is there a way to use it need not change my previous code too much?

We will create console integration, which will change console into a reporter soon.

All 9 comments

Is my usage wrong?

No, it looks just fine. Can you provide a repro case which I can use to debug this?

I installed @sentry/node by yarn.

$ yarn add @sentry/[email protected]                                                                                      
yarn add v1.12.3                                                                                               
warning package.json: No license field                                                                             
warning No license field                                                                                           
[1/4] Resolving packages...                                                                                        
[2/4] Fetching packages...                                                                                         
[3/4] Linking dependencies...                                                                                      
[4/4] Building fresh packages...                                                                                   

success Saved lockfile.                                                                                                      
success Saved 10 new dependencies.                                                                                 
info Direct dependencies                                                                                           
鈹斺攢 @sentry/[email protected]                                                                                              
info All dependencies                                                                                              
鈹溾攢 @sentry/[email protected]                                                                                              
鈹溾攢 @sentry/[email protected]                                                                                           
鈹溾攢 @sentry/[email protected]                                                                                              
鈹溾攢 [email protected]                                                                                                   
鈹溾攢 [email protected]                                                                                                    
鈹溾攢 [email protected]                                                                                                     
鈹溾攢 [email protected]                                                                                                 
鈹溾攢 [email protected]                                                                                                     
鈹溾攢 [email protected]                                                                                                       
鈹斺攢 [email protected]                                                                                              
warning No license field                                                                                           
Done in 5.62s.                                                                                                     

And I tried it in a new js file and following is the complete code in it:

const dsn = 'https://[email protected]/1311215'

const Sentry = require('@sentry/node')

Sentry.init({
  dsn,
  debug: true,
})
console.log(new Error('error0'))
console.error(new Error('error1'))
Sentry.captureException(new Error('error2'))

I can get following output:

Sentry Logger [Log]: Integration installed: Dedupe
Sentry Logger [Log]: Integration installed: InboundFilters
Sentry Logger [Log]: Integration installed: FunctionToString
Sentry Logger [Log]: Integration installed: Console
Sentry Logger [Log]: Integration installed: Http
Sentry Logger [Log]: Integration installed: OnUncaughtException
Sentry Logger [Log]: Integration installed: OnUnhandledRejection
Sentry Logger [Log]: Integration installed: LinkedErrors
Error: error0
    at Object.<anonymous> (/home/wangjie/Workspace/tmp/js/sentry.js:10:13)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
Error: error1
    at Object.<anonymous> (/home/wangjie/Workspace/tmp/js/sentry.js:12:15)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

But I can only see the "error2" in Sentry.

Which is correct, because first two lines are logs, not exception throws :) you should see them as your last error breadcrumbs in our UI only.

Yes, I can see them in the breadcrumbs. So the integrations just capture those message as breadcrumbs but not create an error and I must call Sentry.captureException every time? I used console.log to output the unknown errors to stdout to collect them. I think that Console Integration could collect the errors directly to Sentry by mistake (usually I output them means I want to collect them.). I think it is troublesome to use Sentry if I have to change every place I use console.log before to Sentry.captureException. Is there a way to use it need not change my previous code too much?

Hi there, it's pretty confusing for me too. I configured the client as you did, and I'm still trying to understand how to send any message to Sentry...

https://docs.sentry.io/error-reporting/quickstart/
https://docs.sentry.io/error-reporting/capturing/

For uncaught errors, you don't need to do anything else than just init call.

So the integrations just capture those message as breadcrumbs but not create an error and I must call Sentry.captureException every time?

Yes, because it's a console log, not an exception, thrown error or rejected promise. Logs are logs, errors are errors. Console calls are rarely used in production, thus they are not captured in any way other than logged as breadcrumbs.

Is there a way to use it need not change my previous code too much?

We will create console integration, which will change console into a reporter soon.

We will create console integration, which will change console into a reporter soon.

I am looking forward to it. I think it is a general need to report an error by using console.log to output an instance of Error.

Was this page helpful?
0 / 5 - 0 ratings