From 5e7a399d8bbf4953ab0c8e3167d7fd535fd74ce1 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Thu, 15 Aug 2019 09:25:40 -0700 Subject: [PATCH] Tracing rewrite (#451) The tracing package has been rewritten to provide a common interface for wiring up the tracing package of choice; no tracing facility is provided by default unless the opencensus package is imported. Please see the CHANGELOG for more details. --- CHANGELOG.md | 23 ++++ Gopkg.lock | 122 ++++++++--------- Gopkg.toml | 65 +++------ autorest/adal/sender.go | 37 +++++- autorest/adal/token.go | 7 +- autorest/authorization.go | 10 +- autorest/client.go | 26 +--- autorest/client_test.go | 24 +--- autorest/sender.go | 29 +++- autorest/version.go | 2 +- azure-pipelines.yml | 22 ++- tracing/go.mod | 7 - tracing/go.sum | 164 ----------------------- tracing/opencensus/go.mod | 11 ++ tracing/opencensus/go.sum | 107 +++++++++++++++ tracing/opencensus/opencensus.go | 180 +++++++++++++++++++++++++ tracing/opencensus/opencensus_test.go | 161 ++++++++++++++++++++++ tracing/tracing.go | 184 ++++---------------------- tracing/tracing_test.go | 144 +++++--------------- 19 files changed, 710 insertions(+), 615 deletions(-) delete mode 100644 tracing/go.sum create mode 100644 tracing/opencensus/go.mod create mode 100644 tracing/opencensus/go.sum create mode 100644 tracing/opencensus/opencensus.go create mode 100644 tracing/opencensus/opencensus_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 31113545d..02d79d3bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # CHANGELOG +## v13.0.0 + +## Breaking Changes + +The `tracing` package has been rewritten to provide a common interface for consumers to wire in the tracing package of their choice. +What this means is that by default no tracing provider will be compiled into your program and setting the `AZURE_SDK_TRACING_ENABLED` +environment variable will have no effect. To enable this previous behavior you must now add the following include to your source file. +```go + include _ "github.com/Azure/go-autorest/tracing/opencensus" +``` +The APIs required by autorest-generated code have remained but some APIs have been removed and new ones added. +The following APIs and variables have been removed (the majority of them were moved to the `opencensus` package). +- tracing.Transport +- tracing.Enable() +- tracing.EnableWithAIForwarding() +- tracing.Disable() + +The following APIs and types have been added +- tracing.Tracer +- tracing.Register() + +To hook up a tracer simply call `tracing.Register()` passing in a type that satisfies the `tracing.Tracer` interface. + ## v12.4.3 ### Bug Fixes diff --git a/Gopkg.lock b/Gopkg.lock index ebb731e47..dfd6249ca 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,15 +2,15 @@ [[projects]] - digest = "1:73be43a59b6c938f2f0aa18fe911dc8643164164ab7cd6629306abeb3d002877" + digest = "1:892e39e5c083d0943f1e80ab8351690f183c6a5ab24e1d280adcad424c26255e" name = "contrib.go.opencensus.io/exporter/ocagent" packages = ["."] pruneopts = "UT" - revision = "060e6898ab87d943e2ff1090efb927fbc5181cea" - version = "v0.4.6" + revision = "a8a6f458bbc1d5042322ad1f9b65eeb0b69be9ea" + version = "v0.6.0" [[projects]] - digest = "1:72ae2856339c681442aefad5976ba3b2e9d6709580147ab11a2a4ad9025995c8" + digest = "1:8f5acd4d4462b5136af644d25101f0968a7a94ee90fcb2059cec5b7cc42e0b20" name = "github.com/census-instrumentation/opencensus-proto" packages = [ "gen-go/agent/common/v1", @@ -18,11 +18,11 @@ "gen-go/agent/trace/v1", "gen-go/metrics/v1", "gen-go/resource/v1", - "gen-go/stats/v1", "gen-go/trace/v1", ] pruneopts = "UT" - revision = "ba49f56771b83cff7bea7f34d1236fc139dbc471" + revision = "d89fa54de508111353cb0b06403c00569be780d8" + version = "v0.2.1" [[projects]] digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" @@ -49,11 +49,15 @@ version = "v1.1.0" [[projects]] - digest = "1:ab79000fab128a653e6f1fc2ebe58df147bc150273960fee72fe9176ecc8b162" + digest = "1:b532ee3f683c057e797694b5bfeb3827d89e6adf41c53dbc80e549bca76364ea" name = "github.com/golang/protobuf" packages = [ "jsonpb", "proto", + "protoc-gen-go/descriptor", + "protoc-gen-go/generator", + "protoc-gen-go/generator/internal/remap", + "protoc-gen-go/plugin", "ptypes", "ptypes/any", "ptypes/duration", @@ -62,20 +66,28 @@ "ptypes/wrappers", ] pruneopts = "UT" - revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" - version = "v1.2.0" + revision = "6c65a5562fc06764971b7c5d05c76c75e84bdbf7" + version = "v1.3.2" [[projects]] - digest = "1:ee73ed01fc93b8aa38a7f25543afed400df661992eeb7d3b250100b8b8f989b9" + digest = "1:3b341cd71012c63aacddabfc70b9110be8e30c553349552ad3f77242843f2d03" name = "github.com/grpc-ecosystem/grpc-gateway" packages = [ + "internal", "runtime", - "runtime/internal", "utilities", ] pruneopts = "UT" - revision = "8558711daa6c2853489043207b563dceacbc19cf" - version = "v1.5.0" + revision = "ad529a448ba494a88058f9e5be0988713174ac86" + version = "v1.9.5" + +[[projects]] + digest = "1:7fae9ec96d10b2afce0da23c378c8b3389319b7f92fa092f2621bba3078cfb4b" + name = "github.com/hashicorp/golang-lru" + packages = ["simplelru"] + pruneopts = "UT" + revision = "7f827b33c0f158ec5dfbba01bb0b14a4541fd81d" + version = "v0.5.3" [[projects]] digest = "1:5d231480e1c64a726869bc4142d270184c419749d34f167646baa21008eb0a79" @@ -105,13 +117,15 @@ version = "v1.3.0" [[projects]] - digest = "1:032feaff40ceceb08d163a35388c48dc3ab017314e99452567aeda612d7b0bc4" + digest = "1:06157420e24cdbcf3e6e23a03297dce37d501866592cfffc65eb85f860ad15d5" name = "go.opencensus.io" packages = [ ".", - "exemplar", "internal", "internal/tagencoding", + "metric/metricdata", + "metric/metricproducer", + "plugin/ocgrpc", "plugin/ochttp", "plugin/ochttp/propagation/b3", "plugin/ochttp/propagation/tracecontext", @@ -126,7 +140,8 @@ "trace/tracestate", ] pruneopts = "UT" - revision = "aab39bd6a98b853ab66c8a564f5d6cfcad59ce8a" + revision = "9c377598961b706d1542bd2d84d538b5094d596e" + version = "v0.22.0" [[projects]] branch = "master" @@ -141,22 +156,9 @@ [[projects]] branch = "master" - digest = "1:134674d729e1afbae39eeaa6abcf8e5f3106338f83643394ab5205a020efbd9b" - name = "golang.org/x/lint" - packages = [ - ".", - "golint", - ] - pruneopts = "UT" - revision = "959b441ac422379a43da2230f62be024250818b0" - -[[projects]] - branch = "master" - digest = "1:eae689808191546269bf951e1e66e0b6bc468be58a0498c0f037feeef2c67bab" + digest = "1:5be6e4c89f3e219abb5655a328f56e2a35b43069651acbf9894ac47f07796673" name = "golang.org/x/net" packages = [ - "context", - "context/ctxhttp", "http/httpguts", "http2", "http2/hpack", @@ -165,7 +167,7 @@ "trace", ] pruneopts = "UT" - revision = "ca1201d0de80cfde86cb01aea620983605dfe99b" + revision = "74dc4d7220e7acc4e100824340f3e66577424772" [[projects]] branch = "master" @@ -177,11 +179,11 @@ [[projects]] branch = "master" - digest = "1:fdfd985fe7956d77128572032636b5c1b7b58a81acd7089e96923e2f9539c573" + digest = "1:47844666be86089349a441f5f0ece22f42a87a8cb8c9a31294c593f43209ad19" name = "golang.org/x/sys" packages = ["unix"] pruneopts = "UT" - revision = "51ab0e2deafac1f46c46ad59cf0921be2f180c3d" + revision = "fde4db37ae7ad8191b03d30d27f258b5291ae4e3" [[projects]] digest = "1:8d8faad6b12a3a4c819a3f9618cb6ee1fa1cfc33253abeeea8b55336721e3405" @@ -209,60 +211,50 @@ version = "v0.3.2" [[projects]] - branch = "master" - digest = "1:a45ec3bb7c73e52430410dff3e0a5534ce518f72a8eb4355bc8502c546b91ecc" - name = "golang.org/x/tools" - packages = [ - "go/ast/astutil", - "go/gcexportdata", - "go/internal/gcimporter", - "go/types/typeutil", - ] - pruneopts = "UT" - revision = "35ef2682e516ea0dd37d51a73b1e957db246ebbf" - -[[projects]] - digest = "1:bd681ade881db4ab0c29eafaa22ea17e488ff7795c285f69fc9b5aada6a49bc8" + digest = "1:5f003878aabe31d7f6b842d4de32b41c46c214bb629bb485387dbcce1edf5643" name = "google.golang.org/api" - packages = [ - "container/v1", - "gensupport", - "googleapi", - "googleapi/internal/uritemplates", - "support/bundler", - ] + packages = ["support/bundler"] pruneopts = "UT" - revision = "7ca32eb868bf53ea2fc406698eb98583a8073d19" + revision = "dec2ee309f5b09fc59bc40676447c15736284d78" + version = "v0.8.0" [[projects]] - digest = "1:5bec19a56fc7942f49b710f964d32ca927a4115794c412553cd5a2d2f663f333" + branch = "master" + digest = "1:3565a93b7692277a5dea355bc47bd6315754f3246ed07a224be6aec28972a805" name = "google.golang.org/genproto" packages = [ - ".", + "googleapis/api/httpbody", "googleapis/rpc/status", + "protobuf/field_mask", ] pruneopts = "UT" - revision = "11092d34479b07829b72e10713b159248caf5dad" + revision = "fa694d86fc64c7654a660f8908de4e879866748d" [[projects]] - digest = "1:ab8e92d746fb5c4c18846b0879842ac8e53b3d352449423d0924a11f1020ae1b" + digest = "1:3b97661db2e5d4c87f7345e875ea28f911e54c715ba0a74be08e1649d67e05cd" name = "google.golang.org/grpc" packages = [ ".", "balancer", "balancer/base", "balancer/roundrobin", + "binarylog/grpc_binarylog_v1", "codes", "connectivity", "credentials", + "credentials/internal", "encoding", "encoding/proto", "grpclog", "internal", "internal/backoff", + "internal/balancerload", + "internal/binarylog", "internal/channelz", "internal/envconfig", "internal/grpcrand", + "internal/grpcsync", + "internal/syscall", "internal/transport", "keepalive", "metadata", @@ -271,24 +263,22 @@ "resolver", "resolver/dns", "resolver/passthrough", + "serviceconfig", "stats", "status", "tap", ] pruneopts = "UT" - revision = "8dea3dc473e90c8179e519d91302d0597c0ca1d1" - version = "v1.15.0" + revision = "6eaf6f47437a6b4e2153a190160ef39a92c7eceb" + version = "v1.23.0" [solve-meta] analyzer-name = "dep" analyzer-version = 1 input-imports = [ "contrib.go.opencensus.io/exporter/ocagent", - "github.com/census-instrumentation/opencensus-proto/gen-go/stats/v1", "github.com/dgrijalva/jwt-go", "github.com/dimchansky/utfbom", - "github.com/golang/protobuf/proto", - "github.com/grpc-ecosystem/grpc-gateway/runtime", "github.com/mitchellh/go-homedir", "github.com/stretchr/testify/require", "go.opencensus.io/plugin/ochttp", @@ -296,10 +286,6 @@ "go.opencensus.io/stats/view", "go.opencensus.io/trace", "golang.org/x/crypto/pkcs12", - "golang.org/x/lint/golint", - "google.golang.org/api/container/v1", - "google.golang.org/genproto", - "google.golang.org/grpc", ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 5783e05dc..1fc286596 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,6 +1,6 @@ # Gopkg.toml example # -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html # for detailed Gopkg.toml documentation. # # required = ["github.com/user/thing/cmd/thing"] @@ -16,67 +16,44 @@ # source = "github.com/myfork/project2" # # [[override]] -# name = "github.com/x/y" -# version = "2.4.0" +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true -required = [ - "github.com/census-instrumentation/opencensus-proto/gen-go/stats/v1", - "github.com/golang/protobuf/proto", - "github.com/grpc-ecosystem/grpc-gateway/runtime", - "golang.org/x/lint/golint", - "google.golang.org/api/container/v1", - "google.golang.org/genproto", - "google.golang.org/grpc" - ] +required = ["golang.org/x/lint/golint"] [prune] - unused-packages = true go-tests = true + unused-packages = true + +[[constraint]] + name = "contrib.go.opencensus.io/exporter/ocagent" + version = "0.6.0" [[constraint]] name = "github.com/dgrijalva/jwt-go" - version = "3.1.0" + version = "3.2.0" [[constraint]] name = "github.com/dimchansky/utfbom" - version = "1.0.0" + version = "1.1.0" [[constraint]] name = "github.com/mitchellh/go-homedir" - version = "1.0.0" + version = "1.1.0" [[constraint]] name = "github.com/stretchr/testify" - version = "1.2.0" + version = "1.3.0" [[constraint]] name = "go.opencensus.io" - revision = "aab39bd6a98b853ab66c8a564f5d6cfcad59ce8a" - -[[constraint]] - name = "contrib.go.opencensus.io/exporter/ocagent" - version = "=0.4.6" - -[[constraint]] - name = "github.com/census-instrumentation/opencensus-proto" - revision = "ba49f56771b83cff7bea7f34d1236fc139dbc471" - -[[constraint]] - name = "github.com/golang/protobuf" - version = "=1.2.0" - -[[constraint]] - name = "google.golang.org/api" - revision = "7ca32eb868bf53ea2fc406698eb98583a8073d19" - -[[constraint]] - name = "google.golang.org/genproto" - revision = "11092d34479b07829b72e10713b159248caf5dad" - -[[constraint]] - name = "google.golang.org/grpc" - version = "=1.15.0" + version = "0.22.0" [[constraint]] - name = "github.com/grpc-ecosystem/grpc-gateway" - version = "=1.5.0" + branch = "master" + name = "golang.org/x/crypto" diff --git a/autorest/adal/sender.go b/autorest/adal/sender.go index 834401e00..d7e4372bb 100644 --- a/autorest/adal/sender.go +++ b/autorest/adal/sender.go @@ -15,7 +15,12 @@ package adal // limitations under the License. import ( + "crypto/tls" "net/http" + "net/http/cookiejar" + "sync" + + "github.com/Azure/go-autorest/tracing" ) const ( @@ -23,6 +28,9 @@ const ( mimeTypeFormPost = "application/x-www-form-urlencoded" ) +var defaultSender Sender +var defaultSenderInit = &sync.Once{} + // Sender is the interface that wraps the Do method to send HTTP requests. // // The standard http.Client conforms to this interface. @@ -45,7 +53,7 @@ type SendDecorator func(Sender) Sender // CreateSender creates, decorates, and returns, as a Sender, the default http.Client. func CreateSender(decorators ...SendDecorator) Sender { - return DecorateSender(&http.Client{}, decorators...) + return DecorateSender(sender(), decorators...) } // DecorateSender accepts a Sender and a, possibly empty, set of SendDecorators, which is applies to @@ -58,3 +66,30 @@ func DecorateSender(s Sender, decorators ...SendDecorator) Sender { } return s } + +func sender() Sender { + // note that we can't init defaultSender in init() since it will + // execute before calling code has had a chance to enable tracing + defaultSenderInit.Do(func() { + // Use behaviour compatible with DefaultTransport, but require TLS minimum version. + defaultTransport := http.DefaultTransport.(*http.Transport) + transport := &http.Transport{ + Proxy: defaultTransport.Proxy, + DialContext: defaultTransport.DialContext, + MaxIdleConns: defaultTransport.MaxIdleConns, + IdleConnTimeout: defaultTransport.IdleConnTimeout, + TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout, + ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout, + TLSClientConfig: &tls.Config{ + MinVersion: tls.VersionTLS12, + }, + } + var roundTripper http.RoundTripper = transport + if tracing.IsEnabled() { + roundTripper = tracing.NewTransport(transport) + } + j, _ := cookiejar.New(nil) + defaultSender = &http.Client{Jar: j, Transport: roundTripper} + }) + return defaultSender +} diff --git a/autorest/adal/token.go b/autorest/adal/token.go index 3947d0112..b72753498 100644 --- a/autorest/adal/token.go +++ b/autorest/adal/token.go @@ -34,7 +34,6 @@ import ( "time" "github.com/Azure/go-autorest/autorest/date" - "github.com/Azure/go-autorest/tracing" "github.com/dgrijalva/jwt-go" ) @@ -396,7 +395,7 @@ func (spt *ServicePrincipalToken) UnmarshalJSON(data []byte) error { spt.refreshLock = &sync.RWMutex{} } if spt.sender == nil { - spt.sender = &http.Client{Transport: tracing.Transport} + spt.sender = sender() } return nil } @@ -444,7 +443,7 @@ func NewServicePrincipalTokenWithSecret(oauthConfig OAuthConfig, id string, reso RefreshWithin: defaultRefresh, }, refreshLock: &sync.RWMutex{}, - sender: &http.Client{Transport: tracing.Transport}, + sender: sender(), refreshCallbacks: callbacks, } return spt, nil @@ -685,7 +684,7 @@ func newServicePrincipalTokenFromMSI(msiEndpoint, resource string, userAssignedI RefreshWithin: defaultRefresh, }, refreshLock: &sync.RWMutex{}, - sender: &http.Client{Transport: tracing.Transport}, + sender: sender(), refreshCallbacks: callbacks, MaxMSIRefreshAttempts: defaultMaxMSIRefreshAttempts, } diff --git a/autorest/authorization.go b/autorest/authorization.go index 380865cd6..54e87b5b6 100644 --- a/autorest/authorization.go +++ b/autorest/authorization.go @@ -15,6 +15,7 @@ package autorest // limitations under the License. import ( + "crypto/tls" "encoding/base64" "fmt" "net/http" @@ -22,7 +23,6 @@ import ( "strings" "github.com/Azure/go-autorest/autorest/adal" - "github.com/Azure/go-autorest/tracing" ) const ( @@ -149,11 +149,11 @@ type BearerAuthorizerCallback struct { // NewBearerAuthorizerCallback creates a bearer authorization callback. The callback // is invoked when the HTTP request is submitted. -func NewBearerAuthorizerCallback(sender Sender, callback BearerAuthorizerCallbackFunc) *BearerAuthorizerCallback { - if sender == nil { - sender = &http.Client{Transport: tracing.Transport} +func NewBearerAuthorizerCallback(s Sender, callback BearerAuthorizerCallbackFunc) *BearerAuthorizerCallback { + if s == nil { + s = sender(tls.RenegotiateNever) } - return &BearerAuthorizerCallback{sender: sender, callback: callback} + return &BearerAuthorizerCallback{sender: s, callback: callback} } // WithAuthorization returns a PrepareDecorator that adds an HTTP Authorization header whose value diff --git a/autorest/client.go b/autorest/client.go index 92da6adb2..1c6a0617a 100644 --- a/autorest/client.go +++ b/autorest/client.go @@ -22,12 +22,10 @@ import ( "io/ioutil" "log" "net/http" - "net/http/cookiejar" "strings" "time" "github.com/Azure/go-autorest/logger" - "github.com/Azure/go-autorest/tracing" ) const ( @@ -264,30 +262,8 @@ func (c Client) Do(r *http.Request) (*http.Response, error) { // sender returns the Sender to which to send requests. func (c Client) sender(renengotiation tls.RenegotiationSupport) Sender { if c.Sender == nil { - // Use behaviour compatible with DefaultTransport, but require TLS minimum version. - var defaultTransport = http.DefaultTransport.(*http.Transport) - transport := tracing.Transport - // for non-default values of TLS renegotiation create a new tracing transport. - // updating tracing.Transport affects all clients which is not what we want. - if renengotiation != tls.RenegotiateNever { - transport = tracing.NewTransport() - } - transport.Base = &http.Transport{ - Proxy: defaultTransport.Proxy, - DialContext: defaultTransport.DialContext, - MaxIdleConns: defaultTransport.MaxIdleConns, - IdleConnTimeout: defaultTransport.IdleConnTimeout, - TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout, - ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout, - TLSClientConfig: &tls.Config{ - MinVersion: tls.VersionTLS12, - Renegotiation: renengotiation, - }, - } - j, _ := cookiejar.New(nil) - return &http.Client{Jar: j, Transport: transport} + return sender(renengotiation) } - return c.Sender } diff --git a/autorest/client_test.go b/autorest/client_test.go index ca896714d..6cf885cd2 100644 --- a/autorest/client_test.go +++ b/autorest/client_test.go @@ -28,8 +28,6 @@ import ( "time" "github.com/Azure/go-autorest/autorest/mocks" - "github.com/Azure/go-autorest/tracing" - "go.opencensus.io/plugin/ochttp" ) func TestLoggingInspectorWithInspection(t *testing.T) { @@ -134,7 +132,7 @@ func TestNewClientWithUserAgent(t *testing.T) { t.Fatalf("autorest: NewClientWithUserAgent failed to set the UserAgent -- expected %s, received %s", completeUA, c.UserAgent) } - r := c.Sender.(*http.Client).Transport.(*ochttp.Transport).Base.(*http.Transport).TLSClientConfig.Renegotiation + r := c.Sender.(*http.Client).Transport.(*http.Transport).TLSClientConfig.Renegotiation if r != tls.RenegotiateNever { t.Fatal("autorest: TestNewClientWithUserAgentTLSRenegotiation expected RenegotiateNever") } @@ -146,21 +144,21 @@ func TestNewClientWithOptions(t *testing.T) { UserAgent: ua, Renegotiation: tls.RenegotiateFreelyAsClient, }) - r1 := c1.Sender.(*http.Client).Transport.(*ochttp.Transport).Base.(*http.Transport).TLSClientConfig.Renegotiation + r1 := c1.Sender.(*http.Client).Transport.(*http.Transport).TLSClientConfig.Renegotiation if r1 != tls.RenegotiateFreelyAsClient { t.Fatal("autorest: TestNewClientWithUserAgentTLSRenegotiation expected RenegotiateFreelyAsClient") } // ensure default value doesn't stomp over previous value c2 := NewClientWithUserAgent(ua) - r2 := c2.Sender.(*http.Client).Transport.(*ochttp.Transport).Base.(*http.Transport).TLSClientConfig.Renegotiation + r2 := c2.Sender.(*http.Client).Transport.(*http.Transport).TLSClientConfig.Renegotiation if r2 != tls.RenegotiateNever { t.Fatal("autorest: TestNewClientWithUserAgentTLSRenegotiation expected RenegotiateNever") } - r1 = c1.Sender.(*http.Client).Transport.(*ochttp.Transport).Base.(*http.Transport).TLSClientConfig.Renegotiation + r1 = c1.Sender.(*http.Client).Transport.(*http.Transport).TLSClientConfig.Renegotiation if r1 != tls.RenegotiateFreelyAsClient { t.Fatal("autorest: TestNewClientWithUserAgentTLSRenegotiation expected RenegotiateFreelyAsClient (overwritten)") } - r2 = c2.Sender.(*http.Client).Transport.(*ochttp.Transport).Base.(*http.Transport).TLSClientConfig.Renegotiation + r2 = c2.Sender.(*http.Client).Transport.(*http.Transport).TLSClientConfig.Renegotiation if r2 != tls.RenegotiateNever { t.Fatal("autorest: TestNewClientWithUserAgentTLSRenegotiation expected RenegotiateNever (overwritten)") } @@ -378,18 +376,6 @@ func TestClientByInspectingSetsDefault(t *testing.T) { } } -func TestClientTracing(t *testing.T) { - c := Client{} - - httpClient, ok := c.sender(tls.RenegotiateNever).(*http.Client) - if !ok { - t.Fatal("autorest: Client#sender failed to return http.Client by default") - } - if httpClient.Transport != tracing.Transport { - t.Fatal("autorest: Client.Sender Default transport is not the tracing transport") - } -} - func TestCookies(t *testing.T) { second := "second" expected := http.Cookie{ diff --git a/autorest/sender.go b/autorest/sender.go index 92a55404a..e582489b3 100644 --- a/autorest/sender.go +++ b/autorest/sender.go @@ -16,10 +16,12 @@ package autorest import ( "context" + "crypto/tls" "fmt" "log" "math" "net/http" + "net/http/cookiejar" "strconv" "time" @@ -69,7 +71,7 @@ type SendDecorator func(Sender) Sender // CreateSender creates, decorates, and returns, as a Sender, the default http.Client. func CreateSender(decorators ...SendDecorator) Sender { - return DecorateSender(&http.Client{}, decorators...) + return DecorateSender(sender(tls.RenegotiateNever), decorators...) } // DecorateSender accepts a Sender and a, possibly empty, set of SendDecorators, which is applies to @@ -92,7 +94,7 @@ func DecorateSender(s Sender, decorators ...SendDecorator) Sender { // // Send will not poll or retry requests. func Send(r *http.Request, decorators ...SendDecorator) (*http.Response, error) { - return SendWithSender(&http.Client{Transport: tracing.Transport}, r, decorators...) + return SendWithSender(sender(tls.RenegotiateNever), r, decorators...) } // SendWithSender sends the passed http.Request, through the provided Sender, returning the @@ -104,6 +106,29 @@ func SendWithSender(s Sender, r *http.Request, decorators ...SendDecorator) (*ht return DecorateSender(s, decorators...).Do(r) } +func sender(renengotiation tls.RenegotiationSupport) Sender { + // Use behaviour compatible with DefaultTransport, but require TLS minimum version. + defaultTransport := http.DefaultTransport.(*http.Transport) + transport := &http.Transport{ + Proxy: defaultTransport.Proxy, + DialContext: defaultTransport.DialContext, + MaxIdleConns: defaultTransport.MaxIdleConns, + IdleConnTimeout: defaultTransport.IdleConnTimeout, + TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout, + ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout, + TLSClientConfig: &tls.Config{ + MinVersion: tls.VersionTLS12, + Renegotiation: renengotiation, + }, + } + var roundTripper http.RoundTripper = transport + if tracing.IsEnabled() { + roundTripper = tracing.NewTransport(transport) + } + j, _ := cookiejar.New(nil) + return &http.Client{Jar: j, Transport: roundTripper} +} + // AfterDelay returns a SendDecorator that delays for the passed time.Duration before // invoking the Sender. The delay may be terminated by closing the optional channel on the // http.Request. If canceled, no further Senders are invoked. diff --git a/autorest/version.go b/autorest/version.go index 6b6a16a75..cb851937a 100644 --- a/autorest/version.go +++ b/autorest/version.go @@ -19,7 +19,7 @@ import ( "runtime" ) -const number = "v12.4.3" +const number = "v13.0.0" var ( userAgent = fmt.Sprintf("Go/%s (%s-%s) go-autorest/%s", diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b025f5d34..c6a0a3162 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -27,15 +27,21 @@ steps: go get -u gopkg.in/matm/v1/gocov-html workingDirectory: '$(sdkPath)' displayName: 'Install Dependencies' -- script: go vet ./autorest/... +- script: | + go vet ./autorest/... + go vet ./logger/... + go vet ./tracing/... workingDirectory: '$(sdkPath)' displayName: 'Vet' -- script: go build -v ./autorest/... +- script: | + go build -v ./autorest/... + go build -v ./logger/... + go build -v ./tracing/... workingDirectory: '$(sdkPath)' displayName: 'Build' - script: | set -e - go test -race -v -coverprofile=coverage.txt -covermode atomic ./autorest/... 2>&1 | go-junit-report > report.xml + go test -race -v -coverprofile=coverage.txt -covermode atomic ./autorest/... ./logger/... ./tracing/... 2>&1 | go-junit-report > report.xml gocov convert coverage.txt > coverage.json gocov-xml < coverage.json > coverage.xml gocov-html < coverage.json > coverage.html @@ -46,12 +52,18 @@ steps: displayName: 'Copyright Header Check' failOnStderr: true condition: succeededOrFailed() -- script: gofmt -s -l -w ./autorest/. >&2 +- script: | + gofmt -s -l -w ./autorest/. >&2 + gofmt -s -l -w ./logger/. >&2 + gofmt -s -l -w ./tracing/. >&2 workingDirectory: '$(sdkPath)' displayName: 'Format Check' failOnStderr: true condition: succeededOrFailed() -- script: golint ./autorest/... >&2 +- script: | + golint ./autorest/... >&2 + golint ./logger/... >&2 + golint ./tracing/... >&2 workingDirectory: '$(sdkPath)' displayName: 'Linter Check' failOnStderr: true diff --git a/tracing/go.mod b/tracing/go.mod index c757de9e8..25c34c108 100644 --- a/tracing/go.mod +++ b/tracing/go.mod @@ -1,10 +1,3 @@ module github.com/Azure/go-autorest/tracing go 1.12 - -require ( - // use older versions to avoid taking a dependency on protobuf v1.3+ - contrib.go.opencensus.io/exporter/ocagent v0.4.6 - github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect - go.opencensus.io v0.19.2 -) diff --git a/tracing/go.sum b/tracing/go.sum deleted file mode 100644 index da27e8f01..000000000 --- a/tracing/go.sum +++ /dev/null @@ -1,164 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -contrib.go.opencensus.io/exporter/ocagent v0.4.6 h1:xVeoJwnzMbseoL9YWhohR6SN/GncvP1p/fznasLkT/E= -contrib.go.opencensus.io/exporter/ocagent v0.4.6/go.mod h1:YuG83h+XWwqWjvCqn7vK4KSyLKhThY3+gNGQ37iS2V0= -git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= -git.apache.org/thrift.git v0.12.0/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= -github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/census-instrumentation/opencensus-proto v0.1.0-0.20181214143942-ba49f56771b8 h1:gUqsFVdUKoRHNg8fkFd8gB5OOEa/g5EwlAHznb4zjbI= -github.com/census-instrumentation/opencensus-proto v0.1.0-0.20181214143942-ba49f56771b8/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= -github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= -github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/grpc-ecosystem/grpc-gateway v1.5.0 h1:WcmKMm43DR7RdtlkEXQJyo5ws8iTp98CyhCCbOHMvNI= -github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/grpc-ecosystem/grpc-gateway v1.6.2/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= -github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= -github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= -github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= -github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -go.opencensus.io v0.18.1-0.20181204023538-aab39bd6a98b h1:6ayHMBPtdP3jNuk+Sfhso+PTB7ZJQ5E1FBo403m2H8w= -go.opencensus.io v0.18.1-0.20181204023538-aab39bd6a98b/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= -go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A= -go.opencensus.io v0.19.2 h1:ZZpq6xI6kv/LuE/5s5UQvBU5vMjvRnPb8PvJrIntAnc= -go.opencensus.io v0.19.2/go.mod h1:NO/8qkisMZLZ1FCsKNqtJPwc8/TaclWyY0B6wcYNg9M= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181218192612-074acd46bca6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181219222714-6e267b5cc78e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf h1:rjxqQmxjyqerRKEj+tZW+MCm4LgpFXu18bsEoCMgDsk= -google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= -google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= -google.golang.org/api v0.2.0 h1:B5VXkdjt7K2Gm6fGBC9C9a1OAKJDT95cTqwet+2zib0= -google.golang.org/api v0.2.0/go.mod h1:IfRCZScioGtypHNTlz3gFk67J8uePVW7uDTBzXuIkhU= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20180831171423-11092d34479b h1:lohp5blsw53GBXtLyLNaTXPXS9pJ1tiTw61ZHUoE9Qw= -google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19 h1:Lj2SnHtxkRGJDqnGaSjo+CCdIieEnwVazbOXILwQemk= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= -google.golang.org/grpc v1.15.0 h1:Az/KuahOM4NAidTEuJCv/RonAA7rYsTPkqXVjr+8OOw= -google.golang.org/grpc v1.15.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= -google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= -google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/tracing/opencensus/go.mod b/tracing/opencensus/go.mod new file mode 100644 index 000000000..b3d62a821 --- /dev/null +++ b/tracing/opencensus/go.mod @@ -0,0 +1,11 @@ +module github.com/Azure/go-autorest/tracing/opencensus + +go 1.12 + +require ( + contrib.go.opencensus.io/exporter/ocagent v0.6.0 + github.com/Azure/go-autorest/tracing v0.7.0 + go.opencensus.io v0.22.0 +) + +replace github.com/Azure/go-autorest/tracing => ../ diff --git a/tracing/opencensus/go.sum b/tracing/opencensus/go.sum new file mode 100644 index 000000000..f6e10ed21 --- /dev/null +++ b/tracing/opencensus/go.sum @@ -0,0 +1,107 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +contrib.go.opencensus.io/exporter/ocagent v0.6.0 h1:Z1n6UAyr0QwM284yUuh5Zd8JlvxUGAhFZcgMJkMPrGM= +contrib.go.opencensus.io/exporter/ocagent v0.6.0/go.mod h1:zmKjrJcdo0aYcVS7bmEeSEBLPA9YJp5bjrofdU3pIXs= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/grpc-ecosystem/grpc-gateway v1.9.4 h1:5xLhQjsk4zqPf9EHCrja2qFZMx+yBqkO3XgJ14bNnU0= +github.com/grpc-ecosystem/grpc-gateway v1.9.4/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI= +golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0 h1:9sdfJOzWlkqPltHAuzT2Cp+yrBeY1KRVYgms8soxMwM= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610 h1:Ygq9/SRJX9+dU0WCIICM8RkWvDw03lvB77hrhJnpxfU= +google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.22.0 h1:J0UbZOIrCAl+fpTOf8YLs4dJo8L/owV4LYVtAXQoPkw= +google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/tracing/opencensus/opencensus.go b/tracing/opencensus/opencensus.go new file mode 100644 index 000000000..274ec9555 --- /dev/null +++ b/tracing/opencensus/opencensus.go @@ -0,0 +1,180 @@ +package opencensus + +// Copyright 2018 Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import ( + "context" + "fmt" + "net/http" + "os" + + "contrib.go.opencensus.io/exporter/ocagent" + "github.com/Azure/go-autorest/tracing" + "go.opencensus.io/plugin/ochttp" + "go.opencensus.io/plugin/ochttp/propagation/tracecontext" + "go.opencensus.io/stats/view" + "go.opencensus.io/trace" +) + +func init() { + enableFromEnv() +} + +// split out for testing purposes +func enableFromEnv() { + if _, ok := os.LookupEnv("AZURE_SDK_TRACING_ENABLED"); ok { + agentEndpoint, ok := os.LookupEnv("OCAGENT_TRACE_EXPORTER_ENDPOINT") + if ok { + EnableWithAIForwarding(agentEndpoint) + } else { + Enable() + } + } +} + +var defaultTracer = newocTracer() + +type ocTracer struct { + // Sampler is the tracing sampler. If tracing is disabled it will never sample. Otherwise + // it will be using the parent sampler or the default. + sampler trace.Sampler + + // Views for metric instrumentation. + views map[string]*view.View + + // the trace exporter + traceExporter trace.Exporter +} + +func newocTracer() *ocTracer { + return &ocTracer{ + sampler: trace.NeverSample(), + views: map[string]*view.View{}, + } +} + +// NewTransport returns a new instance of a tracing-aware RoundTripper. +func (oct ocTracer) NewTransport(base *http.Transport) http.RoundTripper { + return &ochttp.Transport{ + Base: base, + Propagation: &tracecontext.HTTPFormat{}, + GetStartOptions: func(*http.Request) trace.StartOptions { + return trace.StartOptions{ + Sampler: oct.sampler, + } + }, + } +} + +// StartSpan starts a trace span +func (oct ocTracer) StartSpan(ctx context.Context, name string) context.Context { + ctx, _ = trace.StartSpan(ctx, name, trace.WithSampler(oct.sampler)) + return ctx +} + +// EndSpan ends a previously started span stored in the context +func (oct ocTracer) EndSpan(ctx context.Context, httpStatusCode int, err error) { + span := trace.FromContext(ctx) + + if span == nil { + return + } + + if err != nil { + span.SetStatus(trace.Status{Message: err.Error(), Code: toTraceStatusCode(httpStatusCode)}) + } + span.End() +} + +// Enable will start instrumentation for metrics and traces. +func Enable() error { + defaultTracer.sampler = nil + + // register the views for HTTP metrics + clientViews := []*view.View{ + ochttp.ClientCompletedCount, + ochttp.ClientRoundtripLatencyDistribution, + ochttp.ClientReceivedBytesDistribution, + ochttp.ClientSentBytesDistribution, + } + for _, cv := range clientViews { + vn := fmt.Sprintf("Azure/go-autorest/tracing/opencensus-%s", cv.Name) + defaultTracer.views[vn] = cv.WithName(vn) + err := view.Register(defaultTracer.views[vn]) + if err != nil { + return err + } + } + tracing.Register(defaultTracer) + return nil +} + +// Disable will disable instrumentation for metrics and traces. +func Disable() { + // unregister any previously registered metrics + for _, v := range defaultTracer.views { + view.Unregister(v) + } + defaultTracer.sampler = trace.NeverSample() + if defaultTracer.traceExporter != nil { + trace.UnregisterExporter(defaultTracer.traceExporter) + } + tracing.Register(nil) +} + +// EnableWithAIForwarding will start instrumentation and will connect to app insights forwarder +// exporter making the metrics and traces available in app insights. +func EnableWithAIForwarding(agentEndpoint string) error { + err := Enable() + if err != nil { + return err + } + + defaultTracer.traceExporter, err = ocagent.NewExporter(ocagent.WithInsecure(), ocagent.WithAddress(agentEndpoint)) + if err != nil { + return err + } + trace.RegisterExporter(defaultTracer.traceExporter) + return nil +} + +// toTraceStatusCode converts HTTP Codes to OpenCensus codes as defined +// at https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/HTTP.md#status +func toTraceStatusCode(httpStatusCode int) int32 { + switch { + case http.StatusOK <= httpStatusCode && httpStatusCode < http.StatusBadRequest: + return trace.StatusCodeOK + case httpStatusCode == http.StatusBadRequest: + return trace.StatusCodeInvalidArgument + case httpStatusCode == http.StatusUnauthorized: // 401 is actually unauthenticated. + return trace.StatusCodeUnauthenticated + case httpStatusCode == http.StatusForbidden: + return trace.StatusCodePermissionDenied + case httpStatusCode == http.StatusNotFound: + return trace.StatusCodeNotFound + case httpStatusCode == http.StatusTooManyRequests: + return trace.StatusCodeResourceExhausted + case httpStatusCode == 499: + return trace.StatusCodeCancelled + case httpStatusCode == http.StatusNotImplemented: + return trace.StatusCodeUnimplemented + case httpStatusCode == http.StatusServiceUnavailable: + return trace.StatusCodeUnavailable + case httpStatusCode == http.StatusGatewayTimeout: + return trace.StatusCodeDeadlineExceeded + default: + return trace.StatusCodeUnknown + } +} diff --git a/tracing/opencensus/opencensus_test.go b/tracing/opencensus/opencensus_test.go new file mode 100644 index 000000000..251468445 --- /dev/null +++ b/tracing/opencensus/opencensus_test.go @@ -0,0 +1,161 @@ +package opencensus + +// Copyright 2018 Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import ( + "context" + "fmt" + "net/http" + "os" + "reflect" + "testing" + + "contrib.go.opencensus.io/exporter/ocagent" + "github.com/Azure/go-autorest/tracing" + "go.opencensus.io/plugin/ochttp" + "go.opencensus.io/stats/view" + "go.opencensus.io/trace" +) + +func TestNoTracingByDefault(t *testing.T) { + if expected, got := false, tracing.IsEnabled(); expected != got { + t.Fatalf("By default expected %t, got %t", expected, got) + } + + if defaultTracer == nil { + t.Fatal("unexpected nil defaultTracer") + } + + if defaultTracer.sampler == nil { + t.Fatal("By default expected non nil sampler") + } + + if tr := defaultTracer.NewTransport(nil); tr.(*ochttp.Transport).GetStartOptions(&http.Request{}).Sampler == nil { + t.Fatalf("By default expected configured Sampler to be non-nil") + } + + for n := range defaultTracer.views { + v := view.Find(n) + if v != nil { + t.Fatalf("By default expected no registered views, found %s", v.Name) + } + } +} + +func TestEnableTracing(t *testing.T) { + err := Enable() + + if err != nil { + t.Fatalf("Enable failed, got error %v", err) + } + if e := tracing.IsEnabled(); !e { + t.Fatalf("Enable failed, IsEnabled() is %t", e) + } + if defaultTracer.sampler != nil { + t.Fatalf("Enable failed, expected nil sampler, got %v", defaultTracer.sampler) + } + + if tr := tracing.NewTransport(nil); tr.(*ochttp.Transport).GetStartOptions(&http.Request{}).Sampler != nil { + t.Fatalf("Enable failed, expected Transport.GetStartOptions.Sampler to be nil") + } + + for n, v := range defaultTracer.views { + fv := view.Find(n) + if fv == nil || !reflect.DeepEqual(v, fv) { + t.Fatalf("Enable failed, view %s was not registered", n) + } + } +} + +func TestTracingByEnv(t *testing.T) { + os.Setenv("AZURE_SDK_TRACING_ENABLED", "") + enableFromEnv() + if e := tracing.IsEnabled(); !e { + t.Fatalf("Enable failed, IsEnabled() is %t", e) + } + if defaultTracer.sampler != nil { + t.Fatalf("Enable failed, expected nil sampler, got %v", defaultTracer.sampler) + } + + if tr := tracing.NewTransport(nil); tr.(*ochttp.Transport).GetStartOptions(&http.Request{}).Sampler != nil { + t.Fatalf("Enable failed, expected Transport.GetStartOptions.Sampler to be nil") + } + + for n, v := range defaultTracer.views { + fv := view.Find(n) + if fv == nil || !reflect.DeepEqual(v, fv) { + t.Fatalf("Enable failed, view %s was not registered", n) + } + } +} + +func TestEnableTracingWithAIError(t *testing.T) { + agentEndpoint := fmt.Sprintf("%s:%d", ocagent.DefaultAgentHost, ocagent.DefaultAgentPort) + if err := EnableWithAIForwarding(agentEndpoint); err != nil { + // note that even though the agent isn't running no error is + // returned, the exporter's state is simply set to disconnected. + t.Fatalf("EnableWithAIForwarding failed: %v", err) + } + if e := tracing.IsEnabled(); !e { + t.Fatalf("Enable failed, IsEnabled() is %t", e) + } + if defaultTracer.sampler != nil { + t.Fatalf("Enable failed, expected nil sampler, got %v", defaultTracer.sampler) + } + + if tr := tracing.NewTransport(nil); tr.(*ochttp.Transport).GetStartOptions(&http.Request{}).Sampler != nil { + t.Fatalf("Enable failed, expected Transport.GetStartOptions.Sampler to be nil") + } + + for n, v := range defaultTracer.views { + fv := view.Find(n) + if fv == nil || !reflect.DeepEqual(v, fv) { + t.Fatalf("Enable failed, view %s was not registered", n) + } + } +} + +func TestDisableTracing(t *testing.T) { + Enable() + Disable() + if expected, got := false, tracing.IsEnabled(); expected != got { + t.Fatalf("By default expected %t, got %t", expected, got) + } + + if defaultTracer.sampler == nil { + t.Fatal("By default expected non nil sampler") + } + + if tr := defaultTracer.NewTransport(nil); tr.(*ochttp.Transport).GetStartOptions(&http.Request{}).Sampler == nil { + t.Fatalf("By default expected configured Sampler to be non-nil") + } + + for n := range defaultTracer.views { + v := view.Find(n) + if v != nil { + t.Fatalf("By default expected no registered views, found %s", v.Name) + } + } +} + +func TestStartSpan(t *testing.T) { + ctx := defaultTracer.StartSpan(context.Background(), "testSpan") + defer defaultTracer.EndSpan(ctx, 200, nil) + + span := trace.FromContext(ctx) + if span == nil { + t.Fatal("StartSpan failed, expected non-nil span") + } +} diff --git a/tracing/tracing.go b/tracing/tracing.go index 28951c284..0e7a6e962 100644 --- a/tracing/tracing.go +++ b/tracing/tracing.go @@ -16,180 +16,52 @@ package tracing import ( "context" - "fmt" "net/http" - "os" - - "contrib.go.opencensus.io/exporter/ocagent" - "go.opencensus.io/plugin/ochttp" - "go.opencensus.io/plugin/ochttp/propagation/tracecontext" - "go.opencensus.io/stats/view" - "go.opencensus.io/trace" -) - -var ( - // Transport is the default tracing RoundTripper. The custom options setter will control - // if traces are being emitted or not. - Transport = NewTransport() - - // enabled is the flag for marking if tracing is enabled. - enabled = false - - // Sampler is the tracing sampler. If tracing is disabled it will never sample. Otherwise - // it will be using the parent sampler or the default. - sampler = trace.NeverSample() - - // Views for metric instrumentation. - views = map[string]*view.View{} - - // the trace exporter - traceExporter trace.Exporter ) -func init() { - enableFromEnv() +// Tracer represents an HTTP tracing facility. +type Tracer interface { + NewTransport(base *http.Transport) http.RoundTripper + StartSpan(ctx context.Context, name string) context.Context + EndSpan(ctx context.Context, httpStatusCode int, err error) } -func enableFromEnv() { - _, ok := os.LookupEnv("AZURE_SDK_TRACING_ENABLED") - _, legacyOk := os.LookupEnv("AZURE_SDK_TRACING_ENABELD") - if ok || legacyOk { - agentEndpoint, ok := os.LookupEnv("OCAGENT_TRACE_EXPORTER_ENDPOINT") - - if ok { - EnableWithAIForwarding(agentEndpoint) - } else { - Enable() - } - } -} +var ( + tracer Tracer +) -// NewTransport returns a new instance of a tracing-aware RoundTripper. -func NewTransport() *ochttp.Transport { - return &ochttp.Transport{ - Propagation: &tracecontext.HTTPFormat{}, - GetStartOptions: getStartOptions, - } +// Register will register the provided Tracer. Pass nil to unregister a Tracer. +func Register(t Tracer) { + tracer = t } -// IsEnabled returns true if monitoring is enabled for the sdk. +// IsEnabled returns true if a Tracer has been registered. func IsEnabled() bool { - return enabled -} - -// Enable will start instrumentation for metrics and traces. -func Enable() error { - enabled = true - sampler = nil - - err := initStats() - return err + return tracer != nil } -// Disable will disable instrumentation for metrics and traces. -func Disable() { - disableStats() - sampler = trace.NeverSample() - if traceExporter != nil { - trace.UnregisterExporter(traceExporter) +// NewTransport creates a new instrumenting http.RoundTripper for the +// registered Tracer. If no Tracer has been registered it returns nil. +func NewTransport(base *http.Transport) http.RoundTripper { + if tracer != nil { + return tracer.NewTransport(base) } - enabled = false + return nil } -// EnableWithAIForwarding will start instrumentation and will connect to app insights forwarder -// exporter making the metrics and traces available in app insights. -func EnableWithAIForwarding(agentEndpoint string) (err error) { - err = Enable() - if err != nil { - return err - } - - traceExporter, err := ocagent.NewExporter(ocagent.WithInsecure(), ocagent.WithAddress(agentEndpoint)) - if err != nil { - return err - } - trace.RegisterExporter(traceExporter) - return -} - -// getStartOptions is the custom options setter for the ochttp package. -func getStartOptions(*http.Request) trace.StartOptions { - return trace.StartOptions{ - Sampler: sampler, - } -} - -// initStats registers the views for the http metrics -func initStats() (err error) { - clientViews := []*view.View{ - ochttp.ClientCompletedCount, - ochttp.ClientRoundtripLatencyDistribution, - ochttp.ClientReceivedBytesDistribution, - ochttp.ClientSentBytesDistribution, - } - for _, cv := range clientViews { - vn := fmt.Sprintf("Azure/go-autorest/tracing-%s", cv.Name) - views[vn] = cv.WithName(vn) - err = view.Register(views[vn]) - if err != nil { - return err - } - } - return -} - -// disableStats will unregister the previously registered metrics -func disableStats() { - for _, v := range views { - view.Unregister(v) - } -} - -// StartSpan starts a trace span +// StartSpan starts a trace span with the specified name, associating it with the +// provided context. Has no effect if a Tracer has not been registered. func StartSpan(ctx context.Context, name string) context.Context { - ctx, _ = trace.StartSpan(ctx, name, trace.WithSampler(sampler)) + if tracer != nil { + return tracer.StartSpan(ctx, name) + } return ctx } -// EndSpan ends a previously started span stored in the context +// EndSpan ends a previously started span stored in the context. +// Has no effect if a Tracer has not been registered. func EndSpan(ctx context.Context, httpStatusCode int, err error) { - span := trace.FromContext(ctx) - - if span == nil { - return - } - - if err != nil { - span.SetStatus(trace.Status{Message: err.Error(), Code: toTraceStatusCode(httpStatusCode)}) - } - span.End() -} - -// toTraceStatusCode converts HTTP Codes to OpenCensus codes as defined -// at https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/HTTP.md#status -func toTraceStatusCode(httpStatusCode int) int32 { - switch { - case http.StatusOK <= httpStatusCode && httpStatusCode < http.StatusBadRequest: - return trace.StatusCodeOK - case httpStatusCode == http.StatusBadRequest: - return trace.StatusCodeInvalidArgument - case httpStatusCode == http.StatusUnauthorized: // 401 is actually unauthenticated. - return trace.StatusCodeUnauthenticated - case httpStatusCode == http.StatusForbidden: - return trace.StatusCodePermissionDenied - case httpStatusCode == http.StatusNotFound: - return trace.StatusCodeNotFound - case httpStatusCode == http.StatusTooManyRequests: - return trace.StatusCodeResourceExhausted - case httpStatusCode == 499: - return trace.StatusCodeCancelled - case httpStatusCode == http.StatusNotImplemented: - return trace.StatusCodeUnimplemented - case httpStatusCode == http.StatusServiceUnavailable: - return trace.StatusCodeUnavailable - case httpStatusCode == http.StatusGatewayTimeout: - return trace.StatusCodeDeadlineExceeded - default: - return trace.StatusCodeUnknown + if tracer != nil { + tracer.EndSpan(ctx, httpStatusCode, err) } } diff --git a/tracing/tracing_test.go b/tracing/tracing_test.go index 66f6ae59a..15c982c1f 100644 --- a/tracing/tracing_test.go +++ b/tracing/tracing_test.go @@ -16,140 +16,56 @@ package tracing import ( "context" - "fmt" "net/http" - "os" - "reflect" "testing" - - "contrib.go.opencensus.io/exporter/ocagent" - "go.opencensus.io/stats/view" - "go.opencensus.io/trace" ) -func TestNoTracingByDefault(t *testing.T) { - if expected, got := false, IsEnabled(); expected != got { - t.Fatalf("By default expected %t, got %t", expected, got) +func TestDisabled(t *testing.T) { + if IsEnabled() { + t.Fatal("unexpected enabled tracing") } - - if sampler == nil { - t.Fatal("By default expected non nil sampler") + if tr := NewTransport(&http.Transport{}); tr != nil { + t.Fatal("unexpected non-nil transport") } - - if Transport.GetStartOptions(&http.Request{}).Sampler == nil { - t.Fatalf("By default expected configured Sampler to be non-nil") - } - - for n := range views { - v := view.Find(n) - if v != nil { - t.Fatalf("By default expected no registered views, found %s", v.Name) - } + if ctx := StartSpan(context.Background(), "foo"); ctx != context.Background() { + t.Fatal("contexts don't match") } } -func TestEnableTracing(t *testing.T) { - err := Enable() - - if err != nil { - t.Fatalf("Enable failed, got error %v", err) - } +func TestEnabled(t *testing.T) { + mt := mockTracer{} + Register(&mt) if !IsEnabled() { - t.Fatalf("Enable failed, IsEnabled() is %t", IsEnabled()) + t.Fatal("unexpected disabled tracing") } - if sampler != nil { - t.Fatalf("Enable failed, expected nil sampler, got %v", sampler) + if tr := NewTransport(&http.Transport{}); tr != http.DefaultTransport { + t.Fatal("didn't receive expected transport") } - - if Transport.GetStartOptions(&http.Request{}).Sampler != nil { - t.Fatalf("Enable failed, expected Transport.GetStartOptions.Sampler to be nil") + ctx := StartSpan(context.Background(), "foo") + v := ctx.Value(mockTracer{}) + if val, ok := v.(string); !ok { + t.Fatal("unexpected value type") + } else if val != "foo" { + t.Fatal("unexpected value") } - - for n, v := range views { - fv := view.Find(n) - if fv == nil || !reflect.DeepEqual(v, fv) { - t.Fatalf("Enable failed, view %s was not registered", n) - } + EndSpan(ctx, http.StatusOK, nil) + if !mt.ended { + t.Fatal("EndSpan didn't forward call to registered tracer") } } -func TestTracingByEnv(t *testing.T) { - os.Setenv("AZURE_SDK_TRACING_ENABLED", "") - enableFromEnv() - if !IsEnabled() { - t.Fatalf("Enable failed, IsEnabled() is %t", IsEnabled()) - } - if sampler != nil { - t.Fatalf("Enable failed, expected nil sampler, got %v", sampler) - } - - if Transport.GetStartOptions(&http.Request{}).Sampler != nil { - t.Fatalf("Enable failed, expected Transport.GetStartOptions.Sampler to be nil") - } - - for n, v := range views { - fv := view.Find(n) - if fv == nil || !reflect.DeepEqual(v, fv) { - t.Fatalf("Enable failed, view %s was not registered", n) - } - } +type mockTracer struct { + ended bool } -func TestEnableTracingWithAIError(t *testing.T) { - agentEndpoint := fmt.Sprintf("%s:%d", ocagent.DefaultAgentHost, ocagent.DefaultAgentPort) - err := EnableWithAIForwarding(agentEndpoint) - if !IsEnabled() { - t.Fatalf("Enable failed, IsEnabled() is %t", IsEnabled()) - } - if sampler != nil { - t.Fatalf("Enable failed, expected nil sampler, got %v", sampler) - } - - if Transport.GetStartOptions(&http.Request{}).Sampler != nil { - t.Fatalf("Enable failed, expected Transport.GetStartOptions.Sampler to be nil") - } - - for n, v := range views { - fv := view.Find(n) - if fv == nil || !reflect.DeepEqual(v, fv) { - t.Fatalf("Enable failed, view %s was not registered", n) - } - } - - if err == nil { - t.Fatal("Expected error on no agent running, got nil") - } +func (m mockTracer) NewTransport(base *http.Transport) http.RoundTripper { + return http.DefaultTransport } -func TestDisableTracing(t *testing.T) { - Enable() - Disable() - if expected, got := false, IsEnabled(); expected != got { - t.Fatalf("By default expected %t, got %t", expected, got) - } - - if sampler == nil { - t.Fatal("By default expected non nil sampler") - } - - if Transport.GetStartOptions(&http.Request{}).Sampler == nil { - t.Fatalf("By default expected configured Sampler to be non-nil") - } - - for n := range views { - v := view.Find(n) - if v != nil { - t.Fatalf("By default expected no registered views, found %s", v.Name) - } - } +func (m mockTracer) StartSpan(ctx context.Context, name string) context.Context { + return context.WithValue(ctx, mockTracer{}, name) } -func TestStartSpan(t *testing.T) { - ctx := StartSpan(context.Background(), "testSpan") - defer EndSpan(ctx, 200, nil) - - span := trace.FromContext(ctx) - if span == nil { - t.Fatal("StartSpan failed, expected non-nil span") - } +func (m *mockTracer) EndSpan(ctx context.Context, httpStatusCode int, err error) { + m.ended = true }