Search code examples
javalogbackdropwizardsentry

Dropwizard: How to set the Sentry user context when using dhatim/dropwizard-sentry [Fixed]


I'm using https://github.com/dhatim/dropwizard-sentry for error logging to Sentry in my Dropwizard Java web service.

How can I set the Sentry user context when using dropwizard-sentry's AppenderFactory integration?

I can successfully send the userId / userEmail to Sentry as tags by adding them to the MDC and adding the "mdcTags:" option to the Sentry appender in my application's YAML configuration ( as per the configuration guidelines ), but this doesn't set the user context.

I've tried using the Sentry static API for Java, but without any luck:

        // Set the current user in the context.
        Sentry.getContext().setUser(
            new UserBuilder().setUsername("user1").build()
        );

EDIT:

The author have fixed this issue in https://github.com/dhatim/dropwizard-sentry/releases/tag/2.0.0-4


Solution

  • I am a maintainer of https://github.com/dhatim/dropwizard-sentry. Currently there is no way to set user information in the Sentry context. Only static tags and tags based on logging MDC are configurable in the Dropwizard sentry plugin. This would be an interesting addition, so feel free to open an issue on the project.