zjh129 commented on code in PR #209:
URL: https://github.com/apache/skywalking-go/pull/209#discussion_r1804043179
##########
plugins/gozero/zrpc/server_middleware_intercepter.go:
##########
@@ -0,0 +1,56 @@
+package zrpc
+
+import (
+ "context"
+ "github.com/apache/skywalking-go/plugins/core/operator"
+ "github.com/apache/skywalking-go/plugins/core/tracing"
+ "github.com/zeromicro/go-zero/zrpc"
+ "google.golang.org/grpc"
+)
+
+type ServerMiddlewareInterceptor struct {
+}
+
+// BeforeInvoke intercepts the HTTP request before invoking the handler.
+func (h *ServerMiddlewareInterceptor) BeforeInvoke(invocation
operator.Invocation) error {
+ server := invocation.CallerInstance().(*zrpc.RpcServer)
+ server.AddUnaryInterceptors(RpcServeInterceptor(invocation))
+ return nil
+}
+
+// AfterInvoke processes after the HTTP request has been handled.
+func (h *ServerMiddlewareInterceptor) AfterInvoke(invocation
operator.Invocation, result ...interface{}) error {
+ return nil
+}
+
+// RpcServeInterceptor is a grpc server interceptor that creates a new span
for each incoming request.
+var RpcServeInterceptor = func(invocation operator.Invocation)
grpc.UnaryServerInterceptor {
+ return func(ctx context.Context, req any, info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler) (resp any, err error) {
+ s, err := tracing.CreateLocalSpan(info.FullMethod,
+ tracing.WithLayer(tracing.SpanLayerRPCFramework),
+ tracing.WithTag(tracing.TagURL, info.FullMethod),
+ tracing.WithComponent(5023),
+ )
+ if err != nil {
+ return nil, err
+ }
+ defer s.End()
+
+ resp, err = handler(ctx, req)
+ if err != nil {
+ s.Error(err.Error())
+ }
+ // collect request and response data
+ if config.CollectRequestParameters {
+ //TODO: collect request data
Review Comment:
The interceptor is currently unable to use packages other than enhanced
objects, so we will remove the functionality for collecting request parameters
and response data and will submit a PR once support is available in the future.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]