Skip to content

Commit

Permalink
logging middleware: log trace_id only if sampled (#529)
Browse files Browse the repository at this point in the history
* logging middleware: log `trace_id` only if sampled

* if not sampled, log it as `trace_id_unsampled`

* update changelog
  • Loading branch information
npazosmendez authored Jun 10, 2024
1 parent 5141842 commit c73f165
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
* [ENHANCEMENT] Expose `InstancesWithTokensCount` and `InstancesWithTokensInZoneCount` in `ring.ReadRing` interface. #516
* [ENHANCEMENT] Middleware: determine route name in a single place, and add `middleware.ExtractRouteName()` method to allow consuming applications to retrieve the route name. #527
* [ENHANCEMENT] SpanProfiler: do less work on unsampled traces. #528
* [ENHANCEMENT] Log Middleware: if the trace is not sampled, log its ID as `trace_id_unsampled` instead of `trace_id`. #529
* [BUGFIX] spanlogger: Support multiple tenant IDs. #59
* [BUGFIX] Memberlist: fixed corrupted packets when sending compound messages with more than 255 messages or messages bigger than 64KB. #85
* [BUGFIX] Ring: `ring_member_ownership_percent` and `ring_tokens_owned` metrics are not updated on scale down. #109
Expand Down
4 changes: 3 additions & 1 deletion middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ func NewLogMiddleware(log log.Logger, logRequestHeaders bool, logRequestAtInfoLe
// logWithRequest information from the request and context as fields.
func (l Log) logWithRequest(r *http.Request) log.Logger {
localLog := l.Log
traceID, ok := tracing.ExtractTraceID(r.Context())
traceID, ok := tracing.ExtractSampledTraceID(r.Context())
if ok {
localLog = log.With(localLog, "trace_id", traceID)
} else if traceID != "" {
localLog = log.With(localLog, "trace_id_unsampled", traceID)
}

if l.SourceIPs != nil {
Expand Down

0 comments on commit c73f165

Please sign in to comment.