The current repo belongs to Paused status, and some functions are restricted. For details, please refer to the description of repo status
2 Star 0 Fork 1

JUMEI_ARCH/go-plugins
Paused

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
awsxray.go 2.46 KB
Copy Edit Raw Blame History
Asim Aslam authored 2018-04-10 15:36 . move awsxray
// Package awsxray is a wrapper for AWS X-Ray distributed tracing
package awsxray
import (
"context"
"github.com/asim/go-awsxray"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/server"
)
type xrayWrapper struct {
opts Options
x *awsxray.AWSXRay
client.Client
}
func (x *xrayWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
var err error
s := getSegment(x.opts.Name, ctx)
defer func() {
setCallStatus(s, req.Service(), req.Method(), err)
go record(x.x, s)
}()
ctx = newContext(ctx, s)
err = x.Client.Call(ctx, req, rsp, opts...)
return err
}
// NewCallWrapper accepts Options and returns a Trace Call Wrapper for individual node calls made by the client
func NewCallWrapper(opts ...Option) client.CallWrapper {
options := Options{
Name: "go.micro.client.CallFunc",
Daemon: "localhost:2000",
}
for _, o := range opts {
o(&options)
}
x := newXRay(options)
return func(cf client.CallFunc) client.CallFunc {
return func(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
var err error
s := getSegment(options.Name, ctx)
defer func() {
setCallStatus(s, addr, req.Method(), err)
go record(x, s)
}()
ctx = newContext(ctx, s)
err = cf(ctx, addr, req, rsp, opts)
return err
}
}
}
// NewClientWrapper accepts Options and returns a Trace Client Wrapper which tracks high level service calls
func NewClientWrapper(opts ...Option) client.Wrapper {
options := Options{
Name: "go.micro.client.Call",
Daemon: "localhost:2000",
}
for _, o := range opts {
o(&options)
}
return func(c client.Client) client.Client {
return &xrayWrapper{options, newXRay(options), c}
}
}
// NewHandlerWrapper accepts Options and returns a Trace Handler Wrapper
func NewHandlerWrapper(opts ...Option) server.HandlerWrapper {
options := Options{
Daemon: "localhost:2000",
}
for _, o := range opts {
o(&options)
}
x := newXRay(options)
return func(h server.HandlerFunc) server.HandlerFunc {
return func(ctx context.Context, req server.Request, rsp interface{}) error {
name := options.Name
if len(name) == 0 {
// default name
name = req.Service() + "." + req.Method()
}
var err error
s := getSegment(name, ctx)
defer func() {
setCallStatus(s, req.Service(), req.Method(), err)
go record(x, s)
}()
ctx = newContext(ctx, s)
err = h(ctx, req, rsp)
return err
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/go-plugins.git
git@gitee.com:JMArch/go-plugins.git
JMArch
go-plugins
go-plugins
v0.9.3

Search

0d507c66 1850385 C8b1a773 1850385