master
Kevin Wan 3 years ago committed by GitHub
parent 6fd08027ff
commit 7618139dad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,7 +5,6 @@ import (
"github.com/tal-tech/go-zero/core/logx"
"github.com/tal-tech/go-zero/core/syncx"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/propagation"

@ -4,7 +4,6 @@ import (
"net/http"
"github.com/tal-tech/go-zero/core/opentelemetry"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"

@ -8,9 +8,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/tal-tech/go-zero/core/opentelemetry"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)

@ -6,10 +6,9 @@ import (
"path/filepath"
"testing"
"github.com/tal-tech/go-zero/tools/goctl/model/sql/gen"
"github.com/stretchr/testify/assert"
"github.com/tal-tech/go-zero/tools/goctl/config"
"github.com/tal-tech/go-zero/tools/goctl/model/sql/gen"
"github.com/tal-tech/go-zero/tools/goctl/util"
)

@ -4,12 +4,11 @@ import (
"context"
"github.com/tal-tech/go-zero/core/opentelemetry"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc"
grpc_codes "google.golang.org/grpc/codes"
gcodes "google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
@ -23,7 +22,6 @@ func OpenTracingInterceptor() grpc.UnaryClientInterceptor {
requestMetadata, _ := metadata.FromOutgoingContext(ctx)
metadataCopy := requestMetadata.Copy()
tr := otel.Tracer(opentelemetry.TraceName)
name, attr := opentelemetry.SpanInfo(method, cc.Target())
@ -37,22 +35,18 @@ func OpenTracingInterceptor() grpc.UnaryClientInterceptor {
opentelemetry.Inject(ctx, propagator, &metadataCopy)
ctx = metadata.NewOutgoingContext(ctx, metadataCopy)
opentelemetry.MessageSent.Event(ctx, 1, req)
err := invoker(ctx, method, req, reply, cc, opts...)
opentelemetry.MessageReceived.Event(ctx, 1, reply)
if err != nil {
if err := invoker(ctx, method, req, reply, cc, opts...); err != nil {
s, _ := status.FromError(err)
span.SetStatus(codes.Error, s.Message())
span.SetAttributes(opentelemetry.StatusCodeAttr(s.Code()))
} else {
span.SetAttributes(opentelemetry.StatusCodeAttr(grpc_codes.OK))
return err
}
return err
span.SetAttributes(opentelemetry.StatusCodeAttr(gcodes.OK))
return nil
}
}
@ -98,7 +92,7 @@ func StreamOpenTracingInterceptor() grpc.StreamClientInterceptor {
span.SetStatus(codes.Error, s.Message())
span.SetAttributes(opentelemetry.StatusCodeAttr(s.Code()))
} else {
span.SetAttributes(opentelemetry.StatusCodeAttr(grpc_codes.OK))
span.SetAttributes(opentelemetry.StatusCodeAttr(gcodes.OK))
}
span.End()

@ -4,20 +4,20 @@ import (
"context"
"github.com/tal-tech/go-zero/core/opentelemetry"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc"
grpc_codes "google.golang.org/grpc/codes"
gcodes "google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)
func UnaryOpenTracingInterceptor() grpc.UnaryServerInterceptor {
propagator := otel.GetTextMapPropagator()
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler) (interface{}, error) {
if !opentelemetry.Enabled() {
return handler(ctx, req)
}
@ -41,20 +41,19 @@ func UnaryOpenTracingInterceptor() grpc.UnaryServerInterceptor {
defer span.End()
opentelemetry.MessageReceived.Event(ctx, 1, req)
resp, err := handler(ctx, req)
if err != nil {
s, _ := status.FromError(err)
span.SetStatus(codes.Error, s.Message())
span.SetAttributes(opentelemetry.StatusCodeAttr(s.Code()))
opentelemetry.MessageSent.Event(ctx, 1, s.Proto())
} else {
span.SetAttributes(opentelemetry.StatusCodeAttr(grpc_codes.OK))
opentelemetry.MessageSent.Event(ctx, 1, resp)
return nil, err
}
return resp, err
span.SetAttributes(opentelemetry.StatusCodeAttr(gcodes.OK))
opentelemetry.MessageSent.Event(ctx, 1, resp)
return resp, nil
}
}
@ -89,7 +88,7 @@ func StreamOpenTracingInterceptor() grpc.StreamServerInterceptor {
span.SetStatus(codes.Error, s.Message())
span.SetAttributes(opentelemetry.StatusCodeAttr(s.Code()))
} else {
span.SetAttributes(opentelemetry.StatusCodeAttr(grpc_codes.OK))
span.SetAttributes(opentelemetry.StatusCodeAttr(gcodes.OK))
}
return err

Loading…
Cancel
Save