Skip to content

Commit 32a3e9a

Browse files
authored
[-] add source and metric tags to pgx traces, fixes #978 (#980)
Resave logger to `ctx` after every `.WithField()` update, so that logs from called functions will use the same updated logger.
1 parent 826bac1 commit 32a3e9a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/reaper/reaper.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (r *Reaper) Reap(ctx context.Context) {
9999
hostsToShutDownDueToRoleChange := make(map[string]bool) // hosts went from master to standby and have "only if master" set
100100
for _, monitoredSource := range r.monitoredSources {
101101
srcL := logger.WithField("source", monitoredSource.Name)
102+
ctx = log.WithLogger(ctx, srcL)
102103

103104
if monitoredSource.Connect(ctx, r.Sources) != nil {
104105
srcL.Warning("could not init connection, retrying on next iteration")
@@ -287,7 +288,9 @@ func (r *Reaper) reapMetricMeasurements(ctx context.Context, md *sources.SourceC
287288
failedFetches := 0
288289
lastDBVersionFetchTime := time.Unix(0, 0) // check DB ver. ev. 5 min
289290

290-
l := r.logger.WithField("source", md.Name).WithField("metric", metricName)
291+
l := log.GetLogger(ctx).WithField("metric", metricName)
292+
ctx = log.WithLogger(ctx, l)
293+
291294
if metricName == specialMetricServerLogEventCounts {
292295
metrics.ParseLogs(ctx, md, md.RealDbname, md.GetMetricInterval(metricName), r.measurementCh, "", "")
293296
return
@@ -470,7 +473,7 @@ func (r *Reaper) FetchMetric(ctx context.Context, md *sources.SourceConn, metric
470473
if metric, ok = metricDefs.GetMetricDef(metricName); !ok {
471474
return nil, metrics.ErrMetricNotFound
472475
}
473-
l := r.logger.WithField("source", md.Name).WithField("metric", metricName)
476+
l := log.GetLogger(ctx)
474477

475478
if metric.IsInstanceLevel && r.Metrics.InstanceLevelCacheMaxSeconds > 0 && time.Second*time.Duration(md.GetMetricInterval(metricName)) < r.Metrics.CacheAge() {
476479
cacheKey = fmt.Sprintf("%s:%s", md.GetClusterIdentifier(), metricName)

0 commit comments

Comments
 (0)