2023-10-17 01:48:50 +03:00
|
|
|
package tracer_test
|
2023-10-17 01:00:00 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"go.unistack.org/micro/v4/logger"
|
2023-10-17 01:48:50 +03:00
|
|
|
"go.unistack.org/micro/v4/logger/slog"
|
|
|
|
"go.unistack.org/micro/v4/tracer"
|
2023-10-17 01:00:00 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoggerWithTracer(t *testing.T) {
|
|
|
|
ctx := context.TODO()
|
|
|
|
buf := bytes.NewBuffer(nil)
|
2023-10-17 01:48:50 +03:00
|
|
|
logger.DefaultLogger = slog.NewLogger(logger.WithOutput(buf))
|
|
|
|
|
|
|
|
if err := logger.Init(); err != nil {
|
2023-10-17 01:00:00 +03:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2023-10-17 01:48:50 +03:00
|
|
|
var span tracer.Span
|
|
|
|
ctx, span = tracer.DefaultTracer.Start(ctx, "test")
|
2023-10-17 01:00:00 +03:00
|
|
|
logger.Info(ctx, "msg")
|
|
|
|
if !strings.Contains(buf.String(), span.TraceID()) {
|
|
|
|
t.Fatalf("log does not contains tracer id")
|
|
|
|
}
|
|
|
|
}
|