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