From 7dbc4714017261d50f82e61af22ffb906ad7ab45 Mon Sep 17 00:00:00 2001 From: yndu13 Date: Tue, 17 Oct 2023 22:23:24 +0800 Subject: [PATCH] [golang]feat: support opentracing --- golang/go.mod | 1 + golang/service/service.go | 43 +++++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/golang/go.mod b/golang/go.mod index 4cb4a4e3..b797ad0f 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -5,4 +5,5 @@ go 1.14 require ( github.com/alibabacloud-go/tea v1.1.0 golang.org/x/net v0.17.0 // indirect + github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b ) diff --git a/golang/service/service.go b/golang/service/service.go index 3e3337b4..c106ff15 100644 --- a/golang/service/service.go +++ b/golang/service/service.go @@ -20,29 +20,31 @@ import ( "time" "github.com/alibabacloud-go/tea/tea" + opentracing "github.com/opentracing/opentracing-go" ) var defaultUserAgent = fmt.Sprintf("AlibabaCloud (%s; %s) Golang/%s Core/%s TeaDSL/1", runtime.GOOS, runtime.GOARCH, strings.Trim(runtime.Version(), "go"), "0.01") type RuntimeOptions struct { - Autoretry *bool `json:"autoretry" xml:"autoretry"` - IgnoreSSL *bool `json:"ignoreSSL" xml:"ignoreSSL"` - Key *string `json:"key,omitempty" xml:"key,omitempty"` - Cert *string `json:"cert,omitempty" xml:"cert,omitempty"` - Ca *string `json:"ca,omitempty" xml:"ca,omitempty"` - MaxAttempts *int `json:"maxAttempts" xml:"maxAttempts"` - BackoffPolicy *string `json:"backoffPolicy" xml:"backoffPolicy"` - BackoffPeriod *int `json:"backoffPeriod" xml:"backoffPeriod"` - ReadTimeout *int `json:"readTimeout" xml:"readTimeout"` - ConnectTimeout *int `json:"connectTimeout" xml:"connectTimeout"` - LocalAddr *string `json:"localAddr" xml:"localAddr"` - HttpProxy *string `json:"httpProxy" xml:"httpProxy"` - HttpsProxy *string `json:"httpsProxy" xml:"httpsProxy"` - NoProxy *string `json:"noProxy" xml:"noProxy"` - MaxIdleConns *int `json:"maxIdleConns" xml:"maxIdleConns"` - Socks5Proxy *string `json:"socks5Proxy" xml:"socks5Proxy"` - Socks5NetWork *string `json:"socks5NetWork" xml:"socks5NetWork"` - KeepAlive *bool `json:"keepAlive" xml:"keepAlive"` + Autoretry *bool `json:"autoretry" xml:"autoretry"` + IgnoreSSL *bool `json:"ignoreSSL" xml:"ignoreSSL"` + Key *string `json:"key,omitempty" xml:"key,omitempty"` + Cert *string `json:"cert,omitempty" xml:"cert,omitempty"` + Ca *string `json:"ca,omitempty" xml:"ca,omitempty"` + MaxAttempts *int `json:"maxAttempts" xml:"maxAttempts"` + BackoffPolicy *string `json:"backoffPolicy" xml:"backoffPolicy"` + BackoffPeriod *int `json:"backoffPeriod" xml:"backoffPeriod"` + ReadTimeout *int `json:"readTimeout" xml:"readTimeout"` + ConnectTimeout *int `json:"connectTimeout" xml:"connectTimeout"` + LocalAddr *string `json:"localAddr" xml:"localAddr"` + HttpProxy *string `json:"httpProxy" xml:"httpProxy"` + HttpsProxy *string `json:"httpsProxy" xml:"httpsProxy"` + NoProxy *string `json:"noProxy" xml:"noProxy"` + MaxIdleConns *int `json:"maxIdleConns" xml:"maxIdleConns"` + Socks5Proxy *string `json:"socks5Proxy" xml:"socks5Proxy"` + Socks5NetWork *string `json:"socks5NetWork" xml:"socks5NetWork"` + KeepAlive *bool `json:"keepAlive" xml:"keepAlive"` + Span *opentracing.Span `json:"span" xml:"span"` } var processStartTime int64 = time.Now().UnixNano() / 1e6 @@ -156,6 +158,11 @@ func (s *RuntimeOptions) SetKeepAlive(v bool) *RuntimeOptions { return s } +func (s *RuntimeOptions) SetSpan(v *opentracing.Span) *RuntimeOptions { + s.Span = v + return s +} + func ReadAsString(body io.Reader) (*string, error) { byt, err := ioutil.ReadAll(body) if err != nil {