fix(observabillity): propagate ctx to every log call and add resource to logging
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 5m5s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 5m36s

This commit was merged in pull request #187.
This commit is contained in:
2025-06-17 09:42:19 +02:00
parent ff3c7bdf52
commit 6c92206b3c
27 changed files with 288 additions and 266 deletions

View File

@@ -1,6 +1,7 @@
package db
import (
"context"
"database/sql"
"errors"
"log/slog"
@@ -12,24 +13,24 @@ var (
ErrAlreadyExists = errors.New("row already exists")
)
func TransformAndLogDbError(module string, r sql.Result, err error) error {
func TransformAndLogDbError(ctx context.Context, module string, r sql.Result, err error) error {
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return ErrNotFound
}
slog.Error("database sql", "module", module, "err", err)
slog.ErrorContext(ctx, "database sql", "module", module, "err", err)
return types.ErrInternal
}
if r != nil {
rows, err := r.RowsAffected()
if err != nil {
slog.Error("database rows affected", "module", module, "err", err)
slog.ErrorContext(ctx, "database rows affected", "module", module, "err", err)
return types.ErrInternal
}
if rows == 0 {
slog.Info("row not found", "module", module)
slog.InfoContext(ctx, "row not found", "module", module)
return ErrNotFound
}
}