Skip to content

Commit

Permalink
chore: Remove unused OpenTelemetry imports and fix formatting in Stat…
Browse files Browse the repository at this point in the history
…icLogger.cs and Extensions.cs (#1021)
  • Loading branch information
Meloyg committed Aug 29, 2024
1 parent 8eb77ea commit 8d332e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using Serilog;
using Serilog.Core;
using Serilog.OpenTelemetry;
using Serilog.Sinks.OpenTelemetry;

namespace FSH.Framework.Infrastructure.Logging.Serilog;

public static class StaticLogger
{
public static void EnsureInitialized()
Expand Down
41 changes: 19 additions & 22 deletions src/aspire/service-defaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
Expand Down Expand Up @@ -39,7 +38,6 @@ public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBu

public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
{

#region OpenTelemetry

// Configure OpenTelemetry service resource details
Expand All @@ -54,7 +52,8 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati
var attributes = new Dictionary<string, object>
{
["host.name"] = Environment.MachineName,
["service.names"] = "FSH.Starter.WebApi.Host", //builder.Configuration["OpenTelemetrySettings:ServiceName"]!, //It's a WA Fix because the service.name tag is not completed automatically by Resource.Builder()...AddService(serviceName) https://github.com/open-telemetry/opentelemetry-dotnet/issues/2027
["service.names"] =
"FSH.Starter.WebApi.Host", //builder.Configuration["OpenTelemetrySettings:ServiceName"]!, //It's a WA Fix because the service.name tag is not completed automatically by Resource.Builder()...AddService(serviceName) https://github.com/open-telemetry/opentelemetry-dotnet/issues/2027
["os.description"] = System.Runtime.InteropServices.RuntimeInformation.OSDescription,
["deployment.environment"] = builder.Environment.EnvironmentName.ToLowerInvariant()
};
Expand All @@ -78,12 +77,12 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati
.WithMetrics(metrics =>
{
metrics.SetResourceBuilder(resourceBuilder)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddProcessInstrumentation()
.AddMeter(MetricsConstants.Todos)
.AddMeter(MetricsConstants.Catalog);
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddProcessInstrumentation()
.AddMeter(MetricsConstants.Todos)
.AddMeter(MetricsConstants.Catalog);
//.AddConsoleExporter();
})
.WithTracing(tracing =>
Expand All @@ -94,9 +93,9 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati
}
tracing.SetResourceBuilder(resourceBuilder)
.AddAspNetCoreInstrumentation(nci => nci.RecordException = true)
.AddHttpClientInstrumentation()
.AddEntityFrameworkCoreInstrumentation();
.AddAspNetCoreInstrumentation(nci => nci.RecordException = true)
.AddHttpClientInstrumentation()
.AddEntityFrameworkCoreInstrumentation();
//.AddConsoleExporter();
});

Expand All @@ -116,11 +115,11 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli

// The following lines enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
builder.Services.AddOpenTelemetry()
// BUG: Part of the workaround for https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1617
.WithMetrics(metrics => metrics.AddPrometheusExporter(options =>
{
options.DisableTotalNameSuffixForCounters = true;
}));
// BUG: Part of the workaround for https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1617
.WithMetrics(metrics => metrics.AddPrometheusExporter(options =>
{
options.DisableTotalNameSuffixForCounters = true;
}));

return builder;
}
Expand All @@ -143,14 +142,12 @@ public static WebApplication MapDefaultEndpoints(this WebApplication app)
if (context.Request.Path != "/metrics") return false;
return true;
});

// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks("/health").AllowAnonymous();
// Only health checks tagged with the "live" tag must pass for app to be considered alive
app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
}).AllowAnonymous();
app.MapHealthChecks("/alive", new HealthCheckOptions { Predicate = r => r.Tags.Contains("live") })
.AllowAnonymous();

return app;
}
Expand Down

0 comments on commit 8d332e4

Please sign in to comment.