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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow a DSN string.Empty to be overwritten by the environment #3147

Merged
merged 8 commits into from
Feb 14, 2024

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Feb 13, 2024

TLDR;

This PR aims to let users disable the SDK with options.Dsn = ""; and by convention, let this be overwritten by an environment variable. This "" behavior is 10 years old and set in all SDks. #2494 (comment)

Context

We've introduced some friction by letting the SDK throw if there was no DSN provided during initialization. The idea was to make the onboarding process more explicit and let new users know immediately that there was something wrong with their current configuration. #2494

The change made it very awkward to control the SDK's behavior through the environment since now not setting the DSN via code implicitly gets treated as a configuration error.

The current order of priority:

  • Code
  • Binding through config files
  • Environment
  • AssemblyAttribute
  1. and 3. are now following the convention of letting the environment overwrite config files but that's OK for now. We can track and document this.

Fixes #3136,

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

with these tests passing I believe we have a good logic to deal with this
other than nitpicking on the code itself this LGTM

@jamescrosswell
Copy link
Collaborator

Broadly I'm in favour of this change, as it brings us a little closer to aligning with the Microsoft priorities but just be aware that this is going to be a change in the behaviour of the SDK.

Prevsiously, when using version 3.x or version 4.x of the SDK, if you configured a disabled DSN in appsettings.json, this would not be overwritten by any environment variable configuration (nulls would, but disabled wouldn't - that's the whole point of this change).

After this change, a disabled DSN configuration via appsettings.json will be overwritten by environment variable configuration.

I have no idea how many customers (if any) were relying on the assumption that what they configured in appsettings.json would not be overwritten by environment variables. Just a risk to be aware of.

@slonopotamus
Copy link

slonopotamus commented Feb 13, 2024

You're already different from 3.x. This PR makes code different in another direction that is supposed to fix currently broken usecases. And yes, it will involve adjustments on user side (we need to pass empty string to UseSentry).

@jamescrosswell
Copy link
Collaborator

You're already different from 3.x. This PR makes code different in another direction that is supposed to fix currently broken usecases. And yes, it will involve adjustments on user side (we need to pass empty string to UseSentry).

That's true. The other workaround I'd proposed (relying on assembly attributes) would not be breaking things for customers who were relying on them being able to configure a valid or disabled DSN in appsettings that would not be overwritten by env variables though. This PR would break things for those customers.

As I say, I'm not sure how many (if any) customers have their CI/CD setup that way, but it's a risk to be aware of. We could be inadvertedly breaking things for a bunch of customers here.

@slonopotamus
Copy link

slonopotamus commented Feb 13, 2024

We could be inadvertedly breaking things for a bunch of customers here.

Hah. I have a bias here, because this PR will fix my workflow :D But I believe that cases "we have SENTRY_DSN defined in env, but expect it to be ignored" are nonexistent.

@bruno-garcia
Copy link
Member

Hah. I have a bias here, because this PR will fix my workflow :D But I believe that cases "we have SENTRY_DSN defined in env, but expect it to be ignored" are nonexistent.

Yeah env var should trump all other values and it's how a lot of software works so I feel OK about this change

@jamescrosswell
Copy link
Collaborator

Yeah env var should trump all other values and it's how a lot of software works so I feel OK about this change

Do we just want to do it for the DSN property, or should we make this change instead (it would render this PR irrelevant)?

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
@bitsandfoxes bitsandfoxes merged commit 1aad9ab into main Feb 14, 2024
30 checks passed
@bitsandfoxes bitsandfoxes deleted the fix/dsn branch February 14, 2024 12:16
@bruno-garcia
Copy link
Member

Yeah env var should trump all other values and it's how a lot of software works so I feel OK about this change

Do we just want to do it for the DSN property, or should we make this change instead (it would render this PR irrelevant)?

* [Align configuration binding precedence with Microsoft priorities #3143](https://github.com/getsentry/sentry-dotnet/issues/3143)

makes sense to change the behavior across all env vars

@ericsampson
Copy link

thanks for reconsidering the original direction all, it's an appreciated sign of customer focus <3

Maybe you can partner with some poweruser companies/people who would be a "beta test" partner group? I'd be happy to, just LMK. If you gave me a heads-up when there are design questions or a beta version to check out, then I'd be happy to give it a whirl and provide feedback. As long as it was at like 3 or 4 weeks before the planned SDK GA, to give time to schedule the change/deploy n our side.

Cheers

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.

Migration guide: How to disable Sentry when no DSN supplied
6 participants