Logs. Add code to change span status.

This commit is contained in:
Владислав Весельский 2024-03-05 13:03:57 +03:00
parent f588822664
commit aba3ad40a6
1 changed files with 5 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import (
"go.opentelemetry.io/otel" "go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0" semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
"go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace"
) )
@ -169,11 +170,15 @@ func SaveMetaRootStruct(
switch tfield.Kind() { switch tfield.Kind() {
case reflect.Slice: case reflect.Slice:
if err := SaveMetaCollection(ctx, db, dataItem.Field(i), ownerId, removedIds, deltaSave); err != nil { if err := SaveMetaCollection(ctx, db, dataItem.Field(i), ownerId, removedIds, deltaSave); err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return errors.WithMessagef(err, "Can not execute SaveMetaRootStruct. Got error from SaveMetaCollection. ownerId: %d.", ownerId) return errors.WithMessagef(err, "Can not execute SaveMetaRootStruct. Got error from SaveMetaCollection. ownerId: %d.", ownerId)
} }
break break
case reflect.Struct: case reflect.Struct:
if err := saveStruct(ctx, db, dataItem.Field(i), ownerId); err != nil { if err := saveStruct(ctx, db, dataItem.Field(i), ownerId); err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return errors.WithMessagef(err, "Can not execute SaveMetaRootStruct. Got error from saveStruct. ownerId: %d.", ownerId) return errors.WithMessagef(err, "Can not execute SaveMetaRootStruct. Got error from saveStruct. ownerId: %d.", ownerId)
} }
break break