fix(contrib/database/sql): detect lib/pq and disable DBM-APM link on COPY
What does this PR do?
Detects lib/pq usage to avoid inserting SQLCommenter comments for DBM-APM link.
Additionally, does small refactors done in the scope to simplify code.
Upstream PR for fixing the root cause in lib/pq: https://github.com/lib/pq/pull/1198
Motivation
Avoid COPY statements breaking like:
error: sql: expected 0 arguments, got N
Reviewer's Checklist
- [ ] Changed code has unit tests for its functionality at or near 100% coverage.
- [ ] System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
- [ ] There is a benchmark for any new code, or changes to existing code.
- [ ] If this interacts with the agent in a new way, a system test has been added.
- [ ] New code is free of linting errors. You can check this by running
./scripts/lint.shlocally. - [ ] Add an appropriate team label so this PR gets put in the right place for the release notes.
- [ ] Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.
Unsure? Have a question? Request a review!
Benchmarks
Benchmark execution time: 2025-08-13 10:19:59
Comparing candidate commit 5fadd4a236ad0bf7a549cb3b51fd2fd9d9bd9872 in PR branch dario.castane/langplat-726/avoid-dbm-apm-link-on-libpq-copy with baseline commit 66aa2ddd8dfa16e63a41729fcd8e6acf49a095f3 in branch main.
Found 0 performance improvements and 0 performance regressions! Performance is the same for 24 metrics, 0 unstable metrics.
⚠️ Warnings
🧪 2 Tests failed
TestPostgresfromgithub.com/DataDog/dd-trace-go/contrib/database/sql/v2(Datadog)Failed === RUN TestPostgres --- FAIL: TestPostgres (0.00s)
TestPostgres/Queryfromgithub.com/DataDog/dd-trace-go/contrib/database/sql/v2(Datadog)Failed === RUN TestPostgres/Query sql.go:124: Error Trace: /home/runner/work/dd-trace-go/dd-trace-go/instrumentation/testutils/sql/sql.go:124 Error: Expected nil, but got: &pq.Error{Severity:"ERROR", Code:"42P01", Message:"relation \"testsql\" does not exist", Detail:"", Hint:"", Position:"148", InternalPosition:"", InternalQuery:"", Where:"", Schema:"", Table:"", Column:"", DataTypeName:"", Constraint:"", File:"parse_relation.c", Line:"1449", Routine:"parserOpenTable"} Test: TestPostgres/Query sql.go:302: Error Trace: /home/runner/work/dd-trace-go/dd-trace-go/instrumentation/testutils/sql/sql.go:302 /home/runner/work/dd-trace-go/dd-trace-go/instrumentation/testutils/sql/sql.go:145 ...
ℹ️ Info
❄️ No new flaky tests detected
This comment will be updated automatically if new data arrives.🔗 Commit SHA: 5fadd4a | Docs | Was this helpful? Give us feedback!