Copyright 2018, OpenCensus Authors 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.

package ochttp

import (
	
	

	
	
)
Transport is an http.RoundTripper that instruments all outgoing requests with 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.
Base may be set to wrap another http.RoundTripper that does the actual requests. By default http.DefaultTransport is used. If base HTTP roundtripper implements CancelRequest, the returned round tripper will be cancelable.
Propagation defines how traces are propagated. If unspecified, a default (currently B3 format) will be used.
StartOptions are applied to the span started by this Transport around each request. StartOptions.SpanKind will always be set to trace.SpanKindClient for spans started by this transport.
GetStartOptions allows to set start options per request. If set, StartOptions is going to be ignored.
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.
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.
TODO: Implement tag propagation for HTTP.
}
RoundTrip implements http.RoundTripper, delegating to Base and recording stats and traces for the request.
func ( *Transport) ( *http.Request) (*http.Response, error) {
	 := .base()
	if isHealthEndpoint(.URL.Path) {
		return .RoundTrip()
TODO: remove excessive nesting of http.RoundTrippers here.
	 := .Propagation
	if  == nil {
		 = defaultFormat
	}
	 := .FormatSpanName
	if  == nil {
		 = spanNameFromURL
	}

	 := .StartOptions
	if .GetStartOptions != nil {
		 = .GetStartOptions()
	}

	 = &traceTransport{
		base:   ,
		format: ,
		startOptions: trace.StartOptions{
			Sampler:  .Sampler,
			SpanKind: trace.SpanKindClient,
		},
		formatSpanName: ,
		newClientTrace: .NewClientTrace,
	}
	 = statsTransport{base: }
	return .RoundTrip()
}

func ( *Transport) () http.RoundTripper {
	if .Base != nil {
		return .Base
	}
	return http.DefaultTransport
}
CancelRequest cancels an in-flight request by closing its connection.
func ( *Transport) ( *http.Request) {
	type  interface {
		(*http.Request)
	}
	if ,  := .base().();  {
		.()
	}