-
-
Notifications
You must be signed in to change notification settings - Fork 213
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migration guide: How to disable Sentry when no DSN supplied #3136
Comments
that's kinda awkward. What about also introducing a new setting and env var like |
It is already possible to enable/disable sentry by setting the This suggested addition to the migration guide is really for folks who want to simulate the behaviour of the 3.x SDK which was that if no DSN at all was provided (e.g. if no |
hmm ok, that's just different than the long-standing Unix convention of "environment variables that are unset or blank should result in the same behavior" and so the new behavior kinda violates the "principle of least surprise" IMO |
I'm not sure I follow... I confess to not having heard of the unix convention. The original change all of this stemmed from was driven by another principle of "fail early". Generally we don't want Sentry to be the cause of any errors in in people's solutions so we try/catch and log almost all of the exceptions that might come from Sentry's code. The one exception to this is initializing Sentry itself. We don't want people to call For users who want to configure Sentry via environment variables this creates a bit of a problem... which I think stems from the fact that Sentry is using an unusual order of precedence for configuration provider sources. Microsoft is using (from highest to lowest):
Sentry is using:
So people rolling out applications instrumented with Sentry will presently have to use one set of conventions in their CI/CD for all of the MS Stuff (e.g. set default behaviour in appsettings.json but override on a per machine basis in environment variables) and a completely different set of conventions for Sentry, for the same assembly/software. The precedence mismatch is probably the root cause of the problem but we definitely can't change something that fundamental without making a major version bump and making quite a bit of noise about it... as it would be very disruptive. Currently then, if people want to set some default behaviour for Sentry that can be overriden with Environment variables, the only way to do it is to use an AssemblyForAttribute to configure the default behaviour... this would allow them to use similar devops conventions for Sentry and Microsoft stuff when rolling these out in their environments. |
The funny thing is that you just did a major bump and opened a can of worms by changing behavior. MS priority of things is not invented by MS, it is globally accepted order. From high to low: env, local config, global config, code defaults. This is what everyone expects. If you do anything different, it will trigger WTFs and break workflows. Things were prioritised this way for a reason. |
Yeah it's unfortunate we didn't get any feedback about this during the beta testing and only just realized this now. I think we need to partner more closely during testing with people who are using Sentry in large real world applications. The Sentry .NET SDK has been using a divergent order of precedence wrt configuration source providers for quite a while now (at least for all of the 3.x versions). The change we made in 4.0.0 simply made this more apparent as, previously, the consequence of this was that the SDK would be silently disabled... We'll have to look at addressing this in v5.x now I think. |
This is offtopic, but I believe this is important. We use |
We don't need to wait for the next major to fix what the current one broke. |
Check comment in the other PR. |
Problem
A couple of our customers have a setup where they enable Sentry by configuring the DSN in an environment variable. When this environment variable is not set, however, they want Sentry to be disabled.
This is tricky to do since the configuration files take precedence... then code, then environment variables. So if a disabled DSN is configured in XML/JSON/Code then it can't be conditionally overwritten by an environment variable only on those machines where customers want Sentry enabled.
However they can get Sentry to do what they want by configuring the Disabled DSN in an assembly attribute... which is the very last place that our
SettingsLocator
checks (even after having checked environment variables):sentry-dotnet/src/Sentry/Internal/SettingLocator.cs
Lines 33 to 47 in 0aed969
So you can cadd a file called
AssembyInfo.cs
to your project with the following contents:That way you end up with the same behaviour as you had in 3.x (which is that if no DSN is provided anywhere, you get a disabled DSN by default).
Originally posted by @jamescrosswell in #3134 (comment)
TODO
We should summarize the solution above and add it to the 4.0.0 migration guide.
The text was updated successfully, but these errors were encountered: