Add OpenTelemetry tracing and log correlation
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
ledgerv1 "gl/gen/ledger/v1"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/reflection"
|
||||
@@ -34,7 +35,7 @@ func Run(ctx context.Context, cfg ServerConfig, handler ledgerv1.GeneralLedgerSe
|
||||
func runWithListener(ctx context.Context, shutdownTimeout time.Duration, listener net.Listener, handler ledgerv1.GeneralLedgerServiceServer) error {
|
||||
defer listener.Close()
|
||||
|
||||
server := grpc.NewServer(grpc.ChainUnaryInterceptor(structuredUnaryLogger(), panicRecovery()))
|
||||
server := grpc.NewServer(grpc.StatsHandler(otelgrpc.NewServerHandler()), grpc.ChainUnaryInterceptor(structuredUnaryLogger(), panicRecovery()))
|
||||
ledgerv1.RegisterGeneralLedgerServiceServer(server, handler)
|
||||
reflection.Register(server)
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
@@ -18,7 +20,7 @@ type ServerConfig struct {
|
||||
func Run(ctx context.Context, cfg ServerConfig, handler http.Handler) error {
|
||||
server := &http.Server{
|
||||
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
|
||||
Handler: handler,
|
||||
Handler: otelhttp.NewHandler(handler, "gl-dashboard"),
|
||||
ReadHeaderTimeout: cfg.ReadHeaderTimeout,
|
||||
}
|
||||
serveErr := make(chan error, 1)
|
||||
|
||||
Reference in New Issue
Block a user