| | | 1 | | using Npgsql; |
| | | 2 | | using OpenTelemetry.Trace; |
| | | 3 | | using OpenTelemetry.Metrics; |
| | | 4 | | using OpenTelemetry.Resources; |
| | | 5 | | |
| | | 6 | | namespace Syki.Back.Configs; |
| | | 7 | | |
| | | 8 | | public static class OpenTelemetryConfigs |
| | | 9 | | { |
| | | 10 | | public const string CommandsProcessing = nameof(CommandsProcessing); |
| | | 11 | | public const string WebhookEventsProcessing = nameof(WebhookEventsProcessing); |
| | | 12 | | |
| | | 13 | | public static void AddOpenTelemetryConfigs(this WebApplicationBuilder builder) |
| | | 14 | | { |
| | 2 | 15 | | var settings = builder.Configuration.OpenTelemetry; |
| | | 16 | | |
| | 4 | 17 | | if (!settings.Enabled) return; |
| | | 18 | | |
| | 0 | 19 | | builder.Services |
| | 0 | 20 | | .AddOpenTelemetry() |
| | 0 | 21 | | .ConfigureResource(resource => resource.AddService("Back")) |
| | 0 | 22 | | .WithMetrics(metrics => |
| | 0 | 23 | | { |
| | 0 | 24 | | metrics |
| | 0 | 25 | | .AddNpgsqlInstrumentation() |
| | 0 | 26 | | .AddRuntimeInstrumentation() |
| | 0 | 27 | | .AddAspNetCoreInstrumentation() |
| | 0 | 28 | | .AddHttpClientInstrumentation(); |
| | 0 | 29 | | |
| | 0 | 30 | | metrics |
| | 0 | 31 | | .AddMeter("Microsoft.AspNetCore.Hosting") |
| | 0 | 32 | | .AddMeter("Microsoft.AspNetCore.Server.Kestrel") |
| | 0 | 33 | | .AddOtlpExporter(); |
| | 0 | 34 | | }) |
| | 0 | 35 | | .WithTracing(tracing => |
| | 0 | 36 | | { |
| | 0 | 37 | | tracing |
| | 0 | 38 | | .AddNpgsql() |
| | 0 | 39 | | .AddHttpClientInstrumentation() |
| | 0 | 40 | | .AddAspNetCoreInstrumentation(); |
| | 0 | 41 | | |
| | 0 | 42 | | tracing |
| | 0 | 43 | | .SetSampler(new TraceIdRatioBasedSampler(settings.TracingSamplingRatio)) |
| | 0 | 44 | | .AddOtlpExporter(); |
| | 0 | 45 | | }); |
| | 0 | 46 | | } |
| | | 47 | | } |