Compare commits
13
Commits
15a2ad0b89
..
otel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3572902300 | ||
|
|
085b69d388 | ||
|
|
dbb7dc168b | ||
|
|
31333ea168 | ||
|
|
e26c79a9d7 | ||
|
|
200789e832 | ||
|
|
ae1440fce3 | ||
|
|
b58b5777fd | ||
|
|
3e84af9bb5 | ||
|
|
83dfdc2cc3 | ||
|
|
bbdb27b116 | ||
|
|
31f2439033 | ||
|
|
1da1328870 |
+8
-1
@@ -29,6 +29,13 @@ steps:
|
||||
commands:
|
||||
- trivy image --image-src remote --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/webapitest:${DRONE_BUILD_NUMBER}
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
event:
|
||||
exclude:
|
||||
- promote
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
@@ -58,4 +65,4 @@ trigger:
|
||||
event:
|
||||
- promote
|
||||
target:
|
||||
- uat
|
||||
- staging
|
||||
@@ -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
@@ -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();
|
||||
@@ -8,7 +8,7 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5221"
|
||||
"applicationUrl": "http://0.0.0.0:5000"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user