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>
(cherry picked from commit 093dd57a78)
This commit is contained in:
Tim Möhlmann
2024-04-03 11:48:24 +03:00
committed by Livio Spring
parent 7a34697267
commit 7ef95c9194
5 changed files with 16 additions and 0 deletions

View File

@@ -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")
}