Add query info to query.Exec span (#9320)

**What this PR does / why we need it**:
It's kinda difficult to see the query that is being run on a trace.

The only place where I can see the query is in the `url` attribute of
the `loki_api_v1_query_range` handler, but since it’s encoded it’s kinda
difficult to read. If it's elsewhere it's not quite obvious.

It’d make sense to have the query in the `query.Exec` span along with
the stats of the query.

**Checklist**
- [ ] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [ ] Documentation added
- [ ] Tests updated
- [ ] `CHANGELOG.md` updated
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`
chaudum/cri-config
Salva Corts 2 years ago committed by GitHub
parent ebf271e64b
commit ca8a7accf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      pkg/logql/engine.go

@ -214,8 +214,17 @@ func (q *query) resultLength(res promql_parser.Value) int {
func (q *query) Exec(ctx context.Context) (logqlmodel.Result, error) {
sp, ctx := opentracing.StartSpanFromContext(ctx, "query.Exec")
defer sp.Finish()
log := spanlogger.FromContext(ctx)
defer log.Finish()
spLogger := spanlogger.FromContext(ctx)
defer spLogger.Finish()
sp.LogKV(
"type", GetRangeType(q.params),
"query", q.params.Query(),
"start", q.params.Start(),
"end", q.params.End(),
"step", q.params.Step(),
"length", q.params.End().Sub(q.params.Start()),
)
if q.logExecQuery {
queryHash := HashedQuery(q.params.Query())
@ -240,7 +249,7 @@ func (q *query) Exec(ctx context.Context) (logqlmodel.Result, error) {
queueTime, _ := ctx.Value(httpreq.QueryQueueTimeHTTPHeader).(time.Duration)
statResult := statsCtx.Result(time.Since(start), queueTime, q.resultLength(data))
statResult.Log(level.Debug(log))
statResult.Log(level.Debug(spLogger))
status := "200"
if err != nil {

Loading…
Cancel
Save