Skip to content

Commit 0bc9382

Browse files
Add traceID if possible when using context logger. (#2518)
* Add traceID if possible when using context logger. Signed-off-by: Cyril Tovena <[email protected]> * Simplify userID extraction Signed-off-by: Peter Štibraný <[email protected]> * CHANGELOG.md Signed-off-by: Peter Štibraný <[email protected]> Co-authored-by: Peter Štibraný <[email protected]>
1 parent decd5b4 commit 0bc9382

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* `cortex_querier_bucket_store_blocks_meta_sync_consistency_delay_seconds` > `cortex_querier_blocks_meta_sync_consistency_delay_seconds`
1919
* [CHANGE] Experimental TSDB: Modified default values for `compactor.deletion-delay` option from 48h to 12h and `-experimental.tsdb.bucket-store.ignore-deletion-marks-delay` from 24h to 6h. #2414
2020
* [CHANGE] Experimental WAL: Default value of `-ingester.checkpoint-enabled` changed to `true`. #2416
21+
* [CHANGE] `trace_id` field in log files has been renamed to `traceID`. #2518
2122
* [FEATURE] Ruler: The `-ruler.evaluation-delay` flag was added to allow users to configure a default evaluation delay for all rules in cortex. The default value is 0 which is the current behavior. #2423
2223
* [ENHANCEMENT] Experimental TSDB: sample ingestion errors are now reported via existing `cortex_discarded_samples_total` metric. #2370
2324
* [ENHANCEMENT] Failures on samples at distributors and ingesters return the first validation error as opposed to the last. #2383

pkg/util/log.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ func WithContext(ctx context.Context, l log.Logger) log.Logger {
103103
// Weaveworks uses "orgs" and "orgID" to represent Cortex users,
104104
// even though the code-base generally uses `userID` to refer to the same thing.
105105
userID, err := user.ExtractOrgID(ctx)
106-
if err != nil {
107-
return l
106+
if err == nil {
107+
l = WithUserID(userID, l)
108108
}
109-
l = WithUserID(userID, l)
110109

111110
traceID, ok := middleware.ExtractTraceID(ctx)
112111
if !ok {
@@ -127,7 +126,7 @@ func WithUserID(userID string, l log.Logger) log.Logger {
127126
// its details.
128127
func WithTraceID(traceID string, l log.Logger) log.Logger {
129128
// See note in WithContext.
130-
return log.With(l, "trace_id", traceID)
129+
return log.With(l, "traceID", traceID)
131130
}
132131

133132
// CheckFatal prints an error and exits with error code 1 if err is non-nil

0 commit comments

Comments
 (0)