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

CU-8687yhbz5 tweaking sentry config #124

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions Web/Resgrid.Web.ServicesCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
options.AttachStacktrace = true;
options.SendDefaultPii = true;
options.AutoSessionTracking = true;

if (ExternalErrorConfig.SentryPerfSampleRate > 0)
options.EnableTracing = true;

options.TracesSampleRate = ExternalErrorConfig.SentryPerfSampleRate;
options.Environment = ExternalErrorConfig.Environment;
options.Release = Assembly.GetEntryAssembly().GetName().Version.ToString();
Expand Down
56 changes: 28 additions & 28 deletions Web/Resgrid.Web.ServicesCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,26 +482,26 @@ public void ConfigureServices(IServiceCollection services)
// .AddService("ResgridApi"))
// .AddConsoleExporter();
//});
services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService("ResgridApi"))
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddConsoleExporter())
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddConsoleExporter());

// For options which can be bound from IConfiguration.
services.Configure<AspNetCoreTraceInstrumentationOptions>(this.Configuration.GetSection("AspNetCoreInstrumentation"));

// For options which can be configured from code only.
services.Configure<AspNetCoreTraceInstrumentationOptions>(options =>
{
options.Filter = (req) =>
{
return req.Request.Host != null;
};
});
//services.AddOpenTelemetry()
// .ConfigureResource(resource => resource.AddService("ResgridApi"))
// .WithTracing(tracing => tracing
// .AddAspNetCoreInstrumentation()
// .AddConsoleExporter())
// .WithMetrics(metrics => metrics
// .AddAspNetCoreInstrumentation()
// .AddConsoleExporter());

//// For options which can be bound from IConfiguration.
//services.Configure<AspNetCoreTraceInstrumentationOptions>(this.Configuration.GetSection("AspNetCoreInstrumentation"));

//// For options which can be configured from code only.
//services.Configure<AspNetCoreTraceInstrumentationOptions>(options =>
//{
// options.Filter = (req) =>
// {
// return req.Request.Host != null;
// };
//});


services.AddAuthentication("BasicAuthentication")
Expand All @@ -522,16 +522,16 @@ public void ConfigureServices(IServiceCollection services)
//services.AddHostedService<Worker>();
this.Services = services;

if (Config.ExternalErrorConfig.ApplicationInsightsEnabled)
{
services.AddSingleton<ITelemetryInitializer, ApiTelemetryInitializer>();
//if (Config.ExternalErrorConfig.ApplicationInsightsEnabled)
//{
// services.AddSingleton<ITelemetryInitializer, ApiTelemetryInitializer>();

var aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.InstrumentationKey = ExternalErrorConfig.ApplicationInsightsInstrumentationKey;
aiOptions.ConnectionString = ExternalErrorConfig.ApplicationInsightsConnectionString;
// var aiOptions = new ApplicationInsightsServiceOptions();
// aiOptions.InstrumentationKey = ExternalErrorConfig.ApplicationInsightsInstrumentationKey;
// aiOptions.ConnectionString = ExternalErrorConfig.ApplicationInsightsConnectionString;

services.AddApplicationInsightsTelemetry(aiOptions);
}
// services.AddApplicationInsightsTelemetry(aiOptions);
//}
}

public void ConfigureContainer(ContainerBuilder builder)
Expand Down
11 changes: 9 additions & 2 deletions Web/Resgrid.WebCore/Areas/User/Views/Shared/_UserLayout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@
}
<script src="https://js.stripe.com/v3/"></script>

@if (Resgrid.Config.ExternalErrorConfig.ApplicationInsightsEnabled)
@if (Resgrid.Config.ExternalErrorConfig.SentryPerfSampleRate > 0 && !String.IsNullOrWhiteSpace(Resgrid.Config.ExternalErrorConfig.ExternalErrorServiceUrlForWebsite))
{
//@Html.Raw(JavaScriptSnippet.FullScript)
<script src="https://browser.sentry-cdn.com/7.116.0/bundle.min.js"></script>
<script>
Sentry.init({
dsn: '@Resgrid.Config.ExternalErrorConfig.ExternalErrorServiceUrlForWebsite',
integrations: [new Sentry.Integrations.Breadcrumbs({ console: false })],
tracesSampleRate: @Resgrid.Config.ExternalErrorConfig.SentryPerfSampleRate
});
</script>
}
</head>
<body>
Expand Down
8 changes: 6 additions & 2 deletions Web/Resgrid.WebCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();

if (!string.IsNullOrWhiteSpace(Config.ExternalErrorConfig.ExternalErrorServiceUrlForWebsite))
{
webBuilder.UseSentry(options =>
Expand All @@ -40,6 +38,10 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
options.Dsn = Config.ExternalErrorConfig.ExternalErrorServiceUrlForWebsite;
options.AttachStacktrace = true;
options.SendDefaultPii = true;

if (ExternalErrorConfig.SentryPerfSampleRate > 0)
options.EnableTracing = true;

options.TracesSampleRate = ExternalErrorConfig.SentryPerfSampleRate;
options.Environment = ExternalErrorConfig.Environment;
options.AutoSessionTracking = true;
Expand Down Expand Up @@ -69,6 +71,8 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
};
});
}

webBuilder.UseStartup<Startup>();
});
}
}
18 changes: 9 additions & 9 deletions Web/Resgrid.WebCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ public void ConfigureServices(IServiceCollection services)

this.Services = services;

if (Config.ExternalErrorConfig.ApplicationInsightsEnabled)
{
services.AddSingleton<ITelemetryInitializer, WebTelemetryInitializer>();

var aiOptions = new ApplicationInsightsServiceOptions();
aiOptions.InstrumentationKey = ExternalErrorConfig.ApplicationInsightsInstrumentationKey;
aiOptions.ConnectionString = ExternalErrorConfig.ApplicationInsightsConnectionString;
services.AddApplicationInsightsTelemetry(aiOptions);
}
//if (Config.ExternalErrorConfig.ApplicationInsightsEnabled)
//{
// services.AddSingleton<ITelemetryInitializer, WebTelemetryInitializer>();

// var aiOptions = new ApplicationInsightsServiceOptions();
// aiOptions.InstrumentationKey = ExternalErrorConfig.ApplicationInsightsInstrumentationKey;
// aiOptions.ConnectionString = ExternalErrorConfig.ApplicationInsightsConnectionString;
// services.AddApplicationInsightsTelemetry(aiOptions);
//}
}

public void ConfigureContainer(ContainerBuilder builder)
Expand Down
Loading