FDE-45: Add automatic log-trace correlation for slog#13
Open
prathamesh-sonpatki wants to merge 3 commits intomainfrom
Open
FDE-45: Add automatic log-trace correlation for slog#13prathamesh-sonpatki wants to merge 3 commits intomainfrom
prathamesh-sonpatki wants to merge 3 commits intomainfrom
Conversation
Add instrumentation/slog package that wraps any slog.Handler to automatically inject trace_id and span_id from the OTel span context into every log record. This bridges the log-trace correlation gap identified in FDE-32. Key features: - NewHandler wraps any slog.Handler with trace attribute injection - NewJSONHandler/NewTextHandler convenience constructors - SetDefault sets the global slog logger with trace correlation - Options struct for custom attribute key names - Injects only when span context is valid (sc.IsValid()) - Correctly handles WithAttrs/WithGroup via record cloning Linear: FDE-45 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add comprehensive documentation for the new instrumentation/slog package including quick setup, handler wrapping, custom keys, how it works, and the context requirement explanation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds three behavioral test cases for the slog handler: - Concurrent Handle calls validates r.Clone() goroutine safety - Deeply nested WithAttrs/WithGroup chains ensures trace injection survives arbitrary handler wrapping - Multiple calls with different contexts proves no ID leaking Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
instrumentation/slogpackage that wraps anyslog.Handlerto automatically injecttrace_idandspan_idfrom OTel span context into log recordsKey Design Decisions
r.Clone()beforeAddAttrs— prevents data races on the slog.Record's internal slicesc.IsValid()gate — injects even for sampled-out spans (valid IDs still useful for correlation)Optionsstruct — allows custom attribute key names (e.g.,dd.trace_idfor Datadog)ctx, works independentlyAPI Surface
Test Plan
Linear: https://linear.app/last9/issue/FDE-45
🤖 Generated with Claude Code