5 Commits
Author SHA1 Message Date
Khwezi Mngoma 3572902300 GRPC switch 2026-05-02 12:47:13 +02:00
= 085b69d388 Added support for otel 2026-05-01 21:51:40 +00:00
= dbb7dc168b Changed launch profile to use the right hosting address 2026-04-18 06:40:59 +00:00
khwezi 31333ea168 Merge pull request 'Removed pull event from build stage' (#106) from test into main
continuous-integration/drone Build is passing
continuous-integration/drone/promote/staging Build is passing
Reviewed-on: #106
2026-04-04 16:39:53 +02:00
khwezi e26c79a9d7 Removed pull event from build stage 2026-04-04 16:39:31 +02:00
5 changed files with 77 additions and 7 deletions
-2
View File
@@ -33,8 +33,6 @@ trigger:
branch:
- main
event:
include:
- push
exclude:
- promote
+9 -1
View File
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@@ -8,10 +9,17 @@ namespace SampleApi.Controllers
[ApiController]
public class DemoController : ControllerBase
{
private static readonly ActivitySource MyActivitySource = new("SampleApi");
// GET: api/<DemoController>
[HttpGet]
public IEnumerable<string> Get()
public IEnumerable<string> Get(ILogger<DemoController> logger)
{
using var activity = MyActivitySource.StartActivity("ManualTraceTest");
activity?.SetTag("test.status", "success");
logger.LogInformation("sample api log");
return new string[] { "value1", "value2" };
}
+62 -3
View File
@@ -1,9 +1,69 @@
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
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";
// 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 =>
{
logging.SetResourceBuilder(resourceBuilder);
logging.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri(oltpAddress);
opt.Protocol = OtlpExportProtocol.Grpc; // Switched to gRPC
// Note: Headers are only needed if you re-enable ApiKey auth mode
});
});
// 4. Configure Tracing and Metrics
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.SetResourceBuilder(resourceBuilder)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri(oltpAddress);
opt.Protocol = OtlpExportProtocol.Grpc;
}))
.WithMetrics(metrics => metrics
.SetResourceBuilder(resourceBuilder)
.AddMeter("SampleApi")
.AddAspNetCoreInstrumentation()
.AddRuntimeInstrumentation()
.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri(oltpAddress);
opt.Protocol = OtlpExportProtocol.Grpc;
}));
var app = builder.Build();
@@ -13,10 +73,9 @@ if (app.Environment.IsDevelopment())
app.UseSwaggerUI();
}
app.MapHealthChecks("/health");
app.UseRouting();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
app.Run();
+1 -1
View File
@@ -8,7 +8,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5221"
"applicationUrl": "http://0.0.0.0:5000"
},
"https": {
"commandName": "Project",
+5
View File
@@ -10,6 +10,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.3" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.1" />
<PackageReference Include="Polly" Version="8.6.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
</ItemGroup>