Logging
gRPC server
By passing in grpc.ServerOption
, Kratos will print detailed request information every time a gRPC request is received.
gRPC client
logger := log.DefaultLogger
var opts = []http.ServerOption{
http.Middleware(
logging.Server(logger),
),
}
HTTP client
By passing logging.Client()
in http.WithMiddleware
, Kratos will print detailed request information every time an Http request is initiated.
grpc-server
// internal/server/grpc.go
exporter, err := stdouttrace.New(stdouttrace.WithWriter(ioutil.Discard))
if err != nil {
fmt.Printf("creating stdout exporter: %v", err)
panic(err)
}
tp := tracesdk.NewTracerProvider(
tracesdk.WithBatcher(exporter),
tracesdk.WithResource(resource.NewSchemaless(
)
var opts = []grpc.ServerOption{
grpc.Middleware(
tracing.Server(tracing.WithTracerProvider(tp)),
),
}
srv := grpc.NewServer(opts...)
Add the trace_id
field to the output log
log.WithContext(ctx).Errorf("Field created: %s", err)