mrproliu commented on code in PR #203:
URL: https://github.com/apache/skywalking-go/pull/203#discussion_r1764784755


##########
plugins/goframe/go.mod:
##########
@@ -0,0 +1,11 @@
+module github.com/apache/skywalking-go/plugins/goframe
+
+go 1.19
+
+require github.com/apache/skywalking-go/plugins/core 
v0.0.0-20240910044646-4f94a255c2d3

Review Comment:
   We have already use the `go work`, so this requirement should be deleted. 



##########
plugins/goframe/instrument.go:
##########
@@ -0,0 +1,46 @@
+package goframe
+
+import (
+       "embed"
+       "github.com/apache/skywalking-go/plugins/core/instrument"

Review Comment:
   I think the import would trigger the `lint` checker, please fix the format. 



##########
plugins/goframe/instrument.go:
##########
@@ -0,0 +1,46 @@
+package goframe

Review Comment:
   Please add the Apache License header. 



##########
plugins/goframe/net/ghttp/intercepter.go:
##########
@@ -0,0 +1,68 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package ghttp
+
+import (
+       "fmt"
+       "github.com/apache/skywalking-go/plugins/core/operator"
+       "github.com/apache/skywalking-go/plugins/core/tracing"
+       "net/http"
+)
+
+// GoFrameServerInterceptor is used to intercept and trace HTTP requests.
+type GoFrameServerInterceptor struct{}
+
+// BeforeInvoke intercepts the HTTP request before invoking the handler.
+func (h *GoFrameServerInterceptor) BeforeInvoke(invocation 
operator.Invocation) error {
+       request := invocation.Args()[1].(*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(5004))
+       if err != nil {
+               return err
+       }
+
+       s.Tag(tracing.TagHTTPParams, request.URL.RawQuery)
+
+       writer := invocation.Args()[0].(http.ResponseWriter)
+       invocation.ChangeArg(0, &writerWrapper{ResponseWriter: writer, 
statusCode: http.StatusOK})
+       invocation.SetContext(s)
+       return nil
+}
+
+// AfterInvoke processes after the HTTP request has been handled.
+func (h *GoFrameServerInterceptor) AfterInvoke(invocation operator.Invocation, 
result ...interface{}) error {
+       fmt.Printf("goframe 拦截请求前 AfterInvoke\n")

Review Comment:
   Please remove the Chinese. And the printf is not allowed, I would make the 
user more confuse about it. 



##########
plugins/goframe/net/ghttp/intercepter.go:
##########
@@ -0,0 +1,68 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package ghttp
+
+import (
+       "fmt"
+       "github.com/apache/skywalking-go/plugins/core/operator"

Review Comment:
   I think the import would trigger the lint checker, please fix the format.



##########
plugins/goframe/net/ghttp/intercepter.go:
##########
@@ -0,0 +1,68 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package ghttp
+
+import (
+       "fmt"
+       "github.com/apache/skywalking-go/plugins/core/operator"
+       "github.com/apache/skywalking-go/plugins/core/tracing"
+       "net/http"
+)
+
+// GoFrameServerInterceptor is used to intercept and trace HTTP requests.
+type GoFrameServerInterceptor struct{}
+
+// BeforeInvoke intercepts the HTTP request before invoking the handler.
+func (h *GoFrameServerInterceptor) BeforeInvoke(invocation 
operator.Invocation) error {
+       request := invocation.Args()[1].(*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(5004))

Review Comment:
   this framework is new, please add a [new library in the skywalking 
project](https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml)
 



-- 
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]

Reply via email to