From 678c0f2cc9713845dedc708ce30b680318036408 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sat, 25 Nov 2023 12:28:10 +0300 Subject: [PATCH 1/2] feat: add query logger --- query.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/query.go b/query.go index ed53f541..f8aabbe2 100644 --- a/query.go +++ b/query.go @@ -191,6 +191,9 @@ type Query struct { ExternalData []proto.InputColumn // ExternalTable name. Defaults to _data. ExternalTable string + + // Logger for query, optional, defaults to client logger with `query_id` field. + Logger *zap.Logger } // CorruptedDataErr means that provided hash mismatch with calculated. @@ -578,6 +581,30 @@ func (c *Client) Do(ctx context.Context, q Query) (err error) { if q.QueryID == "" { q.QueryID = uuid.New().String() } + { + // Setup query logger. + // + // Since Do is not goroutine-safe, we can safely reuse client logger, + // so next calls will utilize changed c.lg. + lg := c.lg + defer func(v *zap.Logger) { + // Set logger back after query is done. + c.lg = v + }(lg) + if q.Logger != nil { + // Using provided query logger. + lg = q.Logger + } else { + // Using client logger. + // Allow correlation of queries by query_id. + lg = lg.With( + zap.String("query_id", q.QueryID), + ) + } + // Set current logger to query-scoped. + // This will be used by all function calls until query is done. + c.lg = lg + } if c.otel { newCtx, span := c.tracer.Start(ctx, "Do", trace.WithSpanKind(trace.SpanKindClient), From 0ee876215c625c1b1cc5e22141e9c20d2578b90d Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sat, 25 Nov 2023 12:33:59 +0300 Subject: [PATCH 2/2] ci(pr): fix job --- .github/workflows/pr.yml | 4 ---- .github/workflows/x.yml | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8ee4b3a0..859242f8 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -6,9 +6,5 @@ on: # Common Go workflows from go faster # See https://github.com/go-faster/x jobs: - test: - uses: go-faster/x/.github/workflows/main.yml@main - lint: - uses: go-faster/x/.github/workflows/lint.yml@main commit: uses: go-faster/x/.github/workflows/commit.yml@main diff --git a/.github/workflows/x.yml b/.github/workflows/x.yml index 1a499537..c684dec8 100644 --- a/.github/workflows/x.yml +++ b/.github/workflows/x.yml @@ -3,6 +3,7 @@ name: x on: push: branches: [main] + pull_request: # Common Go workflows from go faster # See https://github.com/go-faster/x