Skip to content

Commit

Permalink
✅ confirm to skip if there is nrseg:ignore in function/method document
Browse files Browse the repository at this point in the history
  • Loading branch information
budougumi0617 committed Jan 11, 2021
1 parent c77687f commit 7a82ecd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
1 change: 0 additions & 1 deletion process.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func Process(filename string, src []byte) ([]byte, error) {
ast.Inspect(f, func(n ast.Node) bool {
if fd, ok := n.(*ast.FuncDecl); ok {
if fd.Body != nil {
// TODO: no append if exist calling statement of newrelic.FromContext.
// TODO: skip if comment go:nrsegignore in function/method comment.
sn := genSegName(fd.Name.Name)
vn, t := parseParams(fd.Type)
Expand Down
57 changes: 56 additions & 1 deletion process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestProcess(t *testing.T) {
name, src, want string
}{
{
name: "basicProcess",
name: "BasicProcess",
src: `package main
import (
Expand Down Expand Up @@ -76,6 +76,61 @@ func SampleHandler(w http.ResponseWriter, req *http.Request) {
// comment 1
fmt.Fprintf(w, "Hello, %q", req.URL.Path)
}
`,
},
{
name: "SkipIfIgnoreComment",
src: `package main
import (
"context"
"fmt"
"net/http"
)
type S struct{}
func (s *S) SampleMethod(ctx context.Context) {
fmt.Println("Hello, playground")
}
// SampleFunc is sample function.
// nrseg:ignore it does not be needed to insert segment in this function.
func SampleFunc(ctx context.Context) {
fmt.Println("Hello, playground")
}
func SampleHandler(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Hello, %q", req.URL.Path)
}
`,
want: `package main
import (
"context"
"fmt"
"net/http"
"github.com/newrelic/go-agent/v3/newrelic"
)
type S struct{}
func (s *S) SampleMethod(ctx context.Context) {
defer newrelic.FromContext(ctx).StartSegment("sample_method").End()
fmt.Println("Hello, playground")
}
// SampleFunc is sample function.
// nrseg:ignore it does not be needed to insert segment in this function.
func SampleFunc(ctx context.Context) {
fmt.Println("Hello, playground")
}
func SampleHandler(w http.ResponseWriter, req *http.Request) {
defer newrelic.FromContext(req.Context()).StartSegment("sample_handler").End()
fmt.Fprintf(w, "Hello, %q", req.URL.Path)
}
`,
},
{
Expand Down

0 comments on commit 7a82ecd

Please sign in to comment.