Skip to content

Commit d7f0680

Browse files
authored
Support go-micro framework with v4 version (#46)
1 parent 19471c4 commit d7f0680

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2988
-139
lines changed

.github/workflows/plugin-tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
- go-restfulv3
6363
- gorm
6464
- kratosv2
65+
- microv4
6566
- plugin_exclusion
6667
steps:
6768
- uses: actions/checkout@v2

agent/core/compile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
_ "sync"
3535
_ "sync/atomic"
3636
_ "time"
37+
_ "unsafe"
3738

3839
//go:nolint
3940
_ "github.com/apache/skywalking-go/agent/core/operator"

docs/en/agent/support-plugins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* RPC Frameworks
1010
* `dubbo`: [Dubbo](https://github.com/apache/dubbo-go)
1111
* `kratosv2`: [Kratos](github.com/go-kratos/kratos)
12+
* `microv4`: [Go-Micro](https://github.com/go-micro/go-micro)
1213
* Database Client
1314
* `gorm`: [GORM](https://github.com/go-gorm/gorm)
1415
* [MySQL Driver](https://github.com/go-gorm/mysql)

docs/en/development-and-contribution/development-guide.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,26 @@ Following the previous API define, you should following these steps to use the a
387387
4. Once the above steps are all set, call `span.AsyncFinish()` in any goroutine.
388388
5. When the `span.AsyncFinish()` is complete for all spans, the all spans would be finished and report to the backend.
389389

390+
#### Tracing Context Operation
391+
392+
In the Go Agent, Trace Context would continue cross goroutines automatically by default.
393+
However, in some cases, goroutine would be context sharing due to be scheduled by the pool mechanism. Consider these advanced APIs to manipulate context and switch the current context.
394+
395+
```go
396+
// CaptureContext capture current tracing context in the current goroutine.
397+
func CaptureContext() ContextSnapshot
398+
399+
// ContinueContext continue the tracing context in the current goroutine.
400+
func ContinueContext(ctx ContextSnapshot)
401+
402+
// CleanContext clean the tracing context in the current goroutine.
403+
func CleanContext()
404+
```
405+
406+
Typically, use APIs as following to control or switch the context:
407+
1. Use `tracing.CaptureContext()` to get the ContextSnapshot object.
408+
2. Propagate the snapshot context to any other goroutine in your plugin.
409+
3. Use `tracing.ContinueContext(snapshot)` to continue the snapshot context in the target goroutine.
390410

391411
## Import Plugin
392412

go.work

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use (
1111
./plugins/go-restfulv3
1212
./plugins/gorm
1313
./plugins/kratosv2
14+
./plugins/microv4
1415

1516
./test/benchmark-codebase/consumer
1617
./test/benchmark-codebase/provider
@@ -24,6 +25,7 @@ use (
2425
./test/plugins/scenarios/go-restfulv3
2526
./test/plugins/scenarios/gorm
2627
./test/plugins/scenarios/kratosv2
28+
./test/plugins/scenarios/microv4
2729

2830
./test/plugins/scenarios/plugin_exclusion
2931

go.work.sum

Lines changed: 856 additions & 10 deletions
Large diffs are not rendered by default.

plugins/core/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/golang/protobuf v1.5.3 // indirect
1717
github.com/kr/pretty v0.3.0 // indirect
1818
github.com/pmezard/go-difflib v1.0.0 // indirect
19-
github.com/rogpeppe/go-internal v1.9.0 // indirect
19+
github.com/rogpeppe/go-internal v1.10.0 // indirect
2020
golang.org/x/mod v0.9.0 // indirect
2121
golang.org/x/net v0.10.0 // indirect
2222
golang.org/x/sys v0.8.0 // indirect

plugins/core/go.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
6868
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
6969
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
7070
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
71-
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
71+
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
7272
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
7373
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
7474
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

plugins/core/operator/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var GetOperator = func() Operator { return nil }
2222
type Operator interface {
2323
Tracing() interface{} // to TracingOperator
2424
Logger() interface{} // to LogOperator
25+
Tools() interface{} // to ToolsOperator
2526
DebugStack() []byte // Getting the stack of the current goroutine, for getting details when plugin broken.
2627
Entity() interface{} // Get the entity of the service
2728
}

plugins/core/operator/tools.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package operator
19+
20+
type ToolsOperator interface {
21+
ReflectGetValue(instance interface{}, filters []interface{}) interface{}
22+
}

0 commit comments

Comments
 (0)