Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Thrown errors not logged in express #24

Open
Starefossen opened this Issue · 14 comments

7 participants

@Starefossen

Hi,

Currently in the works of setting up a Node.JS application using Express.JS and Sentry for error logging. However, only uncaught errors seams to be logged if I use client.patchGlobal() otherwise thrown errors are only printed to the command line and Sentry never gets them. Yes, I run the server in production mode.

Tested on:
Node.JS: v0.8.19
Express.JS: v3.1.0
raven-node: v0.4.6

@mattrobenolt

Can you send an example of what you're doing? Things aren't that obviously broken. :)

@Starefossen

I agree with you @mattrobenolt; I have however searched all the available resources and tried a lot of examples with no different results than my own. Here is my app it only prints stack trace to the console.

"use strict"

http    = require 'http'
express = require 'express'
app     = express()
raven   = require 'raven'

app.use express.bodyParser()
app.get '/', (req, res) ->
  res.send 'Hello World'
  throw new Error 'Broke!'

app.use raven.middleware.express('https://47098ea662:47098ea662@sentry.domain.com/1337')

app.listen 3000
console.log 'Server is running on port 3000'

Starting the server:

NODE_ENV=production node myapp.js
@mstorus

Did you ever figure it out? I've been having the same problem (with basically the same code). The app only prints the stack trace to console and Sentry doesn't get it.

@mattrobenolt

I honestly don't know enough about how Express or these things work, so if you have any ideas, I'm open to checking them out.

@rybnik

Hmmmm did you next() your errors on your express routes?

--- edited ---

Can you try something like:

app.get('/', function(req, res, next) {
   res.send('Hello World');
   next(new Error("Bump!"));
});
@mstorus

Ah, I figured out my problem. I needed to add app.use(app.router) BEFORE app.user(raven.middleware.express(SENTRY_DSN). This is basically what another pull request is talking about #45

@mattrobenolt

@mstorus Do the instructions in that PR fix the issue? Like I said, I'm far from knowledgeable with Express, so.... :)

@defunctzombie

If you are using connect or express I recommend using the following module instead:
https://github.com/shtylman/node-connect-raven?source=c

I use express all the time and leverage this module constantly.

@jpanganiban

I'm having this issue as well. Currently using express 3.xx and raven 0.6.3

@mattrobenolt

@jpanganiban Any more information other than... "I'm having this issue as well."? Since the original issue was just user error.

@jpanganiban

@mattrobenolt: I'm using the express middleware with raven:

app.use(app.router);
app.use(raven.middleware.express('http://72ab090f99364fb9ae30c1d1a6966d0c:b61caddf8a954a028fdddb2d4202367b@sentry.infoshiftinc.com/6'));

// And somewhere below...
app.get('/test', function(req, res) {
  res.json(x);  // an exception should be thrown
});

No events are being sent to sentry. Also, I'm on NODE_ENV=production.

EDIT: Snap. It's working now. Must be my internet connection. :)) Thanks guise!

@namel

Here is an update for express 4

the line: app.use(raven.middleware.express('XXXX'));

must now appear AFTER routing rules app.get() app.post() because middleware and paths are called in the order they were declared.

source:
https://github.com/strongloop/express/wiki/Migrating-from-3.x-to-4.x

@namel

@mattrobenolt - can you please update the README ?

@mattrobenolt

wtf, that's a super shitty change.

@namel if you want to submit a pull request, I'll take that. Otherwise, I'll likely look at it and update later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.