From 389446ee2103593b8ef27b08e7b7393e3ed2c847 Mon Sep 17 00:00:00 2001 From: Spencer Twaddle <7374698+stwaddle@users.noreply.github.com> Date: Mon, 4 May 2026 17:29:01 -0500 Subject: [PATCH] Phase 1: Wire up OpenTelemetry in Budget.Api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds OTel packages (Extensions.Hosting, Instrumentation.AspNetCore/Http/EFCore, Exporter.OTLP) and configures logging + tracing in Program.cs. Endpoint is intentionally left unset in code — read from OTEL_EXPORTER_OTLP_ENDPOINT at runtime. Co-Authored-By: Claude Sonnet 4.6 --- src/Budget.Api/Budget.Api.csproj | 5 +++++ src/Budget.Api/Program.cs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Budget.Api/Budget.Api.csproj b/src/Budget.Api/Budget.Api.csproj index 48be54e..cb46c05 100644 --- a/src/Budget.Api/Budget.Api.csproj +++ b/src/Budget.Api/Budget.Api.csproj @@ -13,6 +13,11 @@ all + + + + + diff --git a/src/Budget.Api/Program.cs b/src/Budget.Api/Program.cs index 299c82e..43c9f50 100644 --- a/src/Budget.Api/Program.cs +++ b/src/Budget.Api/Program.cs @@ -10,9 +10,27 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; var builder = WebApplication.CreateBuilder(args); +builder.Logging.AddOpenTelemetry(logging => +{ + logging.IncludeFormattedMessage = true; + logging.IncludeScopes = true; +}); + +builder.Services.AddOpenTelemetry() + .ConfigureResource(resource => resource + .AddService(serviceName: "budget", serviceVersion: "1.0.0")) + .WithLogging() + .WithTracing(tracing => tracing + .AddAspNetCoreInstrumentation() + .AddHttpClientInstrumentation() + .AddEntityFrameworkCoreInstrumentation() + .AddOtlpExporter()); + var connStr = builder.Configuration.GetConnectionString("DefaultConnection") ?? $"Host={builder.Configuration["POSTGRES_HOST"] ?? "localhost"};" + $"Port={builder.Configuration["POSTGRES_PORT"] ?? "5432"};" +