Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/plugin-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ jobs:
- go-redisv9
- go-restfulv3
- gorm
- gorm-postgres
# - kratosv2 temporary disable because it's not stable
- microv4
- mongo
- mysql
- postgres
- zap
- logrus
- plugin_exclusion
Expand Down
4 changes: 3 additions & 1 deletion docs/en/agent/support-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ metrics based on the tracing data.
* `microv4`: [Go-Micro](https://github.com/go-micro/go-micro) tested v4.6.0 to v4.10.2.
* `grpc` : [gRPC](https://github.com/grpc/grpc-go) tested v1.55.0 to v1.64.0.
* Database Client
* `gorm`: [GORM](https://github.com/go-gorm/gorm) tested v1.22.0 to v1.25.1.
* `gorm`: [GORM](https://github.com/go-gorm/gorm) tested v1.22.0 to v1.25.10.
Comment thread
wl2027 marked this conversation as resolved.
* [MySQL Driver](https://github.com/go-gorm/mysql)
* [PostgreSQL Driver](https://github.com/go-gorm/postgres) tested v1.5.11.
* `mongo`: [Mongo](https://github.com/mongodb/mongo-go-driver) tested v1.11.1 to v1.11.7.
* `sql`: [Native SQL](https://pkg.go.dev/database/sql) tested go v1.19 to go v1.23.
* [MySQL Driver](https://github.com/go-sql-driver/mysql) tested v1.4.0 to v1.7.1.
* [pgx/v5 stdlib](https://github.com/jackc/pgx/tree/master/stdlib) tested v5.5.5.
* `go-elasticsearchv8`: [go-elasticsearch](https://github.com/elastic/go-elasticsearch) tested v8.10.0 to v8.11.1.
* Cache Client
* `go-redisv9`: [go-redis](https://github.com/redis/go-redis) tested v9.0.3 to v9.0.5.
Expand Down
2 changes: 2 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ use (
./test/plugins/scenarios/go-redisv9
./test/plugins/scenarios/go-restfulv3
./test/plugins/scenarios/gorm
./test/plugins/scenarios/gorm-postgres
./test/plugins/scenarios/kratosv2
./test/plugins/scenarios/microv4
./test/plugins/scenarios/mongo
./test/plugins/scenarios/mysql
./test/plugins/scenarios/postgres
./test/plugins/scenarios/logrus
./test/plugins/scenarios/zap
./test/plugins/scenarios/mux
Expand Down
2 changes: 1 addition & 1 deletion plugins/gorm/entry/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (i *OpenInterceptor) AfterInvoke(invocation operator.Invocation, result ...
}

func (i *OpenInterceptor) setupDatabaseInfo(db *gorm.DB) DatabaseInfo {
if db.Config == nil || db.Config.Dialector == nil {
if db == nil || db.Config == nil || db.Config.Dialector == nil {
return nil
}
ins, ok := db.Config.Dialector.(operator.EnhancedInstance)
Expand Down
27 changes: 25 additions & 2 deletions plugins/gorm/entry/interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ func TestInterceptor(t *testing.T) {
}
}

func TestInterceptorWithPrepareStmt(t *testing.T) {
defer core.ResetTracingContext()

interceptor := &OpenInterceptor{}
db, err := gorm.Open(NewTestDialector(&mysql.DatabaseInfo{PeerAddress: peerAddress}), &gorm.Config{
PrepareStmt: true,
DisableAutomaticPing: true,
})
assert.Nil(t, err, "failed to open database")
assert.NotNil(t, db, "failed to open database")
err = interceptor.AfterInvoke(nil, db, err)
assert.Nil(t, err, "failed to invoke AfterInvoke")

res := db.Exec("select * from test where id = ?", "1")
assert.Equal(t, errConnectionExecute, res.Error, "failed to invoke prepared statement")

time.Sleep(100 * time.Millisecond)
spans := core.GetReportedSpans()
assert.NotNil(t, spans, "spans should not be nil")
assert.Equal(t, 1, len(spans), "spans length should be 1")
assert.Equal(t, peerAddress, spans[0].Peer(), "peer should be localhost:3306")
assert.Equal(t, int32(5012), spans[0].ComponentID(), "component id should be 5012")
}

type TestDialector struct {
gorm.Dialector
field interface{}
Expand All @@ -104,8 +128,7 @@ func (i *TestDialector) SetSkyWalkingDynamicField(v interface{}) {
i.field = v
}

type TestConnPool struct {
}
type TestConnPool struct{}

func (i *TestConnPool) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
return nil, errConnectionExecute
Expand Down
25 changes: 21 additions & 4 deletions plugins/gorm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,36 @@ module github.com/apache/skywalking-go/plugins/gorm
go 1.19

require (
github.com/apache/skywalking-go/plugins/core v0.0.0-20260210074111-924fc3238ad2
Comment thread
wl2027 marked this conversation as resolved.
Outdated
github.com/go-sql-driver/mysql v1.7.1
github.com/jackc/pgx/v5 v5.5.5
github.com/stretchr/testify v1.8.2
gorm.io/driver/mysql v1.5.1
gorm.io/gorm v1.25.1
gorm.io/driver/postgres v1.5.11
gorm.io/gorm v1.25.10
)

require (
github.com/apache/skywalking-go v0.6.1-0.20260210074111-924fc3238ad2 // indirect
github.com/dave/dst v0.27.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
68 changes: 67 additions & 1 deletion plugins/gorm/go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,82 @@
github.com/apache/skywalking-go v0.6.1-0.20260210074111-924fc3238ad2 h1:vLuZSawY5RPhBIg3Hz/RfCPuhQjjpPsTPIhLp6Ndd2o=
github.com/apache/skywalking-go v0.6.1-0.20260210074111-924fc3238ad2/go.mod h1:EIbOxJezWSf22p4P0p0RAgpEOvaN0sNQAtfYPX2wAyc=
github.com/apache/skywalking-go/plugins/core v0.0.0-20260210074111-924fc3238ad2 h1:RBRr5CXeoxK/uNfeRQqCZM/k6VxuGMriNaB+tZAhu0Y=
github.com/apache/skywalking-go/plugins/core v0.0.0-20260210074111-924fc3238ad2/go.mod h1:pOd//wrJ9lx9TwCbX6KSxfwf0756WFBstn3qIV/hboY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/dave/dst v0.27.2 h1:4Y5VFTkhGLC1oddtNwuxxe36pnyLxMFXT51FOzH8Ekc=
github.com/dave/dst v0.27.2/go.mod h1:jHh6EOibnHgcUW3WjKHisiooEkYwqpHLBSX1iOBhEyc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag=
google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw=
gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o=
gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
81 changes: 81 additions & 0 deletions plugins/gorm/postgres/instrument.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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 postgres

import (
"embed"

"github.com/apache/skywalking-go/plugins/core/instrument"
)

//go:embed *
var fs embed.FS

const postgresName = "postgres"

//skywalking:nocopy
type Instrument struct {
}

func NewInstrument() *Instrument {
return &Instrument{}
}

func (i *Instrument) Name() string {
return "gorm"
}

func (i *Instrument) BasePackage() string {
return "gorm.io/driver/postgres"
}

func (i *Instrument) VersionChecker(version string) bool {
return true
}

func (i *Instrument) Points() []*instrument.Point {
return []*instrument.Point{
{
PackagePath: "",
At: instrument.NewStaticMethodEnhance("Open",
instrument.WithArgsCount(1), instrument.WithArgType(0, "string"),
instrument.WithResultCount(1), instrument.WithResultType(0, "gorm.Dialector")),
Interceptor: "InstanceInterceptor",
},
{
PackagePath: "",
At: instrument.NewStaticMethodEnhance("New",
instrument.WithArgsCount(1), instrument.WithArgType(0, "Config"),
instrument.WithResultCount(1), instrument.WithResultType(0, "gorm.Dialector")),
Interceptor: "InstanceInterceptor",
},
{
PackagePath: "",
At: instrument.NewStructEnhance("Dialector",
instrument.WithFiledType("", "*Config")),
},
}
}

func (i *Instrument) PluginSourceCodePath() string {
return postgresName
}

func (i *Instrument) FS() *embed.FS {
return &fs
}
Loading
Loading