Skip to content

Commit

Permalink
fix: remove unneeded deps (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma committed Sep 1, 2023
1 parent 347ce16 commit 573d655
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
12 changes: 9 additions & 3 deletions ctx/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,15 @@ func Interface(k string, v interface{}) logger.Field {
}
}

// TraceID returns a open telemetry trace ID context field.
func TraceID(k string, span trace.Span) logger.Field {
if !span.IsRecording() {
// Span represents an open telemetry span.
type Span interface {
IsRecording() bool
SpanContext() trace.SpanContext
}

// TraceID returns an open telemetry trace ID context field.
func TraceID(k string, span Span) logger.Field {
if !span.IsRecording() || !span.SpanContext().HasTraceID() {
return func(*logger.Event) {}
}
return func(e *logger.Event) {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ go 1.16
require (
github.com/go-stack/stack v1.8.1
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.17.0
go.opentelemetry.io/otel/trace v1.17.0
)
19 changes: 6 additions & 13 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/hamba/logger/v2/ctx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -231,7 +229,7 @@ func TestLogger_Stack(t *testing.T) {

log.Info("some message", ctx.Stack("stack"))

want := `lvl=info msg="some message" stack=[github.com/hamba/logger/logger/logger_test.go:232]` + "\n"
want := `lvl=info msg="some message" stack=[github.com/hamba/logger/logger/logger_test.go:230]` + "\n"
assert.Equal(t, want, buf.String())
}

Expand Down Expand Up @@ -265,19 +263,14 @@ type fakeSpan struct {
ID byte
}

func (s *fakeSpan) End(...trace.SpanEndOption) {}
func (s *fakeSpan) AddEvent(string, ...trace.EventOption) {}
func (s *fakeSpan) IsRecording() bool { return s.Recording }
func (s *fakeSpan) RecordError(error, ...trace.EventOption) {}
func (s *fakeSpan) SetStatus(codes.Code, string) {}
func (s *fakeSpan) SetName(string) {}
func (s *fakeSpan) SetAttributes(...attribute.KeyValue) {}
func (s *fakeSpan) TracerProvider() trace.TracerProvider { return nil }
func (s *fakeSpan) IsRecording() bool {
return s.Recording
}

func (s *fakeSpan) SpanContext() trace.SpanContext {
return trace.NewSpanContext(trace.SpanContextConfig{
TraceID: trace.TraceID([16]byte{1}),
SpanID: trace.SpanID([8]byte{s.ID}),
TraceID: [16]byte{1},
SpanID: [8]byte{s.ID},
Remote: false,
})
}

0 comments on commit 573d655

Please sign in to comment.