Skip to content

Commit

Permalink
Merge pull request #65 from wemogy/main
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
SebastianKuesters authored Jan 12, 2024
2 parents 579b844 + 1cd14f8 commit 7d858fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public void ConfigureServices(IServiceCollection services)

Make sure, the default setup is getting used. Again, you can either use the `UseDefaultSetup` extension method or use the options manually, in case you need to tweak in some of your own adjustments.

```csharp

```csharp
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
Expand Down
42 changes: 14 additions & 28 deletions src/Wemogy.AspNet/Monitoring/MonitoringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,10 @@ public static IServiceCollection AddDefaultMonitoring(
throw new ArgumentException("MonitoringEnvironment is not configured.");
}

return services.AddDefaultMonitoring(options.MonitoringEnvironment);
}

public static IServiceCollection AddDefaultMonitoring(
this IServiceCollection services,
MonitoringEnvironment monitoringEnvironment)
{
// Metrics
services.AddOpenTelemetry().WithMetrics(builder =>
{
foreach (var meterName in monitoringEnvironment.MeterNames)
foreach (var meterName in options.MonitoringEnvironment.MeterNames)
{
builder.AddMeter(meterName);
}
Expand All @@ -40,7 +33,7 @@ public static IServiceCollection AddDefaultMonitoring(
builder.AddHttpClientInstrumentation();
builder.AddAspNetCoreInstrumentation();

if (monitoringEnvironment.UsePrometheus)
if (options.MonitoringEnvironment.UsePrometheus)
{
builder.AddPrometheusExporter();
}
Expand All @@ -52,40 +45,40 @@ public static IServiceCollection AddDefaultMonitoring(
builder.ConfigureResource((resource) =>
{
resource.AddService(
serviceName: monitoringEnvironment.ServiceName,
serviceNamespace: monitoringEnvironment.ServiceNamespace,
serviceInstanceId: monitoringEnvironment.ServiceInstanceId,
serviceVersion: monitoringEnvironment.ServiceVersion);
serviceName: options.MonitoringEnvironment.ServiceName,
serviceNamespace: options.MonitoringEnvironment.ServiceNamespace,
serviceInstanceId: options.MonitoringEnvironment.ServiceInstanceId,
serviceVersion: options.MonitoringEnvironment.ServiceVersion);
});

builder.AddAspNetCoreInstrumentation();
builder.AddEntityFrameworkCoreInstrumentation();

foreach (var activitySourceName in monitoringEnvironment.ActivitySourceNames)
foreach (var activitySourceName in options.MonitoringEnvironment.ActivitySourceNames)
{
builder.AddSource(activitySourceName);
}

if (monitoringEnvironment.UseOtlpExporter)
if (options.MonitoringEnvironment.UseOtlpExporter)
{
builder.AddOtlpExporter(oltpOptions =>
{
oltpOptions.Endpoint = monitoringEnvironment.OtlpExportEndpoint;
oltpOptions.Endpoint = options.MonitoringEnvironment.OtlpExportEndpoint;
});
}
});

// Azure
if (monitoringEnvironment.UseApplicationInsights)
if (options.MonitoringEnvironment.UseApplicationInsights)
{
services.AddOpenTelemetry().UseAzureMonitor(azureMonitorOptions =>
{
azureMonitorOptions.ConnectionString = monitoringEnvironment.ApplicationInsightsConnectionString;
azureMonitorOptions.SamplingRatio = monitoringEnvironment.ApplicationInsightsSamplingRatio;
azureMonitorOptions.ConnectionString = options.MonitoringEnvironment.ApplicationInsightsConnectionString;
azureMonitorOptions.SamplingRatio = options.MonitoringEnvironment.ApplicationInsightsSamplingRatio;
});
}

services.AddSingleton(monitoringEnvironment);
services.AddSingleton(options.MonitoringEnvironment);
return services;
}

Expand All @@ -98,14 +91,7 @@ public static void UseDefaultMonitoring(
throw new ArgumentException("OpenApiEnvironment is not configured.");
}

applicationBuilder.UseDefaultMonitoring(options.MonitoringEnvironment);
}

public static void UseDefaultMonitoring(
this IApplicationBuilder applicationBuilder,
MonitoringEnvironment monitoringEnvironment)
{
if (monitoringEnvironment.UsePrometheus)
if (options.MonitoringEnvironment.UsePrometheus)
{
applicationBuilder.UseOpenTelemetryPrometheusScrapingEndpoint();
}
Expand Down

0 comments on commit 7d858fc

Please sign in to comment.