Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/platforms/dotnet/guides/aspnet/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ as well as your logs as breadcrumbs. The logging integrations also capture event

You configure the SDK in the `Global.asax.cs`:

If you'd prefer not to hardcode your DSN in your source code, you can store it in your `Web.config` file:

```xml {filename:Web.config}
<configuration>
<appSettings>
<add key="SentryDsn" value="___PUBLIC_DSN___" />
</appSettings>
</configuration>
```


```csharp
using System;
using System.Configuration;
using System.Web;
using Sentry.AspNet;
using Sentry.EntityFramework; // If you also installed Sentry.EntityFramework
Expand All @@ -50,7 +61,7 @@ public class MvcApplication : HttpApplication
// Initialize Sentry to capture AppDomain unhandled exceptions and more.
_sentry = SentrySdk.Init(options =>
{
options.Dsn = "___PUBLIC_DSN___";
options.Dsn = ConfigurationManager.AppSettings["SentryDsn"];
Copy link

Choose a reason for hiding this comment

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

Bug: The documentation's code example for ASP.NET will crash the application on startup if the SentryDsn key is missing from Web.config due to an unhandled ArgumentNullException.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The code example in the documentation for ASP.NET initialization uses options.Dsn = ConfigurationManager.AppSettings["SentryDsn"];. If the SentryDsn key is missing from Web.config, ConfigurationManager.AppSettings returns null. In Sentry SDK 4.0+, passing a null DSN to SentrySdk.Init() throws an ArgumentNullException. Because this initialization code is placed in Application_Start(), the unhandled exception will prevent the application from starting. The documentation fails to warn users that this configuration key is mandatory, making it easy for a developer following the guide to cause a startup crash.

💡 Suggested Fix

Update the documentation to include a prominent warning that the SentryDsn key in Web.config is mandatory. Alternatively, modify the code example to include null-checking before assigning the DSN to options.Dsn to prevent the SentrySdk.Init() call from throwing an exception if the key is not found.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: docs/platforms/dotnet/guides/aspnet/index.mdx#L64

Potential issue: The code example in the documentation for ASP.NET initialization uses
`options.Dsn = ConfigurationManager.AppSettings["SentryDsn"];`. If the `SentryDsn` key
is missing from `Web.config`, `ConfigurationManager.AppSettings` returns `null`. In
Sentry SDK 4.0+, passing a `null` DSN to `SentrySdk.Init()` throws an
`ArgumentNullException`. Because this initialization code is placed in
`Application_Start()`, the unhandled exception will prevent the application from
starting. The documentation fails to warn users that this configuration key is
mandatory, making it easy for a developer following the guide to cause a startup crash.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7752030

// When configuring for the first time, to see what the SDK is doing:
options.Debug = true;
// Adds request URL and headers, IP and name for users, etc.
Expand Down