Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SentryUserProvider for Spring WebFlux #2686

Answered by adinauer
sleep-dev asked this question in Q&A
Discussion options

Hello Team.

Currently, I install the sentry on my project which use the Spring webflux.
I followed the instruction https://docs.sentry.io/platforms/java/guides/spring-boot/performance/instrumentation/opentelemetry/?original_referrer=https%3A%2F%2Fwww.google.com%2F and use "using-sentry-opentelemetry-agent-without-auto-initialization" way.
After setup, sentry successfully collect logs which don't contain the user informations.

I found the guide to record user information(https://docs.sentry.io/platforms/java/guides/spring-boot/record-user/?original_referrer=https%3A%2F%2Fwww.google.com%2F) but it doesn't work on spring webflux.
Is there anything that support webflux? or should I implement the WebFilterChain?

please help.

Thank you

You must be logged in to vote

Hello @sleep-dev, unfortunately SentryUserProvider is only for Spring WebMVC.

You could add a custom EventProcessor or use beforeSend to set user info before an event is sent to Sentry.

Alternatively you should also be able to modify the current Scope and add the User using aWebFilter. You just need to make sure you set the right order so it goes after SentryWebTracingFilter. You may need to retrieve the current Hub from ServerWebExchange (exchange.getAttributes().getOrDefault(SENTRY_HUB_KEY, null);) depending on your version of Spring (Boot) and availability of ThreadLocalAccessor. You may find this comment helpful.

Does that help?

Replies: 1 comment 4 replies

Comment options

Hello @sleep-dev, unfortunately SentryUserProvider is only for Spring WebMVC.

You could add a custom EventProcessor or use beforeSend to set user info before an event is sent to Sentry.

Alternatively you should also be able to modify the current Scope and add the User using aWebFilter. You just need to make sure you set the right order so it goes after SentryWebTracingFilter. You may need to retrieve the current Hub from ServerWebExchange (exchange.getAttributes().getOrDefault(SENTRY_HUB_KEY, null);) depending on your version of Spring (Boot) and availability of ThreadLocalAccessor. You may find this comment helpful.

Does that help?

You must be logged in to vote
4 replies
Comment options

Thank you for help. @adinauer.

I generate the custom EventProcessor and finally I succeed to make User Information.

By the way, in the guide of EventProcessor it override the SentryEvent process(SentryEvent event, Hint hint) function. but in the sentry, it doesn't call that function while it calls SentryTransaction process(@NotNull SentryTransaction transaction, @NotNull Hint hint). So I override the latter function then I succeed.

I use the Sentry 6.17.0 and spring boot 2.7.11

Is this ok to use the later function? or is there some other things use the function with SentryEvent?

Thanks.

Comment options

I wrote the function like below.

@Component
class CustomSentryEventProcessor: EventProcessor {
 override fun process(event : SentryTransaction, hint: Hint) : SentryTransaction? {
 event.user?.apply {
 // some logic to add user information
 }
 return event
 }
}
Comment options

Hello @sleep-dev.

SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) is used for errors whereas SentryTransaction process(@NotNull SentryTransaction transaction, @NotNull Hint hint) is used for transactions. It's OK to use both of them depending on your use case. If you only use the one for transactions, your errors will not contain the user info directly but you may see it by navigating from the error to the transaction via the trace. Depending on settings like tracesSampleRate and other filtering mechanisms you may not see the transactions and thus lack user info. So you may want to add it to both errors and transactions. The method that adds user info can take a SentryBaseEvent so you only have to implement it once and pass in either error or transaction.

Comment options

Thanks you for kindness
Your answer is really helpful for me.

Answer selected by sleep-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /