Skip to content

Add OTLP logs signal to .NET observability SDK (th-5dca7d)#70

Open
brentrager wants to merge 1 commit into
mainfrom
dotnet-otlp-logs-signal
Open

Add OTLP logs signal to .NET observability SDK (th-5dca7d)#70
brentrager wants to merge 1 commit into
mainfrom
dotnet-otlp-logs-signal

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

The .NET observability SDK exported traces + metrics but not logs. Per the shared design contract (ADR-100), the SDK should send logs into the product /v1/logs OTLP endpoint, correlated to traces.

Solution

New ILoggingBuilder extension SmooObservabilityLoggingExtensions.AddSmooObservability(...) that wires the OpenTelemetry logging provider with an OTLP/HTTP exporter to the logs endpoint. This is the standard OTel logging path — logs hook the host's logging pipeline rather than the standalone tracer/meter providers in ObservabilitySdk.Setup.

  • Same config as traces/metrics — reuses SMOOAI_OBSERVABILITY_ENDPOINT (→ /v1/logs), the same static-token / M2M auth, and the same enable/disable flag. No new config keys.
  • Env-driven overload (AddSmooObservability(BootstrapEnv?)) and an explicit SetupOtelOptions overload.
  • IncludeScopes / ParseStateValues / IncludeFormattedMessage set so structured state + scopes → attributes (product parsed_fields) and the rendered message → body. trace_id / span_id are stamped from the active Activity by the OTel logging provider.
  • No-op when disabled or no logs endpoint is configured — existing logging output is untouched.
  • Refactor: BuildResource, ConfigureExporter, and ResolveAuth are now shared across traces/metrics and logs so all three carry the same resource and authenticate identically.

Packages

  • Library: no new dependency — reuses the existing OpenTelemetry + OpenTelemetry.Exporter.OpenTelemetryProtocol 1.16.0 packages (the OTLP log exporter ships in the exporter package already referenced).
  • Tests: added OpenTelemetry.Exporter.InMemory 1.16.0 to capture and assert on emitted log records.

Verification

Correlation verified, not just compiled: LogWithinActiveActivity_CarriesRealTraceAndSpanId emits a log inside an active ActivitySource span through the extension-configured provider and asserts the captured LogRecord.TraceId/SpanId equal the live span's W3C ids. Plus no-op tests (disabled / no-endpoint → no OpenTelemetry provider registered).

dotnet build (net8/9/10, warnings-as-errors), dotnet test (73 passed, 4 new), and dotnet format --verify-no-changes all green in Release.

🤖 Generated with Claude Code

https://claude.ai/code/session_01S2bM94GAnVjYSSv1x7HKRB

Send LOGS into the product /v1/logs OTLP endpoint, correlated to traces,
matching the traces/metrics setup (ADR-100). The logs signal hooks the host's
ILoggingBuilder — the standard OTel logging path — rather than the standalone
tracer/meter providers in ObservabilitySdk.Setup.

- New SmooObservabilityLoggingExtensions.AddSmooObservability(ILoggingBuilder):
  env-driven (SMOOAI_OBSERVABILITY_ENDPOINT → /v1/logs) and explicit overloads.
  Same endpoint, same auth (static token or M2M TokenProvider), same enable
  flag as traces/metrics. No new config keys.
- AddOpenTelemetry() on ILoggingBuilder with IncludeScopes / ParseStateValues /
  IncludeFormattedMessage so structured state → attributes and the message → body.
  trace_id/span_id come from the active Activity automatically.
- No-op when disabled or no logs endpoint (existing logging untouched).
- Refactor: share the resource builder + exporter config + auth resolution
  between traces/metrics and logs (BuildResource, ConfigureExporter, ResolveAuth).

Reuses the existing OpenTelemetry 1.16.0 exporter package — no new deps in the
library. Test adds OpenTelemetry.Exporter.InMemory to prove a log emitted inside
an active Activity carries that span's real W3C trace/span id.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S2bM94GAnVjYSSv1x7HKRB
@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5deb34b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant