SDK v3 #8

Merged
SoXX merged 77 commits from dev/issue-5 into main 2024-08-14 13:27:35 +00:00
9 changed files with 42 additions and 38 deletions
Showing only changes of commit bd76f838ec - Show all commits

View File

@ -29,10 +29,16 @@ var (
)
func Connect(ctx context.Context, config models.DatabaseConfig) error {
setupTelemetry()
if config.Debug {
log.SetLevel(log.DebugLevel)
}
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "Connect")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"endpoint": config.Endpoint,
"port": config.Port,
"database": config.Database,
@ -64,8 +70,6 @@ func Connect(ctx context.Context, config models.DatabaseConfig) error {
return utils.HandleError(ctx, span, localLogger, err)
}
setupTelemetry()
client = sqlDB
utils.HandleEvent(span, localLogger, "Database connected successfully")
return nil
@ -75,7 +79,7 @@ func migrateDatabase(ctx context.Context, dbPool *gorm.DB, config models.Databas
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "migrateDatabase")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"database": config.Database,
})
@ -100,9 +104,9 @@ func migrateDatabase(ctx context.Context, dbPool *gorm.DB, config models.Databas
if config.Debug {
if n != 0 {
localLogger.Infof("postgres migration: applied %d migrations!", n)
localLogger.Debug("applied %d migrations!", n)
} else {
localLogger.Info("postgres migration: nothing to migrate")
localLogger.Debug("nothing to migrate")
}
}

View File

@ -16,7 +16,7 @@ func CreateUserFavorite(ctx context.Context, userFav models.UserFavorite) (model
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUserFavorite")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_favorite_id": userFav.ID,
})
@ -46,7 +46,7 @@ func CreateUserFavoriteInBatch(ctx context.Context, userFav []models.UserFavorit
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUserFavoriteInBatch")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_favorite_count": len(userFav),
"batch_size": batchSize,
})
@ -86,7 +86,7 @@ func UpdateUserFavorite(ctx context.Context, userFav models.UserFavorite) error
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdateUserFavorite")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_favorite_id": userFav.ID,
})
@ -124,7 +124,7 @@ func GetUserFavoritesByID(ctx context.Context, id models.UserFavoriteID) (models
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetUserFavoritesByID")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_favorite_id": id,
})
@ -160,7 +160,7 @@ func DeleteUserFavorite(ctx context.Context, id models.UserFavoriteID) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUserFavorite")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_favorite_id": id,
})

View File

@ -16,7 +16,7 @@ func CreatePost(ctx context.Context, post models.Post) (models.Post, error) {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreatePost")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"post_id": post.ID,
})
@ -46,7 +46,7 @@ func CreatePostInBatch(ctx context.Context, post []models.Post, batchSize int) e
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreatePostInBatch")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"post_count": len(post),
"batch_size": batchSize,
})
@ -86,7 +86,7 @@ func GetPostByID(ctx context.Context, id models.PostID) (models.Post, error) {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetPostByID")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"post_id": id,
})
@ -122,7 +122,7 @@ func UpdatePost(ctx context.Context, anthrovePost models.Post) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdatePost")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"post_id": anthrovePost.ID,
})
@ -162,7 +162,7 @@ func DeletePost(ctx context.Context, id models.PostID) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePost")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"post_id": id,
})

View File

@ -16,7 +16,7 @@ func CreateSource(ctx context.Context, source models.Source) (models.Source, err
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateSource")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"source_id": source.ID,
})
@ -46,7 +46,7 @@ func CreateSourceInBatch(ctx context.Context, source []models.Source, batchSize
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateSourceInBatch")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"source_count": len(source),
"batch_size": batchSize,
})
@ -86,7 +86,7 @@ func UpdateSource(ctx context.Context, source models.Source) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdateSource")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"source_id": source.ID,
})
@ -126,7 +126,7 @@ func GetSourceByID(ctx context.Context, id models.SourceID) (models.Source, erro
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetSourceByID")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"source_id": id,
})
@ -166,7 +166,7 @@ func GetSourceByDomain(ctx context.Context, sourceDomain models.SourceDomain) (m
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetSourceByDomain")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"source_domain": sourceDomain,
})
@ -202,7 +202,7 @@ func DeleteSource(ctx context.Context, id models.SourceID) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteSource")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"source_id": id,
})

View File

@ -16,7 +16,7 @@ func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagTy
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTag")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_name": tagName,
"tag_type": tagType,
})
@ -53,7 +53,7 @@ func CreateTagInBatch(ctx context.Context, tags []models.Tag, batchSize int) err
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagInBatch")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_count": len(tags),
"batch_size": batchSize,
})
@ -93,7 +93,7 @@ func DeleteTag(ctx context.Context, tagName models.TagName) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTag")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_name": tagName,
})

View File

@ -16,7 +16,7 @@ func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagNa
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAlias")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_alias_name": tagAliasName,
"tag_name": tagName,
})
@ -53,7 +53,7 @@ func CreateTagAliasInBatch(ctx context.Context, tagsAliases []models.TagAlias, b
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAliasInBatch")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_aliases_count": len(tagsAliases),
"batch_size": batchSize,
})
@ -93,7 +93,7 @@ func DeleteTagAlias(ctx context.Context, tagAliasName models.TagAliasName) error
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTagAlias")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_alias_name": tagAliasName,
})

View File

@ -17,7 +17,7 @@ func CreateTagGroup(ctx context.Context, tagGroupName models.TagGroupName, tagNa
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagGroup")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_group_name": tagGroupName,
"tag_name": tagName,
})
@ -54,7 +54,7 @@ func CreateTagGroupInBatch(ctx context.Context, tagsGroups []models.TagGroup, ba
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAliasInBatch")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_groups_count": len(tagsGroups),
"batch_size": batchSize,
})
@ -100,7 +100,7 @@ func DeleteTagGroup(ctx context.Context, tagGroupName models.TagGroupName) error
attribute.String("tag_group_name", string(tagGroupName)),
)
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"tag_group_name": tagGroupName,
})

View File

@ -17,7 +17,7 @@ func CreateUser(ctx context.Context, user models.User) (models.User, error) {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUser")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_id": user.ID,
})
@ -51,7 +51,7 @@ func GetUserByID(ctx context.Context, id models.UserID) (models.User, error) {
attribute.String("user_id", string(id)),
)
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_id": id,
})
@ -83,7 +83,7 @@ func DeleteUser(ctx context.Context, id models.UserID) error {
attribute.String("user_id", string(id)),
)
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_id": id,
})

View File

@ -16,7 +16,7 @@ func CreateUserSource(ctx context.Context, userSource models.UserSource) (models
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUserSource")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_source_id": userSource.ID,
})
@ -46,7 +46,7 @@ func UpdateUserSource(ctx context.Context, userSource models.UserSource) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdateUserSource")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_source_id": userSource.ID,
})
@ -91,7 +91,7 @@ func GetUserSourceByID(ctx context.Context, id models.UserSourceID) (models.User
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetUserSourceByID")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_source_id": id,
})
@ -130,7 +130,7 @@ func DeleteUserSource(ctx context.Context, id models.UserSourceID) error {
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUserSource")
defer span.End()
localLogger.WithFields(log.Fields{
localLogger = localLogger.WithFields(log.Fields{
"user_source_id": id,
})