Documentation
¶
Overview ¶
Package otelhttptrace provides instrumentation for the net/http/httptrace package.
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 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.
const Version = "0.69.0"
Version is the current release version of the httptrace instrumentation.
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)
}),
),
}
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "https://example.com", http.NoBody)
if err != nil {
fmt.Println(err)
return
}
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
fmt.Println(resp.Status)
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.
This option is recommended for services that make a large number of outbound HTTP requests per incoming request (e.g., API gateways, fan-out proxies, or GraphQL servers). Each outbound request creates up to 7 sub-spans (http.getconn, http.dns, http.connect, http.tls, http.headers, http.send, http.receive) as separate heap-allocated trace.Span objects. In high fan-out services this multiplied span volume can overwhelm the span processor queue and increase GC pressure, resulting in elevated and continuously growing memory usage. Using WithoutSubSpans replaces those spans with lightweight events on the parent span, preserving the diagnostic information at a fraction of the cost.
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
example
module
|
|
|
internal
|
|
|
semconv
Package semconv provides OpenTelemetry semantic convention types and functionality.
|
Package semconv provides OpenTelemetry semantic convention types and functionality. |
|
semconv/test
module
|
|
|
test
module
|