opentracinginterceptor_test.go 1005 B

123456789101112131415161718192021222324252627282930313233343536
  1. package serverinterceptors
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/tal-tech/go-zero/core/trace/opentelemetry"
  7. "google.golang.org/grpc"
  8. )
  9. func TestUnaryOpenTracingInterceptor_Disable(t *testing.T) {
  10. interceptor := UnaryOpenTracingInterceptor()
  11. _, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
  12. FullMethod: "/",
  13. }, func(ctx context.Context, req interface{}) (interface{}, error) {
  14. return nil, nil
  15. })
  16. assert.Nil(t, err)
  17. }
  18. func TestUnaryOpenTracingInterceptor_Enabled(t *testing.T) {
  19. opentelemetry.StartAgent(opentelemetry.Config{
  20. Name: "go-zero-test",
  21. Endpoint: "http://localhost:14268/api/traces",
  22. Batcher: "jaeger",
  23. Sampler: 1.0,
  24. })
  25. interceptor := UnaryOpenTracingInterceptor()
  26. _, err := interceptor(context.Background(), nil, &grpc.UnaryServerInfo{
  27. FullMethod: "/package.TestService.GetUser",
  28. }, func(ctx context.Context, req interface{}) (interface{}, error) {
  29. return nil, nil
  30. })
  31. assert.Nil(t, err)
  32. }