How to set Sentry Config in asp.net core IMiddleware #1730
-
I want to use same code on multiple domain and want to set different dsn according to domain, so I need to configure sentry dsn for it, is setting SENTRY_DSN and SENTRY_ENVIRONMENT will work for me if I set it in middleware |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Hi @anwarjaved, thanks for your question. We don't allow the DSN to be changed while an application is running. It is expected that a single instance of the Sentry SDK will be used, and the same DSN will be used the entire time. In an ASP.NET Core application, you can set the DSN in your |
Beta Was this translation helpful? Give feedback.
-
@anwarjaved - Turns out I was wrong about this in my previous replies. We do have a way to support multiple DSNs in the same application. There's an example app that does that here: Basically, you need a separate In your case, you'd have to pre-create and fill a I haven't tested this myself, but in theory it should work. Please let us know if you try and how it goes. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@mattjohnsonpint Thank you, Let me try and get back to you if I need further help |
Beta Was this translation helpful? Give feedback.
@anwarjaved - Turns out I was wrong about this in my previous replies. We do have a way to support multiple DSNs in the same application. There's an example app that does that here:
https://github.com/getsentry/sentry-dotnet/blob/main/samples/Sentry.Samples.Console.Customized/Program.cs
Basically, you need a separate
SentryClient
instance per DSN, then you can apply that client to a particular scope usingSentrySdk.BindClient
.In your case, you'd have to pre-create and fill a
Dictionary<string, ISentryClient>
to map the domain name to the client instance, then configure scope during the request (or in a custom middleware) to pick the appropriate client and bind to it on that scope.I have…