mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-06 13:57:41 +00:00
fix(db): wrap BeginTx in spans to get acquire metrics (#7689)
feat(db): wrap BeginTx in spans to get acquire metrics This changes adds a span around most db.BeginTx calls so we can get tracings about the connection pool acquire process. This might help us pinpoint why sometimes some query package traces show longer execution times, while this was not reflected on database side execution times. Co-authored-by: Silvan <silvan.reusser@gmail.com>
This commit is contained in:
parent
e4e8361f66
commit
093dd57a78
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
z_db "github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
@ -113,7 +114,9 @@ func (d *Database) CreateKeys(ctx context.Context, keys ...*crypto.Key) error {
|
||||
if err != nil {
|
||||
return zerrors.ThrowInternal(err, "", "unable to insert new keys")
|
||||
}
|
||||
ctx, spanBeginTx := tracing.NewNamedSpan(ctx, "db.BeginTx")
|
||||
tx, err := d.client.BeginTx(ctx, nil)
|
||||
spanBeginTx.EndWithError(err)
|
||||
if err != nil {
|
||||
return zerrors.ThrowInternal(err, "", "unable to insert new keys")
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
_ "github.com/zitadel/zitadel/internal/database/cockroach"
|
||||
"github.com/zitadel/zitadel/internal/database/dialect"
|
||||
_ "github.com/zitadel/zitadel/internal/database/postgres"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
@ -38,7 +39,9 @@ func (db *DB) Query(scan func(*sql.Rows) error, query string, args ...any) error
|
||||
}
|
||||
|
||||
func (db *DB) QueryContext(ctx context.Context, scan func(rows *sql.Rows) error, query string, args ...any) (err error) {
|
||||
ctx, spanBeginTx := tracing.NewNamedSpan(ctx, "db.BeginTx")
|
||||
tx, err := db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
|
||||
spanBeginTx.EndWithError(err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -71,7 +74,9 @@ func (db *DB) QueryRow(scan func(*sql.Row) error, query string, args ...any) (er
|
||||
}
|
||||
|
||||
func (db *DB) QueryRowContext(ctx context.Context, scan func(row *sql.Row) error, query string, args ...any) (err error) {
|
||||
ctx, spanBeginTx := tracing.NewNamedSpan(ctx, "db.BeginTx")
|
||||
tx, err := db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
|
||||
spanBeginTx.EndWithError(err)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/migration"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/pseudo"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
)
|
||||
|
||||
type EventStore interface {
|
||||
@ -479,7 +480,9 @@ func (h *Handler) processEvents(ctx context.Context, config *triggerConfig) (add
|
||||
defer cancel()
|
||||
}
|
||||
|
||||
ctx, spanBeginTx := tracing.NewNamedSpan(ctx, "db.BeginTx")
|
||||
tx, err := h.client.BeginTx(txCtx, nil)
|
||||
spanBeginTx.EndWithError(err)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -15,11 +15,14 @@ import (
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func (es *Eventstore) Push(ctx context.Context, commands ...eventstore.Command) (events []eventstore.Event, err error) {
|
||||
ctx, spanBeginTx := tracing.NewNamedSpan(ctx, "db.BeginTx")
|
||||
tx, err := es.client.BeginTx(ctx, nil)
|
||||
spanBeginTx.EndWithError(err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -90,7 +90,9 @@ func (q *Queries) latestState(ctx context.Context, projections ...table) (state
|
||||
}
|
||||
|
||||
func (q *Queries) ClearCurrentSequence(ctx context.Context, projectionName string) (err error) {
|
||||
ctx, spanBeginTx := tracing.NewNamedSpan(ctx, "db.BeginTx")
|
||||
tx, err := q.client.BeginTx(ctx, nil)
|
||||
spanBeginTx.EndWithError(err)
|
||||
if err != nil {
|
||||
return zerrors.ThrowInternal(err, "QUERY-9iOpr", "Errors.RemoveFailed")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user