Use otelgrpc for tracing grpc server and client (#15237)

* Use otelgrpc for tracing grpc server and client.

* Changelog fragment

* gofmt

* Use context in prometheus service

* Remove async start of prometheus service

* Use random port to reduce the probability of concurrent tests using the same port

* Remove comment

* fix lint error

---------

Co-authored-by: Bastin <bastin.m@proton.me>
This commit is contained in:
Preston Van Loon
2025-05-05 13:46:33 -05:00
committed by GitHub
parent 6df476835c
commit 97a95dddfc
14 changed files with 113 additions and 93 deletions

View File

@@ -84,7 +84,7 @@ go_library(
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//plugin/ocgrpc:go_default_library",
"@io_opentelemetry_go_contrib_instrumentation_google_golang_org_grpc_otelgrpc//:go_default_library",
"@io_opentelemetry_go_contrib_instrumentation_net_http_otelhttp//:go_default_library",
"@io_opentelemetry_go_otel_trace//:go_default_library",
"@org_golang_google_grpc//:go_default_library",

View File

@@ -32,7 +32,7 @@ import (
grpcopentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/pkg/errors"
"go.opencensus.io/plugin/ocgrpc"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
@@ -314,7 +314,7 @@ func ConstructDialOptions(
grpcretry.WithMax(grpcRetries),
grpcretry.WithBackoff(grpcretry.BackoffLinear(grpcRetryDelay)),
),
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
grpc.WithUnaryInterceptor(middleware.ChainUnaryClient(
grpcopentracing.UnaryClientInterceptor(),
grpcprometheus.UnaryClientInterceptor,

View File

@@ -376,6 +376,7 @@ func (c *ValidatorClient) registerPrometheusService(cliCtx *cli.Context) error {
return nil
}
service := prometheus.NewService(
cliCtx.Context,
fmt.Sprintf("%s:%d", cliCtx.String(cmd.MonitoringHostFlag.Name), cliCtx.Int(flags.MonitoringPortFlag.Name)),
c.services,
)