## What & why S-16b, second of the S-16 split, on top of the #125 backplane. The five .NET services now emit OpenTelemetry traces so a request is **one connected trace** across them. - Each host wires `AddOpenTelemetry().WithTracing(...)` with `AddAspNetCoreInstrumentation` (incoming) + `AddHttpClientInstrumentation` (outgoing) + `AddOtlpExporter` to **Tempo**. - Because every cross-service call already goes through a typed `HttpClient` (§8 boundaries), the W3C `traceparent` propagates with no manual code — bff → domain → acl → openzaak and bff → projection-api stitch into a single trace. - Service name + OTLP endpoint come from `OTEL_*` env set per app service in compose. `/health` is filtered out so liveness polls don't flood the traces. No new ADR — ADR-0023 already records the stack + the two documented gaps (browser-side tracing is out of scope, so the trace begins at the BFF; the async Flowable-poll boundary is a separate trace). Closes #123 ## Definition of Done - [x] Failing test committed first (`verify-tracing` fails with no instrumentation). - [x] Implementation makes it pass — **validated locally end to end**: a real connected trace spanning `bff` + `projection-api` was found in Tempo (BFF→projection→db + Tempo subset, no OpenZaak/egress). - [x] Conventional Commits referencing the issue (`refs #123`). - [ ] CI green — awaiting Gitea Actions (verify-tracing added to verify-stack after verify-bff). - [x] `docker compose up` health unaffected — services boot healthy even when Tempo is unreachable (exporter no-ops; verified). - [x] Docs — demo-script + BACKLOG. - [x] ADR — none needed (covered by ADR-0023). ## Notes for reviewers - **Per-service wiring, no shared lib:** the block is duplicated across the five hosts by design — services don't share code across boundaries here (§8), same as the duplicated typed clients. - **Packages:** OpenTelemetry.Extensions.Hosting / Instrumentation.AspNetCore / Instrumentation.Http / Exporter.OpenTelemetryProtocol, all 1.17.0, pinned per-csproj (no central props file). - **The check** generates anonymous BFF→projection traffic (no auth, no OpenZaak), then queries Tempo (TraceQL search → fetch trace → assert both service.names present) from a python:3-slim container in-network — same idiom as run-projection-check.sh. - **Next:** #124 (S-16c) adds `/metrics` + Prometheus scrape targets + golden-signal Grafana dashboards. Reviewed-on: #126
58 lines
2.4 KiB
C#
58 lines
2.4 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using OpenTelemetry.Resources;
|
|
using OpenTelemetry.Trace;
|
|
using Projection.ReadModel;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// OpenTelemetry tracing (S-16b, ADR-0023): auto-instrument incoming ASP.NET Core requests, exported
|
|
// over OTLP to Tempo, so a BFF → projection-api read is one connected trace. Service name + OTLP
|
|
// endpoint come from OTEL_* env (compose); the exporter no-ops when Tempo is unreachable.
|
|
builder.Services.AddOpenTelemetry()
|
|
.ConfigureResource(r => r.AddService(
|
|
builder.Configuration["OTEL_SERVICE_NAME"] ?? builder.Environment.ApplicationName))
|
|
.WithTracing(tracing => tracing
|
|
.AddAspNetCoreInstrumentation(o => o.Filter = ctx => ctx.Request.Path != "/health")
|
|
.AddHttpClientInstrumentation()
|
|
.AddOtlpExporter());
|
|
|
|
var connectionString = builder.Configuration.GetConnectionString("Projection")
|
|
?? throw new InvalidOperationException("Missing connection string 'ConnectionStrings:Projection'");
|
|
|
|
builder.Services.AddProjectionReadModel(connectionString);
|
|
|
|
var app = builder.Build();
|
|
|
|
// Ensure the schema exists before serving reads. The Event Subscriber migrates this shared DB too;
|
|
// MigrateProjectionAsync serialises concurrent migrators with a session advisory lock so the whole
|
|
// migration sequence runs exactly once (see ServiceCollectionExtensions).
|
|
await app.Services.MigrateProjectionAsync();
|
|
|
|
app.MapGet("/health", () => "Healthy");
|
|
|
|
// The read side of the projection. Public-safe field filtering is tightened in S-09; for now
|
|
// the minimal projection only carries id + status (bsn/naam deferred — ADR-0008).
|
|
app.MapGet("/register", async (ProjectionDbContext db, CancellationToken ct) =>
|
|
{
|
|
var rows = await db.RegisterEntries
|
|
.OrderBy(r => r.Id)
|
|
.Select(r => new RegisterEntryDto(r.Id, r.Status, r.Reference, r.Bsn, r.NaamPlaceholder))
|
|
.ToListAsync(ct);
|
|
return Results.Ok(rows);
|
|
});
|
|
|
|
app.MapGet("/register/{id}", async (string id, ProjectionDbContext db, CancellationToken ct) =>
|
|
{
|
|
var row = await db.RegisterEntries
|
|
.Where(r => r.Id == id)
|
|
.Select(r => new RegisterEntryDto(r.Id, r.Status, r.Reference, r.Bsn, r.NaamPlaceholder))
|
|
.SingleOrDefaultAsync(ct);
|
|
return row is null ? Results.NotFound() : Results.Ok(row);
|
|
});
|
|
|
|
await app.RunAsync();
|
|
|
|
public sealed record RegisterEntryDto(string Id, string Status, string? Reference, string? Bsn, string? NaamPlaceholder);
|
|
|
|
public partial class Program;
|