Add OpenTelemetry tracing and log correlation

This commit is contained in:
2026-09-17 14:56:57 +03:30
parent 3445ead897
commit f7366a1985
9 changed files with 187 additions and 40 deletions
+2 -1
View File
@@ -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)
+3 -1
View File
@@ -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)