Comments (9)
Curious... I'm not able to reproduce this. Do you think you could provide a small example program that demonstrates this issue (e.g. as a GitHub repo)?
Sorry for the late reply. I will do a minimal reproduction and send it.
from sentry-dotnet.
Are you using Serilog by any chance?
from sentry-dotnet.
Are you using Serilog by any chance?
No, I am using NLog.
This only started when I upgraded to 4.0.0.
If I revert back to a lower version, it starts working fine.
from sentry-dotnet.
Curious... I'm not able to reproduce this. Do you think you could provide a small example program that demonstrates this issue (e.g. as a GitHub repo)?
from sentry-dotnet.
Here's the Minimal API that I tested (binding configuration to appsettings.json and using NLog for logging):
using NLog;
using NLog.Config;
using Sentry;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseSentry();
LogManager.Configuration = new LoggingConfiguration();
LogManager.Configuration
.AddSentry(o =>
{
// Optionally specify a separate format for message
o.Layout = "${message}";
// Optionally specify a separate format for breadcrumbs
o.BreadcrumbLayout = "${logger}: ${message}";
// Debug and higher are stored as breadcrumbs (default is Info)
o.MinimumBreadcrumbLevel = NLog.LogLevel.Debug;
// Error and higher is sent as event (default is Error)
o.MinimumEventLevel = NLog.LogLevel.Info;
// Send the logger name as a tag
o.AddTag("logger", "${logger}");
// All Sentry Options are accessible here.
});
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/weatherforecast", () =>
{
SentrySdk.CaptureMessage("Retrieving the weather forecast");
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
app.Logger.LogInformation("Retrieved weather forecast: returning to client");
return forecast;
})
.WithName("GetWeatherForecast")
.WithOpenApi();
app.Run();
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
from sentry-dotnet.
Might be related to #3134 - but in our case, we want to not configure Sentry when no DSN is specified.
from sentry-dotnet.
Might be related to #3134 - but in our case, we want to not configure Sentry when no DSN is specified.
Possibly related. If you were having issues with the config bindings more generally, that would explain why you ended up with a null DSN (even though you'd supplied it as an environment variable). If there's any way you can provide a small sample project that reproduces this, that would really help. So far I haven't been able to reproduce the issue @elfico reported.
from sentry-dotnet.
@jamescrosswell
Here is a repo that shows a minimal working example: https://github.com/elfico/sentry-extension-example
from sentry-dotnet.
@jamescrosswell Here is a repo that shows a minimal working example: https://github.com/elfico/sentry-extension-example
Hey @elfico , thanks for the repo.
I noticed in your Startup class you have the following to initialize the SDK:
//initialize sentry sdk
SentrySdk.Init(sentry =>
{
SentryOptions options = new SentryOptions();
// Add this to the SDK initialization callback
// To set a uniform sample rate
options.TracesSampleRate = 1.0;
So none of the options you're configuring there are being used for anything (that options
variable passes out of scope and gets garbage collected at the end of the callback).
You wouldn't generally new up any options in the callback - rather the options get passed in as a parameter... so that code should look like this instead:
//initialize sentry sdk
SentrySdk.Init(options =>
{
// Add this to the SDK initialization callback
// To set a uniform sample rate
options.TracesSampleRate = 1.0;
Also, if you're initializing via SentrySdk.Init
(which you'd typically do in a Console app) then you don't get configuration bindings out of the box... meaning none of the config from your appsettings.json
file will be used. You could wire it up to work but it's a bit unusual.
Instead, I'd just move all of that initialization from your Startup
class to Program.CreateHostBuilder
(you're calling UseSentry
there and that's where you do get configuration bindings).
This fixes the problem. The reason you were getting the null DSN error is that you were calling SentrySdk.Init without any DSN (and since this method doesn't read the configuration from your appsettings.json, it was throwing an exception).
from sentry-dotnet.
Related Issues (20)
- EF Core errors grouping and message issue
- Performance Query Logging for SqlClient in Asp.Net 4.8 HOT 6
- Flaky: Profiler_ThrowingOnSessionStartup_DoesntBreakSentryInit HOT 1
- Blocking detection
- Enable AVD caching during Android Device Tests
- Integrationtests for `Session`
- No service for type 'Sentry.IHub' has been registered
- MAUI: Option for adding button text to breadcrumbs HOT 1
- Connecting Queries with Code
- Metrics not showing in the Sentry Dashboard
- ArgumentNullException When No DSN Is Configured (4.X) HOT 19
- Sentry.Samples.AspNetCore.Mvc is missing tunneling config
- Migration guide: How to disable Sentry when no DSN supplied HOT 9
- AddAspNet() gone in 4.x HOT 1
- Allow for optional separation into services.AddSentry and app.UseSentry HOT 3
- Should config values from Environment variables override other settings? HOT 1
- AppDomainProcessExitIntegration doesn't get unregistered when Sentry is disposed of/closed HOT 1
- Align configuration binding precedence with Microsoft priorities HOT 2
- Sentry init fails with empty DSN string HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sentry-dotnet.