diff --git a/internal/xattribute/xattribute.go b/internal/xattribute/xattribute.go index dbad1468..c265d93e 100644 --- a/internal/xattribute/xattribute.go +++ b/internal/xattribute/xattribute.go @@ -4,6 +4,7 @@ package xattribute import ( "fmt" "slices" + "time" "go.opentelemetry.io/otel/attribute" ) @@ -51,3 +52,14 @@ func StringMap(k string, m map[string]string) attribute.KeyValue { return attribute.StringSlice(k, ss.val) } + +// UnixNano returns [time.Time] as unix nano timestamp. +// +// If value is zero, timestamp would be zero too. +func UnixNano(k string, t time.Time) attribute.KeyValue { + var v int64 + if !t.IsZero() { + v = t.UnixNano() + } + return attribute.Int64(k, v) +}