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

Unable to include tags #1632

Closed
samholmes opened this issue Oct 9, 2018 · 8 comments
Closed

Unable to include tags #1632

samholmes opened this issue Oct 9, 2018 · 8 comments

Comments

@samholmes
Copy link

Sentry.init({
	dsn: process.env.SENTRY_DSN,
	tags: {
		process_name: 'webserver',
	},
})

Above is the code I have in my project. When errors are logged from the express middleware, the process_name tag is not included. This is obviously a bug.

Note: I've also tried:

Sentry.configureScope(scope => {
	scope.setTag('process_name', 'webserver')
})

with no avail.

@kamilogorek
Copy link
Contributor

I can confirm that it's an issue when working with express. I'll take care of it this week.

@kamilogorek
Copy link
Contributor

@samholmes because of pipeline-like nature of Express (its middlewares), a user has to pass the scope through all the pipes and carry it over with the request. Otherwise, there's no way to isolate them from each other.

Here's how to work with custom data in Express.js:

app.use(Sentry.Handlers.requestHandler());

// Set any data for all the requests
app.use((req, res, next) => {
  Sentry.getHubFromCarrier(req).configureScope(scope => {
    scope.setTag('process_name', 'webserver')
    scope.setExtra('whatever', 'you-need');
  });
  next();
});

// set data per endpoint
app.get("/foo", req => {
  Sentry.getHubFromCarrier(req).configureScope(scope => {
    scope.setTag("foo", "my-value");
  });

  throw new Error("foo!");
});

app.use(Sentry.Handlers.errorHandler());

Also, one thing you have to remember is that if you want to use captureMessage/captureException and preserve your data, you also need to call them on the requests hub, Sentry.getHubFromCarrier(req).captureMessage("foo");

We'll make sure to document it better. Also we'll release 4.1.0 this week, and then global

Sentry.configureScope(scope => {
	scope.setTag('process_name', 'webserver')
})

Will work as well :)

@kamilogorek
Copy link
Contributor

@kamilogorek
Copy link
Contributor

and #1637

@kamilogorek
Copy link
Contributor

@samholmes ignore my previous comments. We fixed everything internally and starting 4.1.0 (to be released today or tomorrow), everything will "just work" :)

@saoudrizwan
Copy link

Hey @kamilogorek just to clarify, we can now use middleware and set scope without first setting the hub?
I.e.

app.use((req, res, next) => {
  Sentry.configureScope(scope => {
    // ...
  });
  next();
});

will just work?

@kamilogorek
Copy link
Contributor

@saoudrizwan yes, as long as you attach app.use(Sentry.Handlers.requestHandler()) first, it'll work just fine :)

@saoudrizwan
Copy link

That's magical, great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants