diff --git a/SampleApi/Program.cs b/SampleApi/Program.cs index 8581ec2..39873bd 100644 --- a/SampleApi/Program.cs +++ b/SampleApi/Program.cs @@ -7,18 +7,29 @@ using System.Diagnostics.Metrics; var builder = WebApplication.CreateBuilder(args); +// ONLY FOR TESTING: Allow untrusted certificates +var handler = new HttpClientHandler +{ + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true +}; +builder.Services.AddHttpClient("OtlpClient").ConfigurePrimaryHttpMessageHandler(() => handler); + // 1. Define Resource Information var resourceBuilder = ResourceBuilder.CreateDefault() .AddService("SampleApi"); // 2. Configuration Variables +// Using the API Key from your aspire-dashboard-auth secret var oltpApiKey = "mc3G63K2j5ZOEsi0AjMojLTXm1KEZFctzIIjSwDiTGut8qGSkPuWwxGP1RbscJUo"; -var oltpAddress = "http://aspire-dashboard-service.aspire.svc.cluster.local:18889"; + +// Pointing to your Traefik IngressRoute. +// The SDK will append /v1/traces, /v1/metrics, etc., to this base URL +var oltpAddress = "https://aspire.khongisa.co.za/otlp-grpc"; +//var oltpAddress = "https://aspire.khongisa.co.za/otlp-http"; builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -builder.Services.AddHealthChecks(); // 3. Configure OpenTelemetry Logging builder.Logging.AddOpenTelemetry(logging => @@ -27,50 +38,44 @@ builder.Logging.AddOpenTelemetry(logging => logging.AddOtlpExporter(opt => { opt.Endpoint = new Uri(oltpAddress); - opt.Protocol = OtlpExportProtocol.Grpc; - opt.Headers = $"x-otlp-api-key={oltpApiKey}"; + opt.Protocol = OtlpExportProtocol.Grpc; // Switched to gRPC + // Note: Headers are only needed if you re-enable ApiKey auth mode }); }); -// 4. Configure Tracing and Metrics (Merged into one registration) +// 4. Configure Tracing and Metrics builder.Services.AddOpenTelemetry() .WithTracing(tracing => tracing .SetResourceBuilder(resourceBuilder) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() - .AddOtlpExporter(opt => + .AddOtlpExporter(opt => { opt.Endpoint = new Uri(oltpAddress); opt.Protocol = OtlpExportProtocol.Grpc; - opt.Headers = $"x-otlp-api-key={oltpApiKey}"; })) .WithMetrics(metrics => metrics .SetResourceBuilder(resourceBuilder) - .AddMeter("SampleApi") // Register your custom meter here + .AddMeter("SampleApi") .AddAspNetCoreInstrumentation() .AddRuntimeInstrumentation() - .AddOtlpExporter(opt => + .AddOtlpExporter(opt => { opt.Endpoint = new Uri(oltpAddress); opt.Protocol = OtlpExportProtocol.Grpc; - opt.Headers = $"x-otlp-api-key={oltpApiKey}"; })); var app = builder.Build(); -// 5. Initialize your Meter for use in the app -var myMeter = new Meter("SampleApi", "1.0.0"); -var transactionCounter = myMeter.CreateCounter("CustomCounter"); - if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } -app.MapHealthChecks("/health"); app.UseRouting(); app.UseAuthorization(); app.MapControllers(); +app.Run(); app.Run(); \ No newline at end of file