diff --git a/CHANGELOG.md b/CHANGELOG.md index fc5be175c3..7cd9e3d815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#6074](https://github.com/thanos-io/thanos/pull/6074) *: Allow configuring series and sample limits per `Series` request for all Stores. - [#6104](https://github.com/thanos-io/thanos/pull/6104) Objstore: Support S3 session token. - [#5548](https://github.com/thanos-io/thanos/pull/5548) Query: Added experimental support for load balancing across multiple Store endpoints. +- [#6148](https://github.com/thanos-io/thanos/pull/6148) Query-frontend: add traceID to slow query detected log line ### Fixed diff --git a/internal/cortex/frontend/transport/handler.go b/internal/cortex/frontend/transport/handler.go index e0b2075e0f..e4cad320cc 100644 --- a/internal/cortex/frontend/transport/handler.go +++ b/internal/cortex/frontend/transport/handler.go @@ -154,7 +154,7 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if shouldReportSlowQuery { - f.reportSlowQuery(r, queryString, queryResponseTime) + f.reportSlowQuery(r, hs, queryString, queryResponseTime) } if f.cfg.QueryStatsEnabled { f.reportQueryStats(r, queryString, queryResponseTime, stats) @@ -162,7 +162,7 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // reportSlowQuery reports slow queries. -func (f *Handler) reportSlowQuery(r *http.Request, queryString url.Values, queryResponseTime time.Duration) { +func (f *Handler) reportSlowQuery(r *http.Request, responseHeaders http.Header, queryString url.Values, queryResponseTime time.Duration) { // NOTE(GiedriusS): see https://github.com/grafana/grafana/pull/60301 for more info. grafanaDashboardUID := "-" if dashboardUID := r.Header.Get("X-Dashboard-Uid"); dashboardUID != "" { @@ -172,6 +172,10 @@ func (f *Handler) reportSlowQuery(r *http.Request, queryString url.Values, query if panelID := r.Header.Get("X-Panel-Id"); panelID != "" { grafanaPanelID = panelID } + thanosTraceID := "-" + if traceID := responseHeaders.Get("X-Thanos-Trace-Id"); traceID != "" { + thanosTraceID = traceID + } logMessage := append([]interface{}{ "msg", "slow query detected", @@ -181,6 +185,7 @@ func (f *Handler) reportSlowQuery(r *http.Request, queryString url.Values, query "time_taken", queryResponseTime.String(), "grafana_dashboard_uid", grafanaDashboardUID, "grafana_panel_id", grafanaPanelID, + "trace_id", thanosTraceID, }, formatQueryString(queryString)...) level.Info(util_log.WithContext(r.Context(), f.log)).Log(logMessage...)