refactor(tracing): fixed minor issues & added debug flag
This commit is contained in:
parent
5ffb558ab8
commit
bd76f838ec
@ -29,10 +29,16 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Connect(ctx context.Context, config models.DatabaseConfig) error {
|
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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "Connect")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"endpoint": config.Endpoint,
|
"endpoint": config.Endpoint,
|
||||||
"port": config.Port,
|
"port": config.Port,
|
||||||
"database": config.Database,
|
"database": config.Database,
|
||||||
@ -64,8 +70,6 @@ func Connect(ctx context.Context, config models.DatabaseConfig) error {
|
|||||||
return utils.HandleError(ctx, span, localLogger, err)
|
return utils.HandleError(ctx, span, localLogger, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTelemetry()
|
|
||||||
|
|
||||||
client = sqlDB
|
client = sqlDB
|
||||||
utils.HandleEvent(span, localLogger, "Database connected successfully")
|
utils.HandleEvent(span, localLogger, "Database connected successfully")
|
||||||
return nil
|
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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "migrateDatabase")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"database": config.Database,
|
"database": config.Database,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -100,9 +104,9 @@ func migrateDatabase(ctx context.Context, dbPool *gorm.DB, config models.Databas
|
|||||||
|
|
||||||
if config.Debug {
|
if config.Debug {
|
||||||
if n != 0 {
|
if n != 0 {
|
||||||
localLogger.Infof("postgres migration: applied %d migrations!", n)
|
localLogger.Debug("applied %d migrations!", n)
|
||||||
} else {
|
} else {
|
||||||
localLogger.Info("postgres migration: nothing to migrate")
|
localLogger.Debug("nothing to migrate")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func CreateUserFavorite(ctx context.Context, userFav models.UserFavorite) (model
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUserFavorite")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUserFavorite")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_favorite_id": userFav.ID,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUserFavoriteInBatch")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_favorite_count": len(userFav),
|
"user_favorite_count": len(userFav),
|
||||||
"batch_size": batchSize,
|
"batch_size": batchSize,
|
||||||
})
|
})
|
||||||
@ -86,7 +86,7 @@ func UpdateUserFavorite(ctx context.Context, userFav models.UserFavorite) error
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdateUserFavorite")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdateUserFavorite")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_favorite_id": userFav.ID,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetUserFavoritesByID")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_favorite_id": id,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUserFavorite")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_favorite_id": id,
|
"user_favorite_id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func CreatePost(ctx context.Context, post models.Post) (models.Post, error) {
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreatePost")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreatePost")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"post_id": post.ID,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreatePostInBatch")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"post_count": len(post),
|
"post_count": len(post),
|
||||||
"batch_size": batchSize,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetPostByID")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"post_id": id,
|
"post_id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ func UpdatePost(ctx context.Context, anthrovePost models.Post) error {
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdatePost")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdatePost")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"post_id": anthrovePost.ID,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeletePost")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"post_id": id,
|
"post_id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func CreateSource(ctx context.Context, source models.Source) (models.Source, err
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateSource")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateSource")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"source_id": source.ID,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateSourceInBatch")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"source_count": len(source),
|
"source_count": len(source),
|
||||||
"batch_size": batchSize,
|
"batch_size": batchSize,
|
||||||
})
|
})
|
||||||
@ -86,7 +86,7 @@ func UpdateSource(ctx context.Context, source models.Source) error {
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdateSource")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdateSource")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"source_id": source.ID,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetSourceByID")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"source_id": id,
|
"source_id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ func GetSourceByDomain(ctx context.Context, sourceDomain models.SourceDomain) (m
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetSourceByDomain")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetSourceByDomain")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"source_domain": sourceDomain,
|
"source_domain": sourceDomain,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ func DeleteSource(ctx context.Context, id models.SourceID) error {
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteSource")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteSource")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"source_id": id,
|
"source_id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagTy
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTag")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTag")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_name": tagName,
|
"tag_name": tagName,
|
||||||
"tag_type": tagType,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagInBatch")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_count": len(tags),
|
"tag_count": len(tags),
|
||||||
"batch_size": batchSize,
|
"batch_size": batchSize,
|
||||||
})
|
})
|
||||||
@ -93,7 +93,7 @@ func DeleteTag(ctx context.Context, tagName models.TagName) error {
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTag")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTag")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_name": tagName,
|
"tag_name": tagName,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagNa
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAlias")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAlias")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_alias_name": tagAliasName,
|
"tag_alias_name": tagAliasName,
|
||||||
"tag_name": tagName,
|
"tag_name": tagName,
|
||||||
})
|
})
|
||||||
@ -53,7 +53,7 @@ func CreateTagAliasInBatch(ctx context.Context, tagsAliases []models.TagAlias, b
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAliasInBatch")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAliasInBatch")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_aliases_count": len(tagsAliases),
|
"tag_aliases_count": len(tagsAliases),
|
||||||
"batch_size": batchSize,
|
"batch_size": batchSize,
|
||||||
})
|
})
|
||||||
@ -93,7 +93,7 @@ func DeleteTagAlias(ctx context.Context, tagAliasName models.TagAliasName) error
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTagAlias")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteTagAlias")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_alias_name": tagAliasName,
|
"tag_alias_name": tagAliasName,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ func CreateTagGroup(ctx context.Context, tagGroupName models.TagGroupName, tagNa
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagGroup")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagGroup")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_group_name": tagGroupName,
|
"tag_group_name": tagGroupName,
|
||||||
"tag_name": tagName,
|
"tag_name": tagName,
|
||||||
})
|
})
|
||||||
@ -54,7 +54,7 @@ func CreateTagGroupInBatch(ctx context.Context, tagsGroups []models.TagGroup, ba
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAliasInBatch")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateTagAliasInBatch")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_groups_count": len(tagsGroups),
|
"tag_groups_count": len(tagsGroups),
|
||||||
"batch_size": batchSize,
|
"batch_size": batchSize,
|
||||||
})
|
})
|
||||||
@ -100,7 +100,7 @@ func DeleteTagGroup(ctx context.Context, tagGroupName models.TagGroupName) error
|
|||||||
attribute.String("tag_group_name", string(tagGroupName)),
|
attribute.String("tag_group_name", string(tagGroupName)),
|
||||||
)
|
)
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"tag_group_name": tagGroupName,
|
"tag_group_name": tagGroupName,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ func CreateUser(ctx context.Context, user models.User) (models.User, error) {
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUser")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUser")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_id": user.ID,
|
"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)),
|
attribute.String("user_id", string(id)),
|
||||||
)
|
)
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_id": id,
|
"user_id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ func DeleteUser(ctx context.Context, id models.UserID) error {
|
|||||||
attribute.String("user_id", string(id)),
|
attribute.String("user_id", string(id)),
|
||||||
)
|
)
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_id": id,
|
"user_id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func CreateUserSource(ctx context.Context, userSource models.UserSource) (models
|
|||||||
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUserSource")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "CreateUserSource")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_source_id": userSource.ID,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "UpdateUserSource")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_source_id": userSource.ID,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "GetUserSourceByID")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_source_id": id,
|
"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")
|
ctx, span, localLogger := utils.SetupTracing(ctx, tracer, "DeleteUserSource")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
localLogger.WithFields(log.Fields{
|
localLogger = localLogger.WithFields(log.Fields{
|
||||||
"user_source_id": id,
|
"user_source_id": id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user