-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement module for pgx/v5 #1364
Conversation
…to make setting values safe in runtime
# Conflicts: # module/apmpgxv5/batch_tracer.go # module/apmpgxv5/batch_tracer_test.go
💔 Tests Failed
Expand to view the summary
Build stats
Test stats 🧪
Test errorsExpand to view the tests failures
|
} | ||
|
||
for _, tt := range testcases { | ||
t.Run(tt.name, func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do parallel tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps, I don't think it matters in practice, they should be pretty fast.
…ontext and replace it with start and end span functions
@axw hey, I think module is ready for review, please take a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gvencadze! I've left a handful of comments. Someone else may respond later, as I'll be on holidays for a couple of weeks 🎄
…ment in endSpan function with error type and wrap sql queries using apmsql.QuerySignature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks pretty good in general
} | ||
|
||
for _, tt := range testcases { | ||
t.Run(tt.name, func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps, I don't think it matters in practice, they should be pretty fast.
…nsaction, make batch start span non-exit and batch query span exit
…saction in connect, copy and query tests
var _ pgx.BatchTracer = (*BatchTracer)(nil) | ||
|
||
func (b BatchTracer) TraceBatchStart(ctx context.Context, conn *pgx.Conn, _ pgx.TraceBatchStartData) context.Context { | ||
span, spanCtx, ok := startSpan(ctx, apmsql.QuerySignature("BATCH"), batchSpanType, conn.Config(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move "BATCH" to consts?
@marclop re-review pls 🦊 |
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good, CI is failing due to a few unformatted files, missing headers, I'll commit those changes to the branch, so the CI passes.
Signed-off-by: Marc Lopez Rubio <[email protected]>
@marclop can you take a look why CI fail pls? I didn't find any error related to my code |
@gvencadze CI is failing for Go versions 1.15, 1.16, and 1.17. They all fail with this error:
Looking at the pgx main branch, it says it requires Go 1.18. I guess we'll need to add a |
…irement + set go version to 1.18 in go.mod file
hey @axw, I've added build tags and set go version in |
It's not ideal, but for now please set Please ensure The |
This reverts commit 2f655ea.
… 1.15 due to CI requirements
🌐 Coverage report
|
Thanks for your contribution @gvencadze! The macOS CI failure appears to be unrelated, so I'll merge this. |
Verified with APM Server (elastic/apm-server@4c1e156):
main.gopackage main
import (
"context"
"fmt"
"log"
"github.com/jackc/pgx/v5"
"go.elastic.co/apm/module/apmpgxv5/v2"
"go.elastic.co/apm/v2"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
cfg, err := pgx.ParseConfig("postgres://postgres:changeme@localhost:5432/testdb")
if err != nil {
return fmt.Errorf("failed to parse config: %w", err)
}
apmpgxv5.Instrument(cfg)
t := apm.DefaultTracer()
t.SetExitSpanMinDuration(0)
t.SetSpanCompressionEnabled(false)
tx := t.StartTransaction("t5", "manual")
defer apm.DefaultTracer().Flush(nil)
defer tx.End()
ctx := apm.ContextWithTransaction(context.Background(), tx)
conn, err := pgx.ConnectConfig(ctx, cfg)
if err != nil {
return fmt.Errorf("failed to connect config: %w", err)
}
defer func() {
if err := conn.Close(ctx); err != nil {
log.Fatal(fmt.Errorf("failed to close2: %w", err))
}
}()
if _, err := conn.Exec(ctx, "CREATE TABLE IF NOT EXISTS foo (bar INT)"); err != nil {
return fmt.Errorf("failed to create table: %w", err)
}
batch := &pgx.Batch{}
for _, query := range []string{
"SELECT * FROM foo WHERE bar = 1",
} {
batch.Queue(query)
}
br := conn.SendBatch(ctx, batch)
if err := br.Close(); err != nil {
return fmt.Errorf("failed to close: %w", err)
}
rows, err := conn.Query(ctx, "SELECT * FROM foo")
if err != nil {
return fmt.Errorf("failed to query: %w", err)
}
defer rows.Close()
return nil
} |
This module have some improvements that's was released with pgx/v5, such as detailed batch and connect traces
Closes: #1345
Batch example with connect trace: