Vonng / pg_exporter

Advanced PostgreSQL & Pgbouncer Metrics Exporter for Prometheus
https://pigsty.io
Apache License 2.0
180 stars 45 forks source link

Increase Caller Skip Depth by One Layer #55

Closed ulysseskk closed 5 months ago

ulysseskk commented 5 months ago

image Using the current caller depth skip function only outputs the tool method layer, making it impossible to pinpoint the actual problematic code. The reason is that the logging library by default skips the first 3 layers of calls, but in reality, reaching the actual call requires skipping 4 layers. To solve this problem, it is necessary to specify an additional caller skip layer when initializing the logger. Current code(utils.go:44): logger = level.NewFilter(logger, lvl) logger = log.With(logger, "timestamp", log.DefaultTimestampUTC, "caller", log.DefaultCaller) Correct code: logger = level.NewFilter(logger, lvl) logger = log.With(logger, "timestamp", log.DefaultTimestampUTC, "caller", log.Caller(4))

Vonng commented 5 months ago

Great point! Thank you very much~ Resolved by https://github.com/Vonng/pg_exporter/commit/e41aaff92dae7f704ba951a48387cbcdaf04a304