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

Appearance settings
Discussion options

Hello team.

In the middle of developing webflux user identification, I found something that I cannot understand.

In the SentryWebFilter, code like

chain.filter(exchange).doFinally( __ -> { 
    requestHub.popScope()
...
})
.doFirst {
...
    requestHub.pushScope()
...
}

and in the SentryWebTracingFilter

chain.filter(exchange).doFinally( __ -> {
    ...
    transaction.finish()
})

Most of time in my computer, transaction.finish() is run after hub.popScope(). so even though I change the scope information before popScope(), it doesn't apply when transaction.finish()

I made a filter to change the scope information, but it doesn't affect. and I think above things are reason.

I wrote code like below

class CustomSentryFilter: WebFilter {
    override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
        val hub = exchange.attributes.getOrDefault(SentryWebFilter.SENTRY_HUB_KEY, null) as IHub
        hub.configureScope { scope ->
           // something change outside of Mono flow
        }

        return Mono.just(1)
            .doOnNext { 
                hub.configureScope { scope ->
                   //something change in the middle
                }
            }
            .then(chain.filter(exchange)
            .doFirst {
                hub.configureScope { scope ->
                   //something change on first
                }
            }
            .doFinally {
               hub.configureScope { scope -> 
                  //something change on finally
               }
            }
    }
}

Sometimes, SentryWebFilter doFinally run after SentryWebTracingFilter's one, in that time it give me result what i want. but in the most of time it doesn't.

Is there something that I misunderstand? How can I fix it?

You must be logged in to vote

I've created #2700 to track the bug.

Replies: 1 comment · 4 replies

Comment options

Hello @sleep-dev, can you confirm the order of filters is correct and your CustomSentryFilter is invoked after SentryWebFilter / SentryWebTracingFilter?

You must be logged in to vote
4 replies
@sleep-dev
Comment options

Yup, I debugged and result shows CustomSentryFilter run after SentryWebFilter and WebTracingFilter.

@sleep-dev
Comment options

I found that SentryWebFilter uses Ordered.HIGHEST_PRECEDENCE and SentryWebTracingFilter uses Ordered.HIGHEST_PRECEDENCE+1
I tested CustomSentryFilter on both 0 and Ordered.HIGHEST_PRECEDENCE+2 and both show same result.

I use
spring-boot 2.7.11
sentry 6.18.1

(added)

If I set the CustomSentryFilter order between SentryWebFilter and SentryWebTracingFilter then the doFinally on CustomSentryFilter affect to result.

Is that right way?

@adinauer
Comment options

If I set the CustomSentryFilter order between SentryWebFilter and SentryWebTracingFilter then the doFinally on CustomSentryFilter affect to result.

Hmm this surprises me.

Hub.popScope being executed before transaction.finish() sounds like a bug to me. Not sure if this was introduced recently or if it's been there for a while. I'll investigate.

As a workaround, can you please try to retrieve the current transaction in your CustomSentryFilter and manipulate the transaction directly?

@adinauer
Comment options

I've created #2700 to track the bug.

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
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.