start reworking exporters to be more composable
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"git.ma-al.com/gora_filip/pkg/level"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/semconv/v1.25.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type IntoTraceAttribute interface {
|
||||
@ -19,6 +20,27 @@ type IntoTraceAttributes interface {
|
||||
IntoTraceAttributes() []attribute.KeyValue
|
||||
}
|
||||
|
||||
func CollectAttributes(attrs ...interface{}) []attribute.KeyValue {
|
||||
collected := make([]attribute.KeyValue, len(attrs))
|
||||
for _, a := range attrs {
|
||||
switch a.(type) {
|
||||
case []attribute.KeyValue:
|
||||
collected = append(collected, a.([]attribute.KeyValue)...)
|
||||
case attribute.KeyValue:
|
||||
collected = append(collected, a.(attribute.KeyValue))
|
||||
case IntoTraceAttribute:
|
||||
collected = append(collected, a.(IntoTraceAttribute).IntoTraceAttribute())
|
||||
case IntoTraceAttributes:
|
||||
collected = append(collected, a.(IntoTraceAttributes).IntoTraceAttributes()...)
|
||||
}
|
||||
}
|
||||
return collected
|
||||
}
|
||||
|
||||
func WithAttributes(attrs ...interface{}) trace.SpanStartEventOption {
|
||||
return trace.WithAttributes(CollectAttributes(attrs...)...)
|
||||
}
|
||||
|
||||
const (
|
||||
SeverityLevelKey = attribute.Key("level")
|
||||
LogMessageLongKey = attribute.Key("log_message.long")
|
||||
|
Reference in New Issue
Block a user