fix(query): print log line on secret generator error (#8424)

# Which Problems Are Solved

Log some details when a secret generator is not found.
This should help us debugging such issue.

# How the Problems Are Solved

When a secret generator by type query fails,
we log the generator type and instance id for which
the generator was requested.

# Additional Changes

- none

# Additional Context

- Related to https://github.com/zitadel/zitadel/issues/8379
- Also encountered in https://github.com/zitadel/zitadel/pull/8407
This commit is contained in:
Tim Möhlmann
2024-08-13 15:52:43 +03:00
committed by GitHub
parent 042c438813
commit fcda6580ff
3 changed files with 119 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
sq "github.com/Masterminds/squirrel"
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/api/call"
@@ -125,10 +126,11 @@ func (q *Queries) SecretGeneratorByType(ctx context.Context, generatorType domai
ctx, span := tracing.NewSpan(ctx)
defer func() { span.EndWithError(err) }()
instanceID := authz.GetInstance(ctx).InstanceID()
stmt, scan := prepareSecretGeneratorQuery(ctx, q.client)
query, args, err := stmt.Where(sq.Eq{
SecretGeneratorColumnGeneratorType.identifier(): generatorType,
SecretGeneratorColumnInstanceID.identifier(): authz.GetInstance(ctx).InstanceID(),
SecretGeneratorColumnInstanceID.identifier(): instanceID,
}).ToSql()
if err != nil {
return nil, zerrors.ThrowInternal(err, "QUERY-3k99f", "Errors.Query.SQLStatment")
@@ -138,6 +140,7 @@ func (q *Queries) SecretGeneratorByType(ctx context.Context, generatorType domai
generator, err = scan(row)
return err
}, query, args...)
logging.OnError(err).WithField("type", generatorType).WithField("instance_id", instanceID).Error("secret generator by type")
return generator, err
}