Raven-java user user context

How can I set user context with raven-java clock client?

I tried to add the user_email tag and add user_email to the MDC. They both work as expected, with the tag going to the tags, and the MDC moves on to additional data, but neither of them sets the user’s hourly context.

I also use sentinel with javascript, and using raven-js this works fine:

 Raven.setUserContext({ email: '', id: '' }); 

Is there a java equivalent?

+7
java sentry raven
source share
3 answers

It appears that the user cannot send user information over the protocol. You can see the implementation from raven-java:

 protected Event buildEvent(ILoggingEvent iLoggingEvent) { EventBuilder eventBuilder = new EventBuilder() .withTimestamp(new Date(iLoggingEvent.getTimeStamp())) .withMessage(iLoggingEvent.getFormattedMessage()) .withLogger(iLoggingEvent.getLoggerName()) .withLevel(formatLevel(iLoggingEvent.getLevel())) .withExtra(THREAD_NAME, iLoggingEvent.getThreadName()); ...... } 

User information is sent: withSentryInterface (new UserInterface (...)), however I see that this tool only contains code for: StackTraceInterface and MessageInterface. I think you can add it yourself.

+1
source share

from https://github.com/getsentry/raven-java/tree/master/raven-log4j#mapped-tags :

set the following attributes in the application:

 log4j.appender.SentryAppender.mappedTags=User,OS 

and install MDC at runtime:

 void logWithExtras() { // MDC extras MDC.put("User", "test user"); MDC.put("OS", "Linux"); // This adds a message with extras and MDC keys declared in mappedTags as tags to Sentry logger.info("This is a test"); } 
0
source share

If still interested, run this at startup (assuming that "userid" and "ip" are installed in the MDC):

 Raven.getStoredInstance().addBuilderHelper(eventBuilder -> { UserInterface userInterface = new UserInterface(MDC.get("userid"), null, MDC.get("ip"), null); eventBuilder.withSentryInterface(userInterface); }); 
0
source share

All Articles