Skip to content

Commit

Permalink
chore: Rename tracing fields
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Stasyszyn <[email protected]>
  • Loading branch information
bstasyszyn committed Feb 24, 2023
1 parent 31384d3 commit 2d526fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions pkg/log/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const (
FieldTopic = "topic"
FieldTxID = "txID"
FieldURL = "url"
FieldTraceID = "traceID"
FieldSpanID = "spanID"
FieldParentSpanID = "parentSpanID"
FieldTraceID = "trace_id"
FieldSpanID = "span_id"
FieldParentSpanID = "parent_span_id"
)

// WithError sets the error field.
Expand Down
6 changes: 3 additions & 3 deletions pkg/log/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ type logData struct {
Logger string `json:"logger"`
Caller string `json:"caller"`
Error string `json:"error"`
TraceID string `json:"traceID"`
SpanID string `json:"spanID"`
ParentSpanID string `json:"parentSpanID"`
TraceID string `json:"trace_id"`
SpanID string `json:"span_id"`
ParentSpanID string `json:"parent_span_id"`

HTTPStatus int `json:"httpStatus"`
ID string `json:"id"`
Expand Down
22 changes: 13 additions & 9 deletions pkg/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,24 @@ func TestContextLogger(t *testing.T) {

logger := New(module, WithStdOut(stdOut), WithStdErr(stdErr))

ctx, span := tracer.Start(context.Background(), "parent-span")
defer span.End()
ctx1, span1 := tracer.Start(context.Background(), "span1")
defer span1.End()

logger.Debugc(ctx, "Sample debug log")
logger.Infoc(ctx, "Sample info log")
logger.Warnc(ctx, "Sample warn log")
logger.Errorc(ctx, "Sample error log")
ctx2, span2 := tracer.Start(ctx1, "span2")
defer span2.End()

logger.Debugc(ctx2, "Sample debug log")
logger.Infoc(ctx2, "Sample info log")
logger.Warnc(ctx2, "Sample warn log")
logger.Errorc(ctx2, "Sample error log")

require.Panics(t, func() {
logger.Panicc(ctx, "Sample panic log")
logger.Panicc(ctx2, "Sample panic log")
})

require.Contains(t, stdOut.Buffer.String(), "traceID")
require.Contains(t, stdOut.Buffer.String(), "spanID")
require.Contains(t, stdOut.Buffer.String(), "trace_id")
require.Contains(t, stdOut.Buffer.String(), "span_id")
require.Contains(t, stdOut.Buffer.String(), "parent_span_id")
})
}

Expand Down

0 comments on commit 2d526fc

Please sign in to comment.