Skip to content

Commit

Permalink
chore: tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Apr 8, 2024
1 parent 1e139f3 commit ccf056e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 72 deletions.
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^20.12.2",
"@types/react": "^18.2.73",
"typescript": "^5.4.3"
"@types/node": "^20.12.5",
"@types/react": "^18.2.74",
"typescript": "^5.4.4"
}
}
26 changes: 13 additions & 13 deletions docs/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 46 additions & 49 deletions src/GZCTF/Extensions/TelemetryExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,68 @@ public static class TelemetryExtension
{
public static void AddTelemetry(this IServiceCollection services, TelemetryConfig? config)
{
if (config is { Enable: true })
{
var otel = services.AddOpenTelemetry();

otel.ConfigureResource(resource => resource.AddService("GZCTF"));
if (config is not { Enable: true })
return;

otel.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation();
metrics.AddHttpClientInstrumentation();
metrics.AddRuntimeInstrumentation();
metrics.AddProcessInstrumentation();
var otl = services.AddOpenTelemetry();

if (config.Prometheus.Enable)
{
metrics.AddPrometheusExporter(options =>
{
options.DisableTotalNameSuffixForCounters = true;
});
}
otl.ConfigureResource(resource => resource.AddService("GZCTF"));

if (config.Console.Enable)
{
metrics.AddConsoleExporter();
}
});
otl.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation();
metrics.AddHttpClientInstrumentation();
metrics.AddRuntimeInstrumentation();
metrics.AddProcessInstrumentation();
otel.WithTracing(tracing =>
if (config.Prometheus.Enable)
{
tracing.AddAspNetCoreInstrumentation();
tracing.AddHttpClientInstrumentation();
tracing.AddEntityFrameworkCoreInstrumentation();
tracing.AddRedisInstrumentation();
tracing.AddNpgsql();
if (config.Console.Enable)
metrics.AddPrometheusExporter(options =>
{
tracing.AddConsoleExporter();
}
});
options.DisableTotalNameSuffixForCounters = true;
});
}
if (config.AzureMonitor.Enable)
if (config.Console.Enable)
{
otel.UseAzureMonitor(
options => options.ConnectionString = config.AzureMonitor.ConnectionString);
metrics.AddConsoleExporter();
}
});

if (config.OpenTelemetry.Enable)
otl.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation();
tracing.AddHttpClientInstrumentation();
tracing.AddEntityFrameworkCoreInstrumentation();
tracing.AddRedisInstrumentation();
tracing.AddNpgsql();
if (config.Console.Enable)
{
otel.UseOtlpExporter(config.OpenTelemetry.Protocol, new(config.OpenTelemetry.EndpointUri ?? "http://localhost:4317"));
tracing.AddConsoleExporter();
}
});

if (config.AzureMonitor.Enable)
{
otl.UseAzureMonitor(
options => options.ConnectionString = config.AzureMonitor.ConnectionString);
}

if (config.OpenTelemetry.Enable)
{
otl.UseOtlpExporter(config.OpenTelemetry.Protocol, new(config.OpenTelemetry.EndpointUri ?? "http://localhost:4317"));
}
}

public static void UseTelemetry(this IApplicationBuilder app, TelemetryConfig? config)
{
if (config is { Enable: true, Prometheus.Enable: true })
{
if (config.Prometheus.Port is ushort port)
{
app.UseOpenTelemetryPrometheusScrapingEndpoint(context => context.Connection.LocalPort == port);
}
else
{
app.UseOpenTelemetryPrometheusScrapingEndpoint();
}
}
if (config is not { Enable: true, Prometheus.Enable: true })
return;


if (config.Prometheus.Port is ushort port)
app.UseOpenTelemetryPrometheusScrapingEndpoint(context => context.Connection.LocalPort == port);
else
app.UseOpenTelemetryPrometheusScrapingEndpoint();
}
}
7 changes: 0 additions & 7 deletions src/GZCTF/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Globalization;
using System.Reflection;
using System.Text;
using Azure.Monitor.OpenTelemetry.AspNetCore;
using GZCTF.Extensions;
using GZCTF.Hubs;
using GZCTF.Middlewares;
Expand All @@ -24,12 +23,6 @@
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using Npgsql;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Serilog;
using StackExchange.Redis;

Expand Down

0 comments on commit ccf056e

Please sign in to comment.