From a9b8af4c5518405157a06ba0527bfe2fb2327221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E5=9B=BD=E5=BA=86?= <362739259@qq.com> Date: Wed, 12 Jan 2022 22:22:30 +0800 Subject: [PATCH] V1.0.x (#1713) * add jaeger config * add probability --- pkg/net/trace/config.go | 4 ++-- pkg/net/trace/dapper.go | 4 ++-- pkg/net/trace/jaeger/config.go | 10 +++++++--- pkg/net/trace/jaeger/jaeger.go | 6 ++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pkg/net/trace/config.go b/pkg/net/trace/config.go index 3f46cf9cc..e8bf921b9 100644 --- a/pkg/net/trace/config.go +++ b/pkg/net/trace/config.go @@ -58,7 +58,7 @@ func TracerFromEnvFlag() (Tracer, error) { return nil, err } report := newReport(cfg.Network, cfg.Addr, time.Duration(cfg.Timeout), cfg.ProtocolVersion) - return NewTracer(env.AppID, report, cfg.DisableSample), nil + return NewTracer(env.AppID, report, cfg.DisableSample, _probability), nil } // Init init trace report. @@ -71,5 +71,5 @@ func Init(cfg *Config) { } } report := newReport(cfg.Network, cfg.Addr, time.Duration(cfg.Timeout), cfg.ProtocolVersion) - SetGlobalTracer(NewTracer(env.AppID, report, cfg.DisableSample)) + SetGlobalTracer(NewTracer(env.AppID, report, cfg.DisableSample, _probability)) } diff --git a/pkg/net/trace/dapper.go b/pkg/net/trace/dapper.go index 88934b103..8b801b079 100644 --- a/pkg/net/trace/dapper.go +++ b/pkg/net/trace/dapper.go @@ -14,8 +14,8 @@ const ( ) // NewTracer new a tracer. -func NewTracer(serviceName string, report reporter, disableSample bool) Tracer { - sampler := newSampler(_probability) +func NewTracer(serviceName string, report reporter, disableSample bool, probability float32) Tracer { + sampler := newSampler(probability) // default internal tags tags := extendTag() diff --git a/pkg/net/trace/jaeger/config.go b/pkg/net/trace/jaeger/config.go index e5170cc25..345a5ce98 100644 --- a/pkg/net/trace/jaeger/config.go +++ b/pkg/net/trace/jaeger/config.go @@ -11,6 +11,7 @@ import ( var ( _jaegerAppID = env.AppID _jaegerEndpoint = "http://127.0.0.1:9191" + _probability = 0.00025 ) func init() { @@ -27,7 +28,10 @@ func init() { } // Init Init -func Init() { - c := &Config{Endpoint: _jaegerEndpoint, BatchSize: 120} - trace.SetGlobalTracer(trace.NewTracer(_jaegerAppID, newReport(c), true)) +func Init(cfg *Config) { + c := cfg + if c == nil { + c = &Config{AppID: _jaegerAppID, Endpoint: _jaegerEndpoint, BatchSize: 120, Probability: float32(_probability)} + } + trace.SetGlobalTracer(trace.NewTracer(c.AppID, newReport(c), true, c.Probability)) } diff --git a/pkg/net/trace/jaeger/jaeger.go b/pkg/net/trace/jaeger/jaeger.go index 5feda289e..413f444a5 100644 --- a/pkg/net/trace/jaeger/jaeger.go +++ b/pkg/net/trace/jaeger/jaeger.go @@ -6,8 +6,10 @@ import ( ) type Config struct { - Endpoint string - BatchSize int + AppID string + Endpoint string + BatchSize int + Probability float32 } type JaegerReporter struct {