| | 1 | | using Npgsql; |
| | 2 | | using OpenTelemetry.Logs; |
| | 3 | | using OpenTelemetry.Trace; |
| | 4 | | using OpenTelemetry.Metrics; |
| | 5 | | using OpenTelemetry.Resources; |
| | 6 | |
|
| | 7 | | namespace Syki.Daemon.Configs; |
| | 8 | |
|
| | 9 | | public static class OpenTelemetryConfigs |
| | 10 | | { |
| | 11 | | public const string DomainEventsProcessing = nameof(DomainEventsProcessing); |
| | 12 | | public const string CommandsProcessing = nameof(CommandsProcessing); |
| | 13 | |
|
| | 14 | | public static void AddDaemonOpenTelemetryConfigs(this WebApplicationBuilder builder) |
| | 15 | | { |
| 4 | 16 | | if (Env.IsTesting()) return; |
| | 17 | |
|
| 0 | 18 | | var settings = builder.Configuration.Tracing(); |
| | 19 | |
|
| 0 | 20 | | builder.Services |
| 0 | 21 | | .AddOpenTelemetry() |
| 0 | 22 | | .ConfigureResource(resource => resource.AddService("Daemon")) |
| 0 | 23 | | .WithTracing(tracing => |
| 0 | 24 | | { |
| 0 | 25 | | tracing.AddSource(DomainEventsProcessing); |
| 0 | 26 | | tracing.AddSource(CommandsProcessing); |
| 0 | 27 | |
|
| 0 | 28 | | tracing |
| 0 | 29 | | .AddNpgsql() |
| 0 | 30 | | .AddQuartzInstrumentation() |
| 0 | 31 | | .AddHttpClientInstrumentation() |
| 0 | 32 | | .AddAspNetCoreInstrumentation(); |
| 0 | 33 | |
|
| 0 | 34 | | tracing |
| 0 | 35 | | .SetSampler(new TraceIdRatioBasedSampler(settings.SamplingRatio)) |
| 0 | 36 | | .AddOtlpExporter(); |
| 0 | 37 | | }); |
| 0 | 38 | | } |
| | 39 | | } |