33 lines
818 B
Go
33 lines
818 B
Go
|
package tracer
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"maal/tracer/pkg/level"
|
||
|
|
||
|
"go.opentelemetry.io/otel/attribute"
|
||
|
"go.opentelemetry.io/otel/codes"
|
||
|
"go.opentelemetry.io/otel/trace"
|
||
|
)
|
||
|
|
||
|
func LongMessage(message string) attribute.KeyValue {
|
||
|
return attribute.KeyValue{Key: "long_message_", Value: attribute.StringValue(message)}
|
||
|
}
|
||
|
|
||
|
func Level(level level.SyslogLevel) attribute.KeyValue {
|
||
|
return attribute.KeyValue{Key: "level_", Value: attribute.Int64Value(int64(level))}
|
||
|
}
|
||
|
|
||
|
func JsonAttr(key string, jsonEl map[string]interface{}) attribute.KeyValue {
|
||
|
|
||
|
jsonStr, _ := json.Marshal(jsonEl)
|
||
|
return attribute.KeyValue{Key: attribute.Key(key), Value: attribute.StringValue(string(jsonStr))}
|
||
|
|
||
|
}
|
||
|
|
||
|
func RecordError(span trace.Span, err error) error {
|
||
|
span.SetStatus(codes.Error, err.Error())
|
||
|
span.RecordError(err)
|
||
|
|
||
|
return nil
|
||
|
}
|