Add OTLP logs signal to .NET observability SDK (th-5dca7d)#70
Open
brentrager wants to merge 1 commit into
Open
Add OTLP logs signal to .NET observability SDK (th-5dca7d)#70brentrager wants to merge 1 commit into
brentrager wants to merge 1 commit into
Conversation
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/logsOTLP endpoint, correlated to traces.Solution
New
ILoggingBuilderextensionSmooObservabilityLoggingExtensions.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 inObservabilitySdk.Setup.SMOOAI_OBSERVABILITY_ENDPOINT(→/v1/logs), the same static-token / M2M auth, and the same enable/disable flag. No new config keys.AddSmooObservability(BootstrapEnv?)) and an explicitSetupOtelOptionsoverload.IncludeScopes/ParseStateValues/IncludeFormattedMessageset so structured state + scopes → attributes (productparsed_fields) and the rendered message → body.trace_id/span_idare stamped from the activeActivityby the OTel logging provider.BuildResource,ConfigureExporter, andResolveAuthare now shared across traces/metrics and logs so all three carry the same resource and authenticate identically.Packages
OpenTelemetry+OpenTelemetry.Exporter.OpenTelemetryProtocol1.16.0 packages (the OTLP log exporter ships in the exporter package already referenced).OpenTelemetry.Exporter.InMemory1.16.0 to capture and assert on emitted log records.Verification
Correlation verified, not just compiled:
LogWithinActiveActivity_CarriesRealTraceAndSpanIdemits a log inside an activeActivitySourcespan through the extension-configured provider and asserts the capturedLogRecord.TraceId/SpanIdequal 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), anddotnet format --verify-no-changesall green in Release.🤖 Generated with Claude Code
https://claude.ai/code/session_01S2bM94GAnVjYSSv1x7HKRB