getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.88k stars 1.55k forks source link

captureException of sentry/node not working yet raven works #1960

Closed kaienbcjdoapwkfldue closed 5 years ago

kaienbcjdoapwkfldue commented 5 years ago

Package + Version

Version:

Sentry 9.0.0 on premise
Node v11.4.0

Description

I can capture exception with raven, but not with @sentry/node:

const Raven = require('raven')
Raven.config('http://xxx').install()
Raven.captureException(new Error("This is my fake error message"))

works, I can see the event in the Sentry Gui, but

const Sentry = require('@sentry/node')
Sentry.init({
    dsn: 'http://xxx',
    debug: true,
})
Sentry.captureException(new Error("This is my fake error message"))

let client = Sentry.getCurrentHub().getClient();
if (client) {
  client.close(2000).then(function() {
    process.exit();
  });
}

prints to the console:

Sentry Logger [Log]: Integration installed: Dedupe
Sentry Logger [Log]: Integration installed: InboundFilters
Sentry Logger [Log]: Integration installed: FunctionToString
Sentry Logger [Log]: Integration installed: ExtraErrorData
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 triggers no event at all.

How can I figure out what is going wrong here?

Edit

I tried using sentry-cli with

export SENTRY_CLI=xxx
sentry-cli send-event -m "Hello from Sentry" --log-level=TRACE

and get back HTTP/1.1 403 CONNECTnotallowed

wong2 commented 5 years ago

why is the client closed immediately?

kaienbcjdoapwkfldue commented 5 years ago

@wong2 What do you mean by closed immediately? I'm waiting 2s before closing the client, not sure if this is actually necessary.

HazAT commented 5 years ago

@kaienbcjdoapwkfldue I tested exactly your code and it works on sentry.io

image

Maybe try to add beforeSend and see if it's called:

const Sentry = require("@sentry/node");
Sentry.init({
  dsn: "https://53039209a22b4ec1bcc296a3c9fdecd6@sentry.io/4291",
  debug: true,
  beforeSend(event) {
    console.log("sending");
    return event;
  }
});
Sentry.captureException(new Error("This is my fake error message"));

let client = Sentry.getCurrentHub().getClient();
if (client) {
  client.close(2000).then(function() {
    process.exit();
  });
}

Output:

Sentry Logger [Log]: Integration installed: Dedupe
Sentry Logger [Log]: Integration installed: InboundFilters
Sentry Logger [Log]: Integration installed: FunctionToString
Sentry Logger [Log]: Integration installed: ExtraErrorData
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
here
kaienbcjdoapwkfldue commented 5 years ago

@HazAT I tried beforeSend and sending seems to work. It's just that nothing ever shows up in sentry. I'm using sentry on-premise with docker-compose with default settings. It is very strange that it works seamlessly with raven. Any idea how to debug this? Is there any chance to get a more informative logging output?

kaienbcjdoapwkfldue commented 5 years ago

For reproduction:

I precisely followed the instructions for setting up Sentry On-Premise here without changing any of the settings: https://github.com/getsentry/onpremise

There is a corporate proxy server between Sentry and the client that breaks up SSL certificates.

HazAT commented 5 years ago

Hmm, kinda hard to answer, you would need to inspect the network traffic, if beforeSend sends it off it's certainly not the error in the SDK. Not sure, maybe some proxy setting blocking the new request?!

I am closing this since it's not a bug in the SDK (if not proven otherwise ^^)

jharris4 commented 5 years ago

I just hit on what appears to be the same issue while trying out replacing raven-js with @sentry/browser.

I have an error that's being logged with raven-js but NOT with @sentry/browser.

I put some breakpoints in the code to see what's going on, and the problem seems to be happening here: https://github.com/getsentry/sentry-javascript/blob/797f99c877857f6e86184cfa64b2c09f3e560367/packages/hub/src/hub.ts#L80

if (top && top.client && top.client[method]) {
      (top.client as any)[method](...args, top.scope);
    }

In this case, method is equal to captureException but top.client['captureException'] is undefined.

Here's the call stack if it helps:

my code - (error)=> { Sentry.captureException(error); }
@sentry/minimal/esm/index.js - captureException
@sentry/minimal/esm/index.js - callOnHub
@sentry/hub/esm/hub.js - captureException
@sentry/hub/esm/hub.js - _invokeClient
HazAT commented 5 years ago

@jharris4 You called Sentry.init right?

jharris4 commented 5 years ago

yep, like this:

Sentry.init({
  dsn: SENTRY_KEY,
  release: VERSION
});
splitChunkErrorCallback = (error, info) => {
  Sentry.withScope(scope => {
    if (info) {
      Object.keys(info).forEach(key => {
        scope.setExtra(key, info[key]);
      });
    }
    Sentry.captureException(error);
  });
};

Then I tested with code something like:

import('./myChunk').then().catch(splitChunkErrorCallback);

// ./myChunk.js

throw new Error('deliberate error to test split chunk errors');
jharris4 commented 5 years ago

But, I swear I didn't change a thing and yet I can't reproduce anymore this morning! haha

milescui commented 4 years ago
[2020-06-09T20:17:35.378] [ERROR] Application - Error: test error
    at Object.<anonymous> (/Users/milescui/Downloads/GitHub/quant/test/test-sentry.ts:6:14)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Module.m._compile (/Users/milescui/.nvm/versions/node/v14.3.0/lib/node_modules/ts-node/src/index.ts:858:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/milescui/.nvm/versions/node/v14.3.0/lib/node_modules/ts-node/src/index.ts:861:12)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at main (/Users/milescui/.nvm/versions/node/v14.3.0/lib/node_modules/ts-node/src/bin.ts:227:14)
    at Object.<anonymous> (/Users/milescui/.nvm/versions/node/v14.3.0/lib/node_modules/ts-node/src/bin.ts:513:3)
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
TypeError: self._mergeOptions is not a function
    at /Users/milescui/Downloads/GitHub/quant/node_modules/@sentry/core/src/integrations/inboundfilters.ts:43:30
    at /Users/milescui/Downloads/GitHub/quant/node_modules/@sentry/hub/src/scope.ts:102:24
    at new SyncPromise (/Users/milescui/Downloads/GitHub/quant/node_modules/@sentry/utils/src/syncpromise.ts:30:7)
    at Scope._notifyEventProcessors (/Users/milescui/Downloads/GitHub/quant/node_modules/@sentry/hub/src/scope.ts:96:12)
    at Scope.applyToEvent (/Users/milescui/Downloads/GitHub/quant/node_modules/@sentry/hub/src/scope.ts:392:17)
    at NodeClient.<anonymous> (/Users/milescui/Downloads/GitHub/quant/node_modules/log4js-node-sentry-appender/node_modules/@sentry/core/src/baseclient.ts:283:20)
    at step (/Users/milescui/Downloads/GitHub/quant/node_modules/tslib/tslib.js:141:27)
    at Object.next (/Users/milescui/Downloads/GitHub/quant/node_modules/tslib/tslib.js:122:57)
    at /Users/milescui/Downloads/GitHub/quant/node_modules/tslib/tslib.js:115:75
    at new Promise (<anonymous>)
kamilogorek commented 4 years ago

@milescui that's not too helpful tbh. Are you able to provide some kind of repro case?

oscarmeanwell commented 3 years ago

I am having this exact same issue. One day it was working and the next it isnt. The error is been sent, an event id is returned, the dsn is correct, but the error isnt showing up in the sentry dashboard...

oscarmeanwell commented 3 years ago

What solved this for me was upgrading my account - had gone above the tier of error reporting so it looked like everything was working, and it was because it was. Sentry was just not displaying any errors due to surpassing our limit, but they were been reported successfully.

rnjailamba commented 3 years ago

People who see issue and nothing works then you should know that you could be getting rate limited if you are beyond the free limits.

Screen Shot 2021-04-08 at 7 46 29
sungsong88 commented 2 years ago

For those of you using nvm and has missing node issue, take a look at this part from the documentation: https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#using-node-with-nvm-or-volta image

Running that command to generate the symlink to the node worked for me.