On error save SQL request parameters to span.
This commit is contained in:
parent
5801184782
commit
174f52d948
26
save.go
26
save.go
|
@ -104,6 +104,18 @@ func SaveRow(ctx context.Context, db *db.DBC, dataItem meta.IMetaStruct) error {
|
||||||
sqlSmt = sqlSmt[0:200]
|
sqlSmt = sqlSmt[0:200]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.SetAttributes(
|
||||||
|
attribute.Int("sql_param_amount", len(params)),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Convert SQL request parameters to slice of strings.
|
||||||
|
paramStrs := convertInterfacesToStrings(ctx, params)
|
||||||
|
if len(paramStrs) > 0 {
|
||||||
|
span.SetAttributes(
|
||||||
|
attribute.StringSlice("sql_params", paramStrs),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
resultErr := errors.Errorf("Can not execute SaveRow. Got error from updateBuilder.ExecContext. %s (%s)", err.Error(), sqlSmt)
|
resultErr := errors.Errorf("Can not execute SaveRow. Got error from updateBuilder.ExecContext. %s (%s)", err.Error(), sqlSmt)
|
||||||
span.RecordError(resultErr)
|
span.RecordError(resultErr)
|
||||||
span.SetStatus(codes.Error, resultErr.Error())
|
span.SetStatus(codes.Error, resultErr.Error())
|
||||||
|
@ -118,6 +130,20 @@ func SaveRow(ctx context.Context, db *db.DBC, dataItem meta.IMetaStruct) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertInterfacesToStrings(ctx context.Context, items []interface{}) []string {
|
||||||
|
itemAmount := len(items)
|
||||||
|
if itemAmount == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
strs := make([]string, itemAmount)
|
||||||
|
for i, item := range items {
|
||||||
|
strs[i] = fmt.Sprint(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
return strs
|
||||||
|
}
|
||||||
|
|
||||||
func SaveMetaRootStruct(
|
func SaveMetaRootStruct(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
db *db.DBC,
|
db *db.DBC,
|
||||||
|
|
Loading…
Reference in New Issue