getsentry / sentry-docs

Sentry's documentation (and tools to build it)
https://docs.sentry.io
Other
332 stars 1.46k forks source link

Missing DSN causes exception rather than silently doing nothing #9290

Open HughWarrington opened 8 months ago

HughWarrington commented 8 months ago

Core or SDK?

Core Sentry product

Which part? Which one?

.NET SDK 4.1.2

Description

This says

The DSN tells the SDK where to send the events. If this value is not provided, the SDK will try to read it from the SENTRY_DSN environment variable. If that variable also does not exist, the SDK will just not send any events.

I have found this not to be the case.

I copied the code example on that page, and it works fine.

If I set SENTRY_DSN variable in my environment, and remove the explicit options.Dsn = ... from the code, it still works fine, using the DSN from the env var.

If I remove the explicit options.Dsn = ... from the code and do not set any environment variable, I get an unhandled ArgumentNullException and my application crashes at startup. It does not fall back to the 'just do nothing' behaviour that is documented.

I'm not sure if this is a documentation problem, or a bug in the SDK. I see someone has reported a bug here and there is a possible fix here, but it sounds like the fix might already be in the version I was using?

Suggested Solution

It would suit me best if the code behaves exactly as documented. Failing that, the docs should match the code behaviour so I can work out what to do in my situation.

getsantry[bot] commented 8 months ago

Assigning to @getsentry/support for routing ⏲️

HughWarrington commented 8 months ago

I guess this page would need to be updated too since it says the same thing.

HughWarrington commented 8 months ago

On further reading, I think there is a workaround here. That works for me.

I think the docs should say something like "If you are configuring Sentry via code and you want to read the DSN from the environment, you must explicitly set options.Dsn = ""; once you have done this, the DSN will be read from the SENTRY_DSN environment variable. If that variable is unset or empty, Sentry will silently do nothing."