Skip to content

Commit

Permalink
Use instrumentors for func names
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Aug 24, 2023
1 parent 246ca29 commit be26938
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 37 deletions.
54 changes: 30 additions & 24 deletions internal/tools/docgen/libs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ import (
"github.com/hashicorp/go-version"
"go.opentelemetry.io/auto/offsets-tracker/utils"
"go.opentelemetry.io/auto/offsets-tracker/versions"
"go.opentelemetry.io/auto/pkg/instrumentors"
"golang.org/x/mod/semver"

"go.opentelemetry.io/auto/pkg/instrumentors/bpf/database/sql"
"go.opentelemetry.io/auto/pkg/instrumentors/bpf/github.com/gin-gonic/gin"
"go.opentelemetry.io/auto/pkg/instrumentors/bpf/github.com/gorilla/mux"
"go.opentelemetry.io/auto/pkg/instrumentors/bpf/google/golang/org/grpc"
grpcserver "go.opentelemetry.io/auto/pkg/instrumentors/bpf/google/golang/org/grpc/server"
httpclient "go.opentelemetry.io/auto/pkg/instrumentors/bpf/net/http/client"
httpserver "go.opentelemetry.io/auto/pkg/instrumentors/bpf/net/http/server"
)

// Packages are the instrumented packages and the versions supported.
var Packages []Package

type Package struct {
Expand Down Expand Up @@ -73,9 +83,9 @@ var (
PkgGoURL: "https://pkg.go.dev/net/http",

src: "templates/net/http/*.tmpl",
instFn: []string{
"net/http.HandlerFunc.ServeHTTP",
"net/http.(*Client).do",
instrs: []instrumentors.Instrumentor{
httpclient.New(),
httpserver.New(),
},
verFunc: func() ([]string, error) { return goVersions, nil },
},
Expand All @@ -84,12 +94,9 @@ var (
PkgGoURL: "https://pkg.go.dev/google.golang.org/grpc",

src: "templates/google.golang.org/grpc/*.tmpl",
instFn: []string{
"google.golang.org/grpc.(*ClientConn).Invoke",
"google.golang.org/grpc/internal/transport.(*http2Client).NewStream",
"google.golang.org/grpc/internal/transport.(*loopyWriter).headerHandler",
"google.golang.org/grpc.(*Server).handleStream",
"google.golang.org/grpc/internal/transport.(*http2Server).operateHeaders",
instrs: []instrumentors.Instrumentor{
grpc.New(),
grpcserver.New(),
},
verFunc: func() ([]string, error) {
return versions.FindVersionsUsingGoList("google.golang.org/grpc")
Expand All @@ -99,10 +106,8 @@ var (
Name: "github.com/gin-gonic/gin",
PkgGoURL: "https://pkg.go.dev/github.com/gin-gonic/gin",

src: "templates/github.com/gin-gonic/gin/*.tmpl",
instFn: []string{
"github.com/gin-gonic/gin.(*Engine).ServeHTTP",
},
src: "templates/github.com/gin-gonic/gin/*.tmpl",
instrs: []instrumentors.Instrumentor{gin.New()},
verFunc: func() ([]string, error) {
return versions.FindVersionsUsingGoList("github.com/gin-gonic/gin")
},
Expand All @@ -111,10 +116,8 @@ var (
Name: "github.com/gorilla/mux",
PkgGoURL: "https://pkg.go.dev/github.com/gorilla/mux",

src: "templates/github.com/gorilla/mux/*.tmpl",
instFn: []string{
"github.com/gorilla/mux.(*Router).ServeHTTP",
},
src: "templates/github.com/gorilla/mux/*.tmpl",
instrs: []instrumentors.Instrumentor{mux.New()},
verFunc: func() ([]string, error) {
return versions.FindVersionsUsingGoList("github.com/gorilla/mux")
},
Expand All @@ -123,10 +126,8 @@ var (
Name: "database/sql",
PkgGoURL: "https://pkg.go.dev/database/sql",

src: "templates/database/sql/*.tmpl",
instFn: []string{
"database/sql.(*DB).queryDC",
},
src: "templates/database/sql/*.tmpl",
instrs: []instrumentors.Instrumentor{sql.New()},
verFunc: func() ([]string, error) { return goVersions, nil },
},
}
Expand All @@ -140,8 +141,8 @@ type pkg struct {
src string
// verFunc returns all package versions.
verFunc func() ([]string, error)
// instFn are the instrumented functions.
instFn []string
// instrs are the providers of instrumentation.
instrs []instrumentors.Instrumentor
}

func (p pkg) init() (Package, error) {
Expand Down Expand Up @@ -228,9 +229,14 @@ func (p pkg) check(version string) error {
return errFailBuild
}

var funcNames []string
for _, instr := range p.instrs {
funcNames = append(funcNames, instr.FuncNames()...)
}

execPath := filepath.Join(dir, "app")
var missing []string
for _, name := range p.instFn {
for _, name := range funcNames {
has, err := hasSubprogram(execPath, name)
if err != nil {
return err
Expand Down
29 changes: 25 additions & 4 deletions internal/tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/golangci/golangci-lint v1.54.2
github.com/google/go-licenses v1.6.0
github.com/hashicorp/go-version v1.6.0
go.opentelemetry.io/auto v0.2.2-alpha
go.opentelemetry.io/auto/offsets-tracker v0.2.2-alpha
go.opentelemetry.io/build-tools/multimod v0.11.0
golang.org/x/mod v0.12.0
Expand Down Expand Up @@ -41,9 +42,11 @@ require (
github.com/butuzov/ireturn v0.2.0 // indirect
github.com/butuzov/mirror v1.1.0 // indirect
github.com/ccojocar/zxcvbn-go v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charithe/durationcheck v0.0.10 // indirect
github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8 // indirect
github.com/cilium/ebpf v0.11.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/curioswitch/go-reassign v0.2.0 // indirect
github.com/daixiang0/gci v0.11.0 // indirect
Expand All @@ -62,6 +65,8 @@ require (
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-git/v5 v5.8.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-toolsmith/astcast v1.1.0 // indirect
github.com/go-toolsmith/astcopy v1.1.0 // indirect
github.com/go-toolsmith/astequal v1.1.0 // indirect
Expand Down Expand Up @@ -90,6 +95,7 @@ require (
github.com/gostaticanalysis/comment v1.4.2 // indirect
github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down Expand Up @@ -129,9 +135,10 @@ require (
github.com/nishanths/predeclared v0.2.2 // indirect
github.com/nunnatsa/ginkgolinter v0.13.5 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/otiai10/copy v1.6.0 // indirect
github.com/otiai10/copy v1.12.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polyfloyd/go-errorlint v1.4.4 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
Expand Down Expand Up @@ -187,10 +194,18 @@ require (
gitlab.com/bosi/decorder v0.4.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/build-tools v0.11.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.tmz.dev/musttag v0.7.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/arch v0.4.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 // indirect
Expand All @@ -199,6 +214,10 @@ require (
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
Expand All @@ -215,3 +234,5 @@ require (
)

replace go.opentelemetry.io/auto/offsets-tracker => ../../offsets-tracker/

replace go.opentelemetry.io/auto => ../../
Loading

0 comments on commit be26938

Please sign in to comment.