diff --git a/src/Inshapardaz.Api/Inshapardaz.Api.csproj b/src/Inshapardaz.Api/Inshapardaz.Api.csproj index 3815b132..c2f8a4a9 100644 --- a/src/Inshapardaz.Api/Inshapardaz.Api.csproj +++ b/src/Inshapardaz.Api/Inshapardaz.Api.csproj @@ -12,8 +12,11 @@ + + + diff --git a/src/Inshapardaz.Api/Program.cs b/src/Inshapardaz.Api/Program.cs index 79f3d6fa..6d4c6a0d 100644 --- a/src/Inshapardaz.Api/Program.cs +++ b/src/Inshapardaz.Api/Program.cs @@ -30,27 +30,39 @@ builder.WebHost.UseKestrel(o => o.Limits.MaxRequestBodySize = null); //===================================================================== -// Configura open telemetry +// Configure open telemetry const string serviceName = "Inshapardaz"; -builder.Logging.AddOpenTelemetry(options => -{ - options - .SetResourceBuilder( - ResourceBuilder.CreateDefault() - .AddService(serviceName)) - .AddConsoleExporter(); -}); +string tracingOtlpEndpoint = builder.Configuration["OLTP_ENDPOINT_URL"]; + +builder.Logging.AddOpenTelemetry(options => options + .SetResourceBuilder(ResourceBuilder.CreateDefault() + .AddService(serviceName)) + .AddConsoleExporter()); builder.Services.AddOpenTelemetry() .ConfigureResource(resource => resource.AddService(serviceName)) - .WithTracing(tracing => tracing - .AddAspNetCoreInstrumentation() - .AddConsoleExporter()) .WithMetrics(metrics => metrics .AddAspNetCoreInstrumentation() - .AddConsoleExporter()); + .AddMeter("Microsoft.AspnetCore.Hosting") + .AddMeter("Microsoft.AspnetCore.Server.Kestrel") + .AddPrometheusExporter() + .AddConsoleExporter()) + .WithTracing(tracing => + { + tracing + .AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation(); + if (tracingOtlpEndpoint != null) + { + tracing.AddOtlpExporter(opt => opt.Endpoint = new Uri(tracingOtlpEndpoint)); + } + else + { + tracing.AddConsoleExporter(); + } + }); //===================================================================== // Add services to the container. @@ -63,9 +75,9 @@ //-------------------------------------------------------------------- builder.Services.AddCors(options => { - options.AddDefaultPolicy(builder => + options.AddDefaultPolicy(policyBuilder => { - builder.WithOrigins("*") + policyBuilder.WithOrigins("*") .AllowAnyHeader() .AllowAnyMethod() .WithExposedHeaders(HeaderNames.Location, HeaderNames.ContentDisposition, HeaderNames.ContentType); @@ -180,13 +192,13 @@ .WithExposedHeaders(HeaderNames.Location, HeaderNames.ContentDisposition, HeaderNames.ContentType)); app.UseHttpsRedirection(); +app.MapPrometheusScrapingEndpoint(); app.UseAuthorization(); app.UseRequestLogging(); app.UseMiddleware(); app.UseMiddleware(); app.UseStatusCodeMiddleWare(); - app.UseMiddleware(); app.MapControllers();