Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calls to SentryTracingBuilder can now be chained correctly #2726

Merged
merged 2 commits into from Oct 16, 2023

Conversation

jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Oct 15, 2023

Resolves #2721

Problem

The dotnet UseRouting and UseEndpoints methods are just extensions on the builder... they set properties etc. on the builder before adding middleware. The only part of what they do that gets passed to the SentryTracingBuilder.InnerBuilder then is the delegate that they return on the last line of their implementation (e.g. this).

Previously we were calling that delegate against the InnerBuilder and returning the result directly (which implicitly returns a reference to the InnerBuilder). Chained calls would then be against the InnerBuilder rather than the SentryTracingBuilder.

This caused issues since UseRouting sets properties on the SentryTracingBuilder and then (in the chained call) UserEndpoints tries to follow up with some matching logic... only it's not using the same builder! It's using the InnerBuilder at this stage 馃槩

Solution

We've separated using the InnerBuilder to call the delegate from the return value in our SentryTracingBuilder so that for chained calls, the same builder will always be used.

Copy link
Contributor

@bitsandfoxes bitsandfoxes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃敟

@bitsandfoxes bitsandfoxes merged commit 34d65a2 into main Oct 16, 2023
15 checks passed
@bitsandfoxes bitsandfoxes deleted the fix/chain-userrouting-2721 branch October 16, 2023 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AspNetCore chaining UseRouting().UseEndpoints crash with InvalidOperationException
2 participants