aboutsummaryrefslogtreecommitdiff
path: root/vendor/go.opencensus.io/plugin/ochttp/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.opencensus.io/plugin/ochttp/client.go')
-rw-r--r--vendor/go.opencensus.io/plugin/ochttp/client.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/vendor/go.opencensus.io/plugin/ochttp/client.go b/vendor/go.opencensus.io/plugin/ochttp/client.go
index 37f42b3..68faf24 100644
--- a/vendor/go.opencensus.io/plugin/ochttp/client.go
+++ b/vendor/go.opencensus.io/plugin/ochttp/client.go
@@ -16,14 +16,18 @@ package ochttp
import (
"net/http"
+ "net/http/httptrace"
"go.opencensus.io/trace"
"go.opencensus.io/trace/propagation"
)
// Transport is an http.RoundTripper that instruments all outgoing requests with
-// stats and tracing. The zero value is intended to be a useful default, but for
-// now it's recommended that you explicitly set Propagation.
+// OpenCensus stats and tracing.
+//
+// The zero value is intended to be a useful default, but for
+// now it's recommended that you explicitly set Propagation, since the default
+// for this may change.
type Transport struct {
// Base may be set to wrap another http.RoundTripper that does the actual
// requests. By default http.DefaultTransport is used.
@@ -43,17 +47,34 @@ type Transport struct {
// for spans started by this transport.
StartOptions trace.StartOptions
+ // NameFromRequest holds the function to use for generating the span name
+ // from the information found in the outgoing HTTP Request. By default the
+ // name equals the URL Path.
+ FormatSpanName func(*http.Request) string
+
+ // NewClientTrace may be set to a function allowing the current *trace.Span
+ // to be annotated with HTTP request event information emitted by the
+ // httptrace package.
+ NewClientTrace func(*http.Request, *trace.Span) *httptrace.ClientTrace
+
// TODO: Implement tag propagation for HTTP.
}
// RoundTrip implements http.RoundTripper, delegating to Base and recording stats and traces for the request.
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
rt := t.base()
+ if isHealthEndpoint(req.URL.Path) {
+ return rt.RoundTrip(req)
+ }
// TODO: remove excessive nesting of http.RoundTrippers here.
format := t.Propagation
if format == nil {
format = defaultFormat
}
+ spanNameFormatter := t.FormatSpanName
+ if spanNameFormatter == nil {
+ spanNameFormatter = spanNameFromURL
+ }
rt = &traceTransport{
base: rt,
format: format,
@@ -61,6 +82,8 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
Sampler: t.StartOptions.Sampler,
SpanKind: trace.SpanKindClient,
},
+ formatSpanName: spanNameFormatter,
+ newClientTrace: t.NewClientTrace,
}
rt = statsTransport{base: rt}
return rt.RoundTrip(req)