chore(tracing): Update log field names for clarity

This commit is contained in:
SoXX 2024-08-12 09:57:31 +02:00
parent c17b78cc48
commit 6bec8e3373

View File

@ -3,6 +3,7 @@ package database
import ( import (
"context" "context"
"errors" "errors"
"git.anthrove.art/Anthrove/otter-space-sdk/v2/internal/utils" "git.anthrove.art/Anthrove/otter-space-sdk/v2/internal/utils"
otterError "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/error" otterError "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/error"
"git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models" "git.anthrove.art/Anthrove/otter-space-sdk/v2/pkg/models"
@ -32,8 +33,8 @@ func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagTy
} }
logger.WithContext(ctx).WithFields(log.Fields{ logger.WithContext(ctx).WithFields(log.Fields{
"name": tagName, "tag_name": tagName,
"type": tagType, "tag_type": tagType,
}).Debug("attempting to create tag") }).Debug("attempting to create tag")
result := client.WithContext(ctx).Create(&tag) result := client.WithContext(ctx).Create(&tag)
@ -41,22 +42,22 @@ func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagTy
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
loggerFields := log.Fields{ loggerFields := log.Fields{
"name": tagName, "tag_name": tagName,
"type": tagType, "tag_type": tagType,
} }
return models.Tag{}, utils.HandleError(ctx, span, logger, loggerFields, &otterError.Database{Reason: otterError.DuplicateKey}) return models.Tag{}, utils.HandleError(ctx, span, logger, loggerFields, &otterError.Database{Reason: otterError.DuplicateKey})
} }
loggerFields := log.Fields{ loggerFields := log.Fields{
"name": tagName, "tag_name": tagName,
"type": tagType, "tag_type": tagType,
} }
return models.Tag{}, utils.HandleError(ctx, span, logger, loggerFields, result.Error) return models.Tag{}, utils.HandleError(ctx, span, logger, loggerFields, result.Error)
} }
logger.WithContext(ctx).WithFields(log.Fields{ logger.WithContext(ctx).WithFields(log.Fields{
"name": tagName, "tag_name": tagName,
"type": tagType, "tag_type": tagType,
}).Debug("tag created") }).Debug("tag created")
span.AddEvent("Tag created successfully") span.AddEvent("Tag created successfully")
return tag, nil return tag, nil