Skip to content

Commit

Permalink
feat(otel): add ctx logger
Browse files Browse the repository at this point in the history
  • Loading branch information
bradub committed Jun 14, 2024
1 parent bdf94f3 commit e97bdd2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion otel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/purposeinplay/go-commons/otel
go 1.22

require (
github.com/purposeinplay/go-commons/grpc v0.0.26
github.com/purposeinplay/go-commons/grpc v0.0.27
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.52.0
go.opentelemetry.io/otel v1.27.0
Expand Down
4 changes: 2 additions & 2 deletions otel/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions otel/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/test/bufconn"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
)

func TestTracer(t *testing.T) {
Expand Down Expand Up @@ -130,17 +131,23 @@ func TestIntegration(t *testing.T) {
}
})

logger, err := zap.NewDevelopment()
req.NoError(err)

greeterClient1 := greetpb.NewGreetServiceClient(conn1)

grpcServer2, err := commonsgrpc.NewServer(
commonsgrpc.WithGRPCListener(lis2),
commonsgrpc.WithDebug(zap.NewExample(), true),
commonsgrpc.WithOTEL(),
commonsgrpc.WithUnaryServerInterceptorLogger(logger),
commonsgrpc.WithRegisterServerFunc(func(server *grpc.Server) {
greetpb.RegisterGreetServiceServer(server, &greeterService{
greetFunc: func(ctx context.Context, req *greetpb.GreetRequest) (*greetpb.GreetResponse, error) {
t.Log("greet func server 2")

ctxzap.Info(ctx, "zap log")

return greeterClient1.Greet(ctx, req)
},
})
Expand Down

0 comments on commit e97bdd2

Please sign in to comment.