-
-
Notifications
You must be signed in to change notification settings - Fork 472
-
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
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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
}
}
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1 -
❤️ 1
-
Thanks you for kindness
Your answer is really helpful for me.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1