Skip to content

Commit

Permalink
use value.Resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong committed Feb 25, 2024
1 parent 360a13a commit 2349cba
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions gcp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ import (
"strings"
)

const (
TraceKey = "trace-id"
SpanKey = "span-id"
TraceFlagsKey = "trace-flags"
)

// New creates a new Handler with the given Option(s).
// The handler formats records to match [GCP Cloud Logging JSON schema].
//
Expand Down Expand Up @@ -70,12 +76,6 @@ func New(opts ...Option) slog.Handler {
return handler
}

const (
TraceKey = "trace-id"
SpanKey = "span-id"
TraceFlagsKey = "trace-flags"
)

func replaceAttr(project string) func(groups []string, attr slog.Attr) slog.Attr { //nolint:cyclop,funlen
return func(groups []string, attr slog.Attr) slog.Attr {
if len(groups) > 0 {
Expand Down Expand Up @@ -137,14 +137,14 @@ func replaceAttr(project string) func(groups []string, attr slog.Attr) slog.Attr
if project != "" {
switch attr.Key {
case TraceKey:
return slog.String("logging.googleapis.com/trace", "projects/"+project+"/traces/"+attr.Value.String())
return slog.String("logging.googleapis.com/trace", "projects/"+project+"/traces/"+attr.Value.Resolve().String())
case SpanKey:
attr.Key = "logging.googleapis.com/spanId"

return attr
case TraceFlagsKey:
var sampled bool
flags, _ := hex.DecodeString(attr.Value.String())
flags, _ := hex.DecodeString(attr.Value.Resolve().String())
if len(flags) > 0 {
sampled = flags[0]&0x1 == 0x1 //nolint:gomnd
}
Expand All @@ -160,13 +160,14 @@ func replaceAttr(project string) func(groups []string, attr slog.Attr) slog.Attr
type (
logHandler struct {
handler slog.Handler
groups []group

contextProvider func(context.Context) (traceID [16]byte, spanID [8]byte, traceFlags byte)

service string
version string
callers func(error) []uintptr

groups []group
}
group struct {
name string
Expand Down

0 comments on commit 2349cba

Please sign in to comment.