Fix OTel wiring to match working Auth implementation

Three corrections vs Auth project:
- Replace AddOtlpExporter() (traces only) with UseOtlpExporter() so both
  traces and logs are exported via OTLP
- Remove redundant .WithLogging() call; builder.Logging.AddOpenTelemetry()
  is sufficient on its own
- Pass OTEL_EXPORTER_OTLP_ENDPOINT/PROTOCOL through from host env vars
  instead of hardcoding the collector URL

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Spencer Twaddle
2026-05-04 17:34:45 -05:00
parent bfd5880b9c
commit 8d4d7c7ce3
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -7,8 +7,8 @@ services:
- VIRTUAL_PORT=8080 - VIRTUAL_PORT=8080
- ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT:-Production} - ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT:-Production}
- ConnectionStrings__DefaultConnection=Host=apps-db;Port=5432;Database=${POSTGRES_DB:-budget};Username=${POSTGRES_USER:-budget};Password=${POSTGRES_PASSWORD} - ConnectionStrings__DefaultConnection=Host=apps-db;Port=5432;Database=${POSTGRES_DB:-budget};Username=${POSTGRES_USER:-budget};Password=${POSTGRES_PASSWORD}
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 - OTEL_EXPORTER_OTLP_ENDPOINT=${OTEL_EXPORTER_OTLP_ENDPOINT}
- OTEL_EXPORTER_OTLP_PROTOCOL=grpc - OTEL_EXPORTER_OTLP_PROTOCOL=${OTEL_EXPORTER_OTLP_PROTOCOL}
- OTEL_SERVICE_NAME=budget - OTEL_SERVICE_NAME=budget
depends_on: depends_on:
- apps-db - apps-db
+3 -3
View File
@@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using OpenTelemetry;
using OpenTelemetry.Resources; using OpenTelemetry.Resources;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
@@ -24,12 +25,11 @@ builder.Logging.AddOpenTelemetry(logging =>
builder.Services.AddOpenTelemetry() builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource .ConfigureResource(resource => resource
.AddService(serviceName: "budget", serviceVersion: "1.0.0")) .AddService(serviceName: "budget", serviceVersion: "1.0.0"))
.WithLogging()
.WithTracing(tracing => tracing .WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation() .AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation() .AddHttpClientInstrumentation()
.AddEntityFrameworkCoreInstrumentation() .AddEntityFrameworkCoreInstrumentation())
.AddOtlpExporter()); .UseOtlpExporter();
var connStr = builder.Configuration.GetConnectionString("DefaultConnection") var connStr = builder.Configuration.GetConnectionString("DefaultConnection")
?? $"Host={builder.Configuration["POSTGRES_HOST"] ?? "localhost"};" + ?? $"Host={builder.Configuration["POSTGRES_HOST"] ?? "localhost"};" +