1 Star 0 Fork 0

SasukeBo/go-micro

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
datadog.go 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
汪波 提交于 2023-02-23 10:27 . fix: 替换包名
// Package datadog provides wrappers for Datadog ddtrace
package datadog
import (
"gitee.com/sasukebo/go-micro/v4/registry"
"context"
"gitee.com/sasukebo/go-micro/v4/client"
"gitee.com/sasukebo/go-micro/v4/server"
)
var noDebugStack = true
// SetNoDebugStack ...
func SetNoDebugStack(val bool) {
noDebugStack = val
}
type ddWrapper struct {
client.Client
}
func (d *ddWrapper) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) (err error) {
t := newRequestTracker(req, ClientProfile)
ctx = t.StartSpanFromContext(ctx)
defer func() {
t.finishWithError(err, noDebugStack)
}()
err = d.Client.Call(ctx, req, rsp, opts...)
return
}
func (d *ddWrapper) Publish(ctx context.Context, p client.Message, opts ...client.PublishOption) (err error) {
t := newEventTracker(p, ClientProfile)
ctx = t.StartSpanFromContext(ctx)
defer func() {
t.finishWithError(err, noDebugStack)
}()
err = d.Client.Publish(ctx, p, opts...)
return
}
// NewClientWrapper returns a Client wrapped in tracer
func NewClientWrapper() client.Wrapper {
return func(c client.Client) client.Client {
return &ddWrapper{c}
}
}
// NewCallWrapper returns a Call Wrapper
func NewCallWrapper() client.CallWrapper {
return func(cf client.CallFunc) client.CallFunc {
return func(ctx context.Context, node *registry.Node, req client.Request, rsp interface{}, opts client.CallOptions) error {
t := newRequestTracker(req, ClientProfile)
ctx = t.StartSpanFromContext(ctx)
defer func() {
t.finishWithError(nil, noDebugStack)
}()
return cf(ctx, node, req, rsp, opts)
}
}
}
// NewHandlerWrapper returns a Handler Wrapper
func NewHandlerWrapper() server.HandlerWrapper {
return func(h server.HandlerFunc) server.HandlerFunc {
return func(ctx context.Context, req server.Request, rsp interface{}) (err error) {
if req.Endpoint() != "Debug.Health" {
t := newRequestTracker(req, ServerProfile)
ctx = t.StartSpanFromContext(ctx)
defer func() {
t.finishWithError(err, noDebugStack)
}()
}
err = h(ctx, req, rsp)
return
}
}
}
// NewSubscriberWrapper returns a Subscriber Wrapper
func NewSubscriberWrapper() server.SubscriberWrapper {
return func(next server.SubscriberFunc) server.SubscriberFunc {
return func(ctx context.Context, msg server.Message) (err error) {
t := newEventTracker(msg, ServerProfile)
ctx = t.StartSpanFromContext(ctx)
defer func() {
t.finishWithError(err, noDebugStack)
}()
err = next(ctx, msg)
return
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sasukebo/go-micro.git
git@gitee.com:sasukebo/go-micro.git
sasukebo
go-micro
go-micro
6e18eb58b836

搜索帮助

0d507c66 1850385 C8b1a773 1850385