initial commit

This commit is contained in:
2026-02-16 17:36:47 +11:00
commit cb84fe3411
10 changed files with 272 additions and 0 deletions

33
Program.cs Normal file
View File

@@ -0,0 +1,33 @@
using OpenTelemetry.Logs;
var builder = WebApplication.CreateBuilder(args);
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
if (useOtlpExporter)
{
logging.AddOtlpExporter();
}
else
{
Console.WriteLine("OTEL_EXPORTER_OTLP_ENDPOINT is not set. Skipping OTLP exporter configuration.");
}
});
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.MapGet("/log", (ILogger<Program> logger) =>
{
if (logger.IsEnabled(LogLevel.Information))
logger.LogInformation("Logging a message at {time:HH:mm:ss} on {machine}", DateTime.Now, Environment.MachineName);
return Results.Ok();
});
app.Run();