Skip to content

Commit

Permalink
feat(xattribute): add unix timestamp attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jun 7, 2024
1 parent 9390fcc commit 567c14c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/xattribute/xattribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package xattribute
import (
"fmt"
"slices"
"time"

"go.opentelemetry.io/otel/attribute"
)
Expand Down Expand Up @@ -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)
}

0 comments on commit 567c14c

Please sign in to comment.