From 76d9c694e6b7f8d6c9d3319ac4afa655cc0ba6f9 Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Fri, 22 Sep 2023 16:27:25 +0800 Subject: [PATCH] otelgrpc: Modify example to use grpc.StatsHandler (#4325) --- CHANGELOG.md | 4 ++++ .../google.golang.org/grpc/otelgrpc/example/client/main.go | 3 +-- .../google.golang.org/grpc/otelgrpc/example/server/main.go | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b149fa66d4..65a1ceafabc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Set the description for the `rpc.server.duration` metric in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#4302) - Add `NewServerHandler` and `NewClientHandler` that return a `grpc.StatsHandler` used for gRPC instrumentation in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc`. (#3002) +### Changed + +- Use `grpc.StatsHandler` for gRPC instrumentation in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/example`. (#4325) + ## [1.19.0/0.44.0/0.13.0] - 2023-09-12 ### Added diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go b/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go index 44963614ef5..5ef1227c62f 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go @@ -44,8 +44,7 @@ func main() { var conn *grpc.ClientConn conn, err = grpc.Dial(":7777", grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor()), - grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor()), + grpc.WithStatsHandler(otelgrpc.NewClientHandler()), ) if err != nil { diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go b/instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go index f64266d98e5..000c1a78bb4 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go @@ -140,8 +140,7 @@ func main() { } s := grpc.NewServer( - grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor()), - grpc.StreamInterceptor(otelgrpc.StreamServerInterceptor()), + grpc.StatsHandler(otelgrpc.NewServerHandler()), ) api.RegisterHelloServiceServer(s, &server{})