Skip to content

Implement OpenTelemetry for C# service #455

@davideme

Description

@davideme

Overview

Implement the OpenTelemetry integration for the C# (ASP.NET Core + EF Core) service as specified in src/csharp/adr/008-opentelemetry.md.

Parent issue: #14

Tasks

  • Add required NuGet packages (OpenTelemetry.Extensions.Hosting, OpenTelemetry.Instrumentation.AspNetCore, OpenTelemetry.Instrumentation.Http, OpenTelemetry.Instrumentation.EntityFrameworkCore, OpenTelemetry.Instrumentation.Runtime, OpenTelemetry.Exporter.OpenTelemetryProtocol)
  • Register OTel services in Program.cs via AddOpenTelemetry() — OTLP exporters MUST NOT be registered when OTEL_EXPORTER_OTLP_ENDPOINT is absent
  • Configure AddAspNetCoreInstrumentation for inbound HTTP traces and metrics
  • Configure AddHttpClientInstrumentation for outbound HTTP traces
  • Configure AddEntityFrameworkCoreInstrumentation for database traces
  • Configure AddRuntimeInstrumentation for .NET runtime metrics (GC, threads, heap)
  • Bridge ILogger to OTel via AddOpenTelemetry() log provider
  • Verify metrics baseline: http.server.request.duration, http.server.active_requests, .NET runtime metrics
  • Set resource attributes: service.name=lamp-control-api-csharp, service.version, deployment.environment
  • Support both grpc and http/protobuf protocols via OTEL_EXPORTER_OTLP_PROTOCOL
  • Ensure W3C TraceContext + Baggage propagation is enabled
  • Add/update tests to verify instrumentation wires up correctly

Instrumentation summary

Signal Mechanism Type
Traces – Inbound HTTP AddAspNetCoreInstrumentation Config only
Traces – Outbound HTTP AddHttpClientInstrumentation Config only
Traces – Database (EF Core) AddEntityFrameworkCoreInstrumentation Config only
Metrics – HTTP server AddAspNetCoreInstrumentation Config only
Metrics – .NET runtime AddRuntimeInstrumentation Config only
Logs OTel ILogger bridge Config only

Acceptance criteria

  • OTLP exporters are not registered when OTEL_EXPORTER_OTLP_ENDPOINT is not set
  • All three pillars (traces, metrics, logs) emit data when collector is configured
  • Existing tests continue to pass

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions