diff --git a/pkg/log/fields.go b/pkg/log/fields.go index 1b69a0d..271585d 100644 --- a/pkg/log/fields.go +++ b/pkg/log/fields.go @@ -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. diff --git a/pkg/log/fields_test.go b/pkg/log/fields_test.go index cafead4..4e21aa9 100644 --- a/pkg/log/fields_test.go +++ b/pkg/log/fields_test.go @@ -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"` diff --git a/pkg/log/logger_test.go b/pkg/log/logger_test.go index 821595c..db586e0 100644 --- a/pkg/log/logger_test.go +++ b/pkg/log/logger_test.go @@ -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") }) }