From 4d07ba809e943acb94c347517cfbc1d760a65297 Mon Sep 17 00:00:00 2001 From: Konstantin Gvencadze Date: Mon, 24 Oct 2022 13:20:37 +0300 Subject: [PATCH] feat(module): add module for tracing SQL queries created by jackc/pgx (#1301) * feat: implementation of pgx query tracer * feat: add logger support * feat: add copy protocol support * test: add tests for query and copy trace * test: add table tests to test errors in different cases + add Log function test * feat: implement batch trace * docs: add godoc * feat: add stacktrace to span * test: add stacktrace length check * refac: make tracer private * refac: rename package from apmpgx to apmpgx_test to test usage like an external API * test: add t.Parallel() to table tests * chore(tracer): remove set stacktrace because it's unnecessary and bump pgx library version up to v4.17 and write comment for error with min required version * docs(instrumenting): add description of library that serves at "https://www.elastic.co/guide/en/apm/agent/go/master/builtin-modules.html" * docs(instrumenting): add example for apmgpx usage without pool * refac: replace NewTracer constructor with Instrument function that accepts pgx.ConnConfig. Move duplicate code to separate func called startSpan to make ...Trace functions small and simple. Add type casting checks to avoid instrument runtime panics. * test: replace NewTracer call with creating config and then override it with Instrument func for further tests * docs(ci): add license header, run update-licenses,update-modules, fmt and add apmpgx entry to Dockerfile-testing * fix(ci): add vanity import path * refac(tracer): add bool return argument check from startSpan() in CopyTrace func * refac(query): add statement parameter to startSpan func for full statement in span.Context.Database.Statement field * docs(apmpgx): update docs due changes in package API * test(e2e): add end-to-end tests for query and copy statements spans * feat(copy): add statement to copy from trace * test(copy): add statement to DatabaseSpanContext into E2E_CopyTrace test * fix(test): revert postgres connection in E2E_CopyTrace * fix(test): replace interface type cast from []string to pgx.Identifier according to stored value in data map * fix(tracer): add type switch for column names that stored in data map * docs(changelog): add apmpgx module description entry into unreleased section Co-authored-by: Stepan Rabotkin --- CHANGELOG.asciidoc | 1 + docs/instrumenting.asciidoc | 53 +++++++ module/apmpgx/doc.go | 19 +++ module/apmpgx/e2e_test.go | 212 ++++++++++++++++++++++++++ module/apmpgx/go.mod | 14 ++ module/apmpgx/go.sum | 281 +++++++++++++++++++++++++++++++++++ module/apmpgx/tracer.go | 201 +++++++++++++++++++++++++ module/apmpgx/tracer_test.go | 277 ++++++++++++++++++++++++++++++++++ scripts/Dockerfile-testing | 2 + 9 files changed, 1060 insertions(+) create mode 100644 module/apmpgx/doc.go create mode 100644 module/apmpgx/e2e_test.go create mode 100644 module/apmpgx/go.mod create mode 100644 module/apmpgx/go.sum create mode 100644 module/apmpgx/tracer.go create mode 100644 module/apmpgx/tracer_test.go diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 29eb97288..a5a373e41 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,6 +26,7 @@ https://github.com/elastic/apm-agent-go/compare/v2.1.0...main[View commits] - Global labels are now parsed when the tracer is constructed, instead of parsing only once on package initialization {pull}1290[#(1290)] - Rename span_frames_min_duration to span_stack_trace_min_duration {pull}1285[#(1285)] - Ignore *principal* headers by default {pull}1332[#(1332)] +- Add *apmpgx* module for postgres tracing with jackc/pgx driver enhanced support e.g. Copy and Batch statements {pull}1301[#(1301)] [[release-notes-2.x]] === Go Agent version 2.x diff --git a/docs/instrumenting.asciidoc b/docs/instrumenting.asciidoc index 111608267..7b6d4f92e 100644 --- a/docs/instrumenting.asciidoc +++ b/docs/instrumenting.asciidoc @@ -32,6 +32,7 @@ that framework's API. The request context can be used for reporting <> * <> * <> +* <> [[builtin-modules-apmhttp]] ==== module/apmhttp @@ -969,3 +970,55 @@ func main() { ... } ---- + +[[builtin-modules-apmpgx]] +== module/apmpgx +Package apmpgx provides a means of instrumenting the +https://github.com/jackc/pgx[Pgx] for v4.17+, +so that SQL queries are reported as spans within the current transaction. +Also this lib have extended support of pgx, such as COPY FROM queries and BATCH which have their own span types: +`db.postgresql.copy` and `db.postgresql.batch` accordingly. + +To report `pgx` queries, create `pgx` connection, and then provide config to `apmpgx.Instrument()`. If logger is presented in config, +then traces will be written to log. (It's safe to use without logger) + +Spans will be created for queries as long as they have context associated, and the +context includes a transaction. + +Example with pool: +[source,go] +---- +import ( + "github.com/jackc/pgx/v4/pgxpool" + + "go.elastic.com/apm/module/apmpgx/v2" +) + +func main() { + c, err := pgxpool.ParseConfig("dsn_string") + ... + pool, err := pgxpool.ParseConfig("dsn") + ... + // set custom logger before instrumenting + apmpgx.Instrument(pool.ConnConfig) + ... +} +---- + +Example without pool: +[source,go] +---- +import ( + "github.com/jackc/pgx/v4" + + "go.elastic.com/apm/module/apmpgx/v2" +) + +func main() { + c, err := pgx.Connect(context.Background, "dsn_string") + ... + // set custom logger before instrumenting + apmpgx.Instrument(c.Config()) + ... +} +---- \ No newline at end of file diff --git a/module/apmpgx/doc.go b/module/apmpgx/doc.go new file mode 100644 index 000000000..be7dd9727 --- /dev/null +++ b/module/apmpgx/doc.go @@ -0,0 +1,19 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// Package apmpgx provides helpers for tracing github.com/jackc/pgx/v4. Minimal required version is v4.17 +package apmpgx // import "go.elastic.co/apm/module/apmpgx/v2" diff --git a/module/apmpgx/e2e_test.go b/module/apmpgx/e2e_test.go new file mode 100644 index 000000000..bc87acd2a --- /dev/null +++ b/module/apmpgx/e2e_test.go @@ -0,0 +1,212 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package apmpgx_test + +import ( + "context" + "fmt" + "os" + _ "os" + "testing" + + "github.com/jackc/pgx/v4" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.elastic.co/apm/module/apmpgx/v2" + "go.elastic.co/apm/v2/apmtest" + "go.elastic.co/apm/v2/model" +) + +func Test_E2E_QueryTrace(t *testing.T) { + host := os.Getenv("PGHOST") + if host == "" { + t.Skipf("PGHOST not specified") + } + + cfg, err := pgx.ParseConfig(fmt.Sprintf("postgres://postgres:hunter2@%s:5432/test_db", host)) + require.NoError(t, err) + + ctx := context.TODO() + + apmpgx.Instrument(cfg) + + conn, err := pgx.ConnectConfig(ctx, cfg) + require.NoError(t, err) + + _, err = conn.Exec(ctx, "CREATE TABLE IF NOT EXISTS foo (bar INT)") + require.NoError(t, err) + + testcases := []struct { + name string + expectErr bool + query string + }{ + { + name: "QUERY span, success", + expectErr: false, + query: "SELECT * FROM foo", + }, + { + name: "QUERY span, error", + expectErr: true, + query: "SELECT * FROM foo2", + }, + } + + for _, tt := range testcases { + t.Run(tt.name, func(t *testing.T) { + _, spans, errs := apmtest.WithTransaction(func(ctx context.Context) { + rows, _ := conn.Query(ctx, tt.query) + defer rows.Close() + }) + + assert.NotNil(t, spans[0].ID) + + if tt.expectErr { + require.Len(t, errs, 1) + assert.Equal(t, "failure", spans[0].Outcome) + } else { + assert.Equal(t, "success", spans[0].Outcome) + + assert.Equal(t, "SELECT FROM foo", spans[0].Name) + assert.Equal(t, "postgresql", spans[0].Subtype) + assert.Equal(t, "success", spans[0].Outcome) + + assert.Equal(t, &model.SpanContext{ + Destination: &model.DestinationSpanContext{ + Address: cfg.Host, + Port: int(cfg.Port), + Service: &model.DestinationServiceSpanContext{ + Type: "db", + Name: "postgresql", + Resource: "postgresql", + }, + }, + Service: &model.ServiceSpanContext{ + Target: &model.ServiceTargetSpanContext{ + Type: "postgresql", + Name: cfg.Database, + }, + }, + Database: &model.DatabaseSpanContext{ + Instance: cfg.Database, + Statement: "SELECT * FROM foo", + Type: "sql", + User: "postgres", + }, + }, spans[0].Context) + } + }) + } +} + +func Test_E2E_CopyTrace(t *testing.T) { + host := os.Getenv("PGHOST") + if host == "" { + t.Skipf("PGHOST not specified") + } + + cfg, err := pgx.ParseConfig(fmt.Sprintf("postgres://postgres:hunter2@%s:5432/test_db", host)) + require.NoError(t, err) + + ctx := context.TODO() + + apmpgx.Instrument(cfg) + + conn, err := pgx.ConnectConfig(ctx, cfg) + require.NoError(t, err) + + _, err = conn.Exec(ctx, "CREATE TABLE IF NOT EXISTS foo (bar INT)") + require.NoError(t, err) + + testcases := []struct { + name string + expectErr bool + tableName pgx.Identifier + columnNames pgx.Identifier + rows [][]interface{} + }{ + { + name: "COPY span, success", + expectErr: false, + tableName: pgx.Identifier{"foo"}, + columnNames: pgx.Identifier{"bar"}, + rows: [][]interface{}{ + {int32(36)}, + {int32(29)}, + }, + }, + { + name: "COPY span, fail", + expectErr: true, + tableName: pgx.Identifier{"foo"}, + columnNames: pgx.Identifier{"bar"}, + rows: [][]interface{}{ + {"error"}, + }, + }, + } + + for _, tt := range testcases { + t.Run(tt.name, func(t *testing.T) { + _, spans, errs := apmtest.WithTransaction(func(ctx context.Context) { + _, _ = conn.CopyFrom(ctx, + tt.tableName, + tt.columnNames, + pgx.CopyFromRows(tt.rows)) + }) + + assert.NotNil(t, spans[0].ID) + + if tt.expectErr { + require.Len(t, errs, 1) + assert.Equal(t, "failure", spans[0].Outcome) + } else { + assert.Equal(t, "success", spans[0].Outcome) + + assert.Equal(t, "COPY TO foo", spans[0].Name) + assert.Equal(t, "postgresql", spans[0].Subtype) + + assert.Equal(t, &model.SpanContext{ + Destination: &model.DestinationSpanContext{ + Address: cfg.Host, + Port: int(cfg.Port), + Service: &model.DestinationServiceSpanContext{ + Type: "db", + Name: "postgresql", + Resource: "postgresql", + }, + }, + Service: &model.ServiceSpanContext{ + Target: &model.ServiceTargetSpanContext{ + Type: "postgresql", + Name: cfg.Database, + }, + }, + Database: &model.DatabaseSpanContext{ + Instance: cfg.Database, + Statement: "COPY TO foo(bar)", + Type: "sql", + User: "postgres", + }, + }, spans[0].Context) + } + }) + } +} diff --git a/module/apmpgx/go.mod b/module/apmpgx/go.mod new file mode 100644 index 000000000..1d4cb6860 --- /dev/null +++ b/module/apmpgx/go.mod @@ -0,0 +1,14 @@ +module go.elastic.co/apm/module/apmpgx/v2 + +go 1.15 + +require ( + github.com/jackc/pgx/v4 v4.17.0 + github.com/stretchr/testify v1.8.0 + go.elastic.co/apm/module/apmsql/v2 v2.1.0 + go.elastic.co/apm/v2 v2.1.0 +) + +replace go.elastic.co/apm/v2 => ../.. + +replace go.elastic.co/apm/module/apmsql/v2 => ../apmsql diff --git a/module/apmpgx/go.sum b/module/apmpgx/go.sum new file mode 100644 index 000000000..4526772d9 --- /dev/null +++ b/module/apmpgx/go.sum @@ -0,0 +1,281 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= +github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= +github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/elastic/go-licenser v0.4.0 h1:jLq6A5SilDS/Iz1ABRkO6BHy91B9jBora8FwGRsDqUI= +github.com/elastic/go-licenser v0.4.0/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU= +github.com/elastic/go-sysinfo v1.7.1 h1:Wx4DSARcKLllpKT2TnFVdSUJOsybqMYCNQZq1/wO+s0= +github.com/elastic/go-sysinfo v1.7.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0= +github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU= +github.com/elastic/go-windows v1.0.1 h1:AlYZOldA+UJ0/2nBuqWdo90GFCgG9xuyw9SYzGUtJm0= +github.com/elastic/go-windows v1.0.1/go.mod h1:FoVvqWSun28vaDQPbj2Elfc0JahhPB7WQEGa3c814Ss= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= +github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0= +github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= +github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= +github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA= +github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= +github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s= +github.com/jackc/pgconn v1.4.0/go.mod h1:Y2O3ZDF0q4mMacyWV3AstPJpeHXWGEetiFttmq5lahk= +github.com/jackc/pgconn v1.5.0/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI= +github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI= +github.com/jackc/pgconn v1.7.0/go.mod h1:sF/lPpNEMEOp+IYhyQGdAvrG20gWf6A1tKlr0v7JMeA= +github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o= +github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY= +github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= +github.com/jackc/pgconn v1.13.0 h1:3L1XMNV2Zvca/8BYhzcRFS70Lr0WlDg16Di6SFGAbys= +github.com/jackc/pgconn v1.13.0/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI= +github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= +github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= +github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= +github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c= +github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65 h1:DadwsjnMwFjfWc9y5Wi/+Zz7xoE5ALHsRQlOctkOiHc= +github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A= +github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78= +github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA= +github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg= +github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= +github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= +github.com/jackc/pgproto3/v2 v2.0.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.0.5/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.3.1 h1:nwj7qwf0S+Q7ISFfBndqeLwSwxs+4DPsbRFjECT1Y4Y= +github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= +github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg= +github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= +github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= +github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= +github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= +github.com/jackc/pgtype v1.2.0/go.mod h1:5m2OfMh1wTK7x+Fk952IDmI4nw3nPrvtQdM0ZT4WpC0= +github.com/jackc/pgtype v1.3.1-0.20200510190516-8cd94a14c75a/go.mod h1:vaogEUkALtxZMCH411K+tKzNpwzCKU+AnPzBKZ+I+Po= +github.com/jackc/pgtype v1.3.1-0.20200606141011-f6355165a91c/go.mod h1:cvk9Bgu/VzJ9/lxTO5R5sf80p0DiucVtN7ZxvaC4GmQ= +github.com/jackc/pgtype v1.5.0/go.mod h1:JCULISAZBFGrHaOXIIFiyfzW5VY0GRitRr8NeJsrdig= +github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM= +github.com/jackc/pgtype v1.12.0 h1:Dlq8Qvcch7kiehm8wPGIW0W3KsCCHJnRacKW0UM8n5w= +github.com/jackc/pgtype v1.12.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y= +github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM= +github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc= +github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXgo+kA= +github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o= +github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg= +github.com/jackc/pgx/v4 v4.9.0/go.mod h1:MNGWmViCgqbZck9ujOOBN63gK9XVGILXWCvKLGKmnms= +github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= +github.com/jackc/pgx/v4 v4.17.0 h1:Hsx+baY8/zU2WtPLQyZi8WbecgcsWEeyoK1jvg/WgIo= +github.com/jackc/pgx/v4 v4.17.0/go.mod h1:Gd6RmOhtFLTu8cp/Fhq4kP195KrshxYJH3oW8AWJ1pw= +github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.1.2/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jcchavezs/porto v0.1.0 h1:Xmxxn25zQMmgE7/yHYmh19KcItG81hIwfbEEFnd6w/Q= +github.com/jcchavezs/porto v0.1.0/go.mod h1:fESH0gzDHiutHRdX2hv27ojnOVFco37hg1W6E9EZF4A= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8= +github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= +github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= +github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= +github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= +github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= +github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +go.elastic.co/fastjson v1.1.0 h1:3MrGBWWVIxe/xvsbpghtkFoPciPhOCmjsR/HfwEeQR4= +go.elastic.co/fastjson v1.1.0/go.mod h1:boNGISWMjQsUPy/t6yqt2/1Wx4YNPSe+mZjlyw9vKKI= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= +golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= +golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= +golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8= +golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= +golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= +gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= +howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM= +howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= diff --git a/module/apmpgx/tracer.go b/module/apmpgx/tracer.go new file mode 100644 index 000000000..32316d520 --- /dev/null +++ b/module/apmpgx/tracer.go @@ -0,0 +1,201 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package apmpgx // import "go.elastic.co/apm/module/apmpgx/v2" + +import ( + "context" + "errors" + "fmt" + "strings" + "time" + + "go.elastic.co/apm/module/apmsql/v2" + "go.elastic.co/apm/v2" + + "github.com/jackc/pgx/v4" +) + +const ( + //querySpanType is setting action for query expression trace in APM server. + querySpanType = "db.postgresql.query" + + //querySpanType is setting action for copy expression trace in APM server. + copySpanType = "db.postgresql.copy" + + //querySpanType is setting action for batch expression trace in APM server. + batchSpanType = "db.postgresql.batch" +) + +var ( + // ErrUnsupportedPgxVersion is indicating that data doesn't contain value for "time" key. This field appeared in pgx v4.17 + ErrUnsupportedPgxVersion = errors.New("this version of pgx is unsupported, please upgrade to v4.17+") + + // ErrInvalidType is indicating that field type doesn't meet expected one + ErrInvalidType = errors.New("invalid field type") +) + +// tracer struct contains pgx.ConnConfig inside and pgx.Logger implementation. +type tracer struct { + // cfg is the pgx.ConnConfig which used for setting metadata in spans such as host, port, etc. + cfg *pgx.ConnConfig + + // logger used for writing data to log. If it's nil, then data won't be written to log, and only spans will be created. + logger pgx.Logger +} + +// Instrument is getting pgx.ConnConfig and wrap logger into tracer. +// It's safe to pass nil logger into pgx.ConnConfig, if so, then only spans will be created +func Instrument(cfg *pgx.ConnConfig) { + cfg.Logger = &tracer{ + cfg: cfg, + logger: cfg.Logger, + } +} + +// Log is getting type of SQL expression from msg and run suitable trace. +// If logger in tracer struct isn't nil, than log will be +// written to your logger that implements pgx.Logger interface. +func (t *tracer) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{}) { + if t.logger != nil { + t.logger.Log(ctx, level, msg, data) + } + + switch msg { + case "Query", "Exec": + t.QueryTrace(ctx, data) + case "CopyFrom": + t.CopyTrace(ctx, data) + case "SendBatch": + t.BatchTrace(ctx, data) + } +} + +// QueryTrace traces query and creates spans for them. +func (t *tracer) QueryTrace(ctx context.Context, data map[string]interface{}) { + statement, ok := data["sql"].(string) + if !ok { + apm.CaptureError(ctx, + fmt.Errorf("%w: expect string, got: %T", + ErrInvalidType, + data["sql"], + ), + ).Send() + return + } + + span, ok := t.startSpan(ctx, apmsql.QuerySignature(statement), querySpanType, statement, data) + if !ok { + return + } + defer span.End() +} + +// CopyTrace traces copy queries and creates spans for them. +func (t *tracer) CopyTrace(ctx context.Context, data map[string]interface{}) { + tableName, ok := data["tableName"].(pgx.Identifier) + if !ok { + return + } + + var columnNames []string + + switch data["columnNames"].(type) { + case pgx.Identifier: + columnNames = data["columnNames"].(pgx.Identifier) + case []string: + columnNames = data["columnNames"].([]string) + default: + return + } + + statement := fmt.Sprintf("COPY TO %s(%s)", + strings.Join(tableName, ", "), + strings.Join(columnNames, ", "), + ) + + span, ok := t.startSpan(ctx, + fmt.Sprintf("COPY TO %s", strings.Join(tableName, ", ")), + copySpanType, + statement, + data, + ) + if !ok { + return + } + defer span.End() +} + +// BatchTrace traces batch execution and creates spans for the whole batch. +func (t *tracer) BatchTrace(ctx context.Context, data map[string]interface{}) { + span, ok := t.startSpan(ctx, "BATCH", batchSpanType, "", data) + if !ok { + return + } + defer span.End() + + if batchLen, ok := data["batchLen"].(int); ok { + span.Context.SetLabel("batch.length", batchLen) + } +} + +func (t *tracer) startSpan(ctx context.Context, spanName, spanType, statement string, data map[string]interface{}) (*apm.Span, bool) { + stop := time.Now() + + duration, ok := data["time"].(time.Duration) + if !ok { + apm.CaptureError(ctx, ErrUnsupportedPgxVersion).Send() + return nil, false + } + + span, _ := apm.StartSpanOptions(ctx, spanName, spanType, apm.SpanOptions{ + Start: stop.Add(-duration), + ExitSpan: true, + }) + + if span.Dropped() { + span.End() + return nil, false + } + + span.Duration = duration + span.Context.SetDatabase(apm.DatabaseSpanContext{ + Instance: t.cfg.Database, + Statement: statement, + Type: "sql", + User: t.cfg.User, + }) + + span.Context.SetDestinationAddress(t.cfg.Host, int(t.cfg.Port)) + span.Context.SetServiceTarget(apm.ServiceTargetSpanContext{ + Type: "postgresql", + Name: t.cfg.Database, + }) + span.Context.SetDestinationService(apm.DestinationServiceSpanContext{ + Name: "postgresql", + Resource: "postgresql", + }) + + if err, ok := data["err"].(error); ok { + e := apm.CaptureError(ctx, err) + e.Timestamp = stop + e.SetSpan(span) + e.Send() + } + + return span, true +} diff --git a/module/apmpgx/tracer_test.go b/module/apmpgx/tracer_test.go new file mode 100644 index 000000000..cd724d265 --- /dev/null +++ b/module/apmpgx/tracer_test.go @@ -0,0 +1,277 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package apmpgx_test + +import ( + "context" + "errors" + "testing" + "time" + + "github.com/jackc/pgx/v4" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "go.elastic.co/apm/module/apmpgx/v2" + "go.elastic.co/apm/v2/apmtest" +) + +type testLogger struct{} + +func (t *testLogger) Log(_ context.Context, _ pgx.LogLevel, _ string, _ map[string]interface{}) {} + +func TestLog(t *testing.T) { + testcases := []struct { + name, msg string + logger pgx.Logger + }{ + { + name: "QUERY trace", + msg: "Query", + logger: nil, + }, + { + name: "EXEC trace", + msg: "Exec", + logger: nil, + }, + { + name: "COPY FROM trace", + msg: "CopyFrom", + logger: nil, + }, + { + name: "logger test", + msg: "Query", + logger: &testLogger{}, + }, + } + + for _, test := range testcases { + test := test + + t.Run(test.name, func(t *testing.T) { + t.Parallel() + + cfg := &pgx.ConnConfig{ + Logger: nil, + } + + apmpgx.Instrument(cfg) + + cfg.Logger.Log(context.TODO(), pgx.LogLevelNone, test.msg, nil) + }) + } +} + +func TestQueryTrace(t *testing.T) { + cfg := &pgx.ConnConfig{ + Logger: nil, + } + + apmpgx.Instrument(cfg) + + testcases := []struct { + name string + expectErr bool + data map[string]interface{} + }{ + { + name: "QUERY span, no error", + expectErr: false, + data: map[string]interface{}{ + "time": 3 * time.Millisecond, + "sql": "SELECT * FROM foo.bar", + }, + }, + { + name: "QUERY span, empty data", + expectErr: true, + data: nil, + }, + { + name: "QUERY span, error in data object", + expectErr: true, + data: map[string]interface{}{ + "time": 3 * time.Millisecond, + "sql": "SELECT * FROM foo.bar", + "err": errors.New("test error"), + }, + }, + } + + for _, test := range testcases { + test := test + + t.Run(test.name, func(t *testing.T) { + t.Parallel() + + _, spans, errs := apmtest.WithTransaction(func(ctx context.Context) { + cfg.Logger.Log(ctx, pgx.LogLevelNone, "Query", test.data) + }) + + if test.expectErr { + require.Len(t, errs, 1) + } else { + assert.Equal(t, "db", spans[0].Type) + assert.Equal(t, "postgresql", spans[0].Subtype) + assert.Equal(t, "query", spans[0].Action) + assert.Equal(t, "SELECT FROM foo.bar", spans[0].Name) + assert.Equal(t, "SELECT * FROM foo.bar", spans[0].Context.Database.Statement) + + assert.Equal(t, 0, len(spans[0].Stacktrace)) + + require.Len(t, errs, 0) + } + }) + } +} + +func TestCopyTrace(t *testing.T) { + cfg := &pgx.ConnConfig{ + Logger: nil, + } + + apmpgx.Instrument(cfg) + + testcases := []struct { + name string + expectErr bool + data map[string]interface{} + }{ + { + name: "COPY span, no error", + expectErr: false, + data: map[string]interface{}{ + "time": 3 * time.Millisecond, + "tableName": pgx.Identifier{"foo"}, + "columnNames": pgx.Identifier{"id,name,age"}, + }, + }, + { + name: "COPY span, empty data", + expectErr: true, + data: nil, + }, + { + name: "COPY span, error in data object", + expectErr: true, + data: map[string]interface{}{ + "time": 3 * time.Millisecond, + "tableName": pgx.Identifier{"foo"}, + "columnNames": pgx.Identifier{"id,name,age"}, + "err": errors.New("test error"), + }, + }, + } + + for _, test := range testcases { + test := test + + t.Run(test.name, func(t *testing.T) { + t.Parallel() + + _, spans, errs := apmtest.WithTransaction(func(ctx context.Context) { + cfg.Logger.Log(ctx, pgx.LogLevelNone, "CopyFrom", test.data) + }) + + if test.expectErr && test.data != nil { + require.Len(t, errs, 1) + } + + if !test.expectErr { + assert.Equal(t, "db", spans[0].Type) + assert.Equal(t, "postgresql", spans[0].Subtype) + assert.Equal(t, "copy", spans[0].Action) + assert.Equal(t, "COPY TO foo", spans[0].Name) + + assert.Equal(t, len(spans[0].Stacktrace), 0) + + require.Len(t, errs, 0) + } + }) + } +} + +func TestBatchTrace(t *testing.T) { + cfg := &pgx.ConnConfig{ + Logger: nil, + } + + apmpgx.Instrument(cfg) + + testcases := []struct { + name string + expectErr bool + data map[string]interface{} + }{ + { + name: "BATCH span, no error", + expectErr: false, + data: map[string]interface{}{ + "time": 3 * time.Millisecond, + "batchLen": 5, + }, + }, + { + name: "BATCH span, no batch len", + expectErr: false, + data: map[string]interface{}{ + "time": 3 * time.Millisecond, + }, + }, + { + name: "BATCH span, error in data object", + expectErr: true, + data: map[string]interface{}{ + "time": 3 * time.Millisecond, + "batchLen": 5, + "err": errors.New("test error"), + }, + }, + } + + for _, test := range testcases { + test := test + + t.Run(test.name, func(t *testing.T) { + t.Parallel() + + _, spans, errs := apmtest.WithTransaction(func(ctx context.Context) { + cfg.Logger.Log(ctx, pgx.LogLevelNone, "SendBatch", test.data) + }) + + if test.expectErr { + require.Len(t, errs, 1) + } else { + assert.Equal(t, "db", spans[0].Type) + assert.Equal(t, "postgresql", spans[0].Subtype) + assert.Equal(t, "batch", spans[0].Action) + assert.Equal(t, "BATCH", spans[0].Name) + + assert.Equal(t, len(spans[0].Stacktrace), 0) + + if len(spans[0].Context.Tags) > 0 { + assert.Equal(t, float64(5), spans[0].Context.Tags[0].Value) + } + + require.Len(t, errs, 0) + } + }) + } +} diff --git a/scripts/Dockerfile-testing b/scripts/Dockerfile-testing index 3ae752dea..828ace3a5 100644 --- a/scripts/Dockerfile-testing +++ b/scripts/Dockerfile-testing @@ -35,6 +35,7 @@ COPY module/apmlogrus/go.mod module/apmlogrus/go.sum /go/src/go.elastic.co/apm/m COPY module/apmmongo/go.mod module/apmmongo/go.sum /go/src/go.elastic.co/apm/module/apmmongo/ COPY module/apmnegroni/go.mod module/apmnegroni/go.sum /go/src/go.elastic.co/apm/module/apmnegroni/ COPY module/apmot/go.mod module/apmot/go.sum /go/src/go.elastic.co/apm/module/apmot/ +COPY module/apmpgx/go.mod module/apmpgx/go.sum /go/src/go.elastic.co/apm/module/apmpgx/ COPY module/apmprometheus/go.mod module/apmprometheus/go.sum /go/src/go.elastic.co/apm/module/apmprometheus/ COPY module/apmredigo/go.mod module/apmredigo/go.sum /go/src/go.elastic.co/apm/module/apmredigo/ COPY module/apmrestful/go.mod module/apmrestful/go.sum /go/src/go.elastic.co/apm/module/apmrestful/ @@ -77,6 +78,7 @@ RUN cd /go/src/go.elastic.co/apm/module/apmlogrus && go mod download RUN cd /go/src/go.elastic.co/apm/module/apmmongo && go mod download RUN cd /go/src/go.elastic.co/apm/module/apmnegroni && go mod download RUN cd /go/src/go.elastic.co/apm/module/apmot && go mod download +RUN cd /go/src/go.elastic.co/apm/module/apmpgx && go mod download RUN cd /go/src/go.elastic.co/apm/module/apmprometheus && go mod download RUN cd /go/src/go.elastic.co/apm/module/apmredigo && go mod download RUN cd /go/src/go.elastic.co/apm/module/apmrestful && go mod download