Skip to content

Unable to include tags #1632

Closed
Closed

Description

@samholmes
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.

Activity

  1. kamilogorek commented on Oct 9, 2018

    @kamilogorek
    Contributor

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

  2. kamilogorek commented on Oct 9, 2018

    @kamilogorek
    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 :)

  3. kamilogorek commented on Oct 9, 2018

    @kamilogorek
    Contributor
  4. kamilogorek commented on Oct 9, 2018

    @kamilogorek
    Contributor

    and #1637

  5. kamilogorek commented on Oct 10, 2018

    @kamilogorek
    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" :)

  6. saoudrizwan commented on Jun 18, 2019

    @saoudrizwan

    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?

  7. kamilogorek commented on Jun 18, 2019

    @kamilogorek
    Contributor

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

  8. saoudrizwan commented on Jun 18, 2019

    @saoudrizwan

    That's magical, great work!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions