wu-sheng commented on code in PR #209:
URL: https://github.com/apache/skywalking-go/pull/209#discussion_r1802756245
##########
plugins/gozero/rest/server_middleware_intercepter.go:
##########
@@ -0,0 +1,69 @@
+package rest
+
+import (
+ "fmt"
+ "github.com/apache/skywalking-go/plugins/core/operator"
+ "github.com/apache/skywalking-go/plugins/core/tracing"
+ "github.com/zeromicro/go-zero/rest"
+ "net/http"
+)
+
+type ServerMiddlewareInterceptor struct {
+}
+
+// skyWalking middleware
+var SkyWalkingMiddleware rest.Middleware = func(next http.HandlerFunc)
http.HandlerFunc {
+ return func(writer http.ResponseWriter, request *http.Request) {
+ s, err := tracing.CreateEntrySpan(fmt.Sprintf("%s:%s",
request.Method, request.URL.Path), func(headerKey string) (string, error) {
+ return request.Header.Get(headerKey), nil
+ }, tracing.WithLayer(tracing.SpanLayerHTTP),
+ tracing.WithTag(tracing.TagHTTPMethod, request.Method),
+ tracing.WithTag(tracing.TagURL,
request.Host+request.URL.Path),
+ tracing.WithComponent(5023))
+ if err != nil {
+ next(writer, request)
+ return
+ }
+
+ defer s.End()
+
+ // collect response data
+ if config.CollectRequestParameters {
+ switch request.Method {
+ case http.MethodGet:
+ if request.URL.RawQuery != "" {
+ s.Tag(tracing.TagHTTPParams,
request.URL.RawQuery)
+ }
+ case http.MethodPost, http.MethodPut, http.MethodPatch:
+ //TODO collect request body data
+ if request.Body != nil {
+ }
+ }
+ }
+
+ // collect response data
+ if config.CollectResponseData {
+ //TODO: collect response data
+ //s.Tag(tracing.TagHTTPResponse, "resp")
+ }
+
+ // set trace id to response header
+ if config.OutputTraceId {
+ writer.Header().Set("trace-id", s.TraceID())
Review Comment:
All header things should be consistent for all agents by following
https://skywalking.apache.org/docs/main/latest/en/api/x-process-propagation-headers-v3/
--
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]