Documentation ¶
Index ¶
- Constants
- Variables
- func Extract(ctx context.Context, req *http.Request, opts ...Option) ([]attribute.KeyValue, baggage.Baggage, trace.SpanContext)
- func Inject(ctx context.Context, req *http.Request, opts ...Option)
- func NewClientTrace(ctx context.Context, opts ...ClientTraceOption) *httptrace.ClientTrace
- func SemVersion() stringdeprecated
- func Version() string
- func W3C(ctx context.Context, req *http.Request) (context.Context, *http.Request)
- type ClientTraceOption
- type Option
Examples ¶
Constants ¶
const ScopeName = "go.opentelemetry.io/otel/instrumentation/httptrace"
ScopeName is the instrumentation scope name.
Variables ¶
var ( HTTPStatus = attribute.Key("http.status") HTTPHeaderMIME = attribute.Key("http.mime") HTTPRemoteAddr = attribute.Key("http.remote") HTTPLocalAddr = attribute.Key("http.local") HTTPConnectionReused = attribute.Key("http.conn.reused") HTTPConnectionWasIdle = attribute.Key("http.conn.wasidle") HTTPConnectionIdleTime = attribute.Key("http.conn.idletime") HTTPConnectionStartNetwork = attribute.Key("http.conn.start.network") HTTPConnectionDoneNetwork = attribute.Key("http.conn.done.network") HTTPConnectionDoneAddr = attribute.Key("http.conn.done.addr") HTTPDNSAddrs = attribute.Key("http.dns.addrs") )
HTTP attributes.
Functions ¶
func Extract ¶
func Extract(ctx context.Context, req *http.Request, opts ...Option) ([]attribute.KeyValue, baggage.Baggage, trace.SpanContext)
Extract returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.
func NewClientTrace ¶
func NewClientTrace(ctx context.Context, opts ...ClientTraceOption) *httptrace.ClientTrace
NewClientTrace returns an httptrace.ClientTrace implementation that will record OpenTelemetry spans for requests made by an http.Client. By default several spans will be added to the trace for various stages of a request (dns, connection, tls, etc). Also by default, all HTTP headers will be added as attributes to spans, although several headers will be automatically redacted: Authorization, WWW-Authenticate, Proxy-Authenticate, Proxy-Authorization, Cookie, and Set-Cookie.
Example ¶
client := http.Client{ Transport: otelhttp.NewTransport( http.DefaultTransport, otelhttp.WithClientTrace(func(ctx context.Context) *httptrace.ClientTrace { return NewClientTrace(ctx) }), ), } resp, err := client.Get("https://example.com") if err != nil { fmt.Println(err) return } defer resp.Body.Close() fmt.Println(resp.Status)
Output:
func SemVersion
deprecated
added in
v0.24.0
Types ¶
type ClientTraceOption ¶ added in v0.23.0
type ClientTraceOption interface {
// contains filtered or unexported methods
}
ClientTraceOption allows customizations to how the httptrace.Client collects information.
func WithInsecureHeaders ¶ added in v0.23.0
func WithInsecureHeaders() ClientTraceOption
WithInsecureHeaders will add span attributes for all http headers *INCLUDING* the sensitive headers that are redacted by default. The attribute values will include the raw un-redacted text. This might be useful for debugging authentication related issues, but should not be used for production deployments.
func WithRedactedHeaders ¶ added in v0.23.0
func WithRedactedHeaders(headers ...string) ClientTraceOption
WithRedactedHeaders will be replaced by fixed '****' values for the header names provided. These are in addition to the sensitive headers already redacted by default: Authorization, WWW-Authenticate, Proxy-Authenticate Proxy-Authorization, Cookie, Set-Cookie.
func WithTracerProvider ¶ added in v0.26.0
func WithTracerProvider(provider trace.TracerProvider) ClientTraceOption
WithTracerProvider specifies a tracer provider for creating a tracer. The global provider is used if none is specified.
func WithoutHeaders ¶ added in v0.23.0
func WithoutHeaders() ClientTraceOption
WithoutHeaders will disable adding span attributes for the http headers and values.
func WithoutSubSpans ¶ added in v0.23.0
func WithoutSubSpans() ClientTraceOption
WithoutSubSpans will modify the httptrace.ClientTrace to only collect data as Events and Attributes on a span found in the context. By default sub-spans will be generated.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option allows configuration of the httptrace Extract() and Inject() functions.
func WithPropagators ¶
func WithPropagators(props propagation.TextMapPropagator) Option
WithPropagators sets the propagators to use for Extraction and Injection.