otelhttptrace

package module
v0.57.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 15 Imported by: 130

Documentation

Index

Examples

Constants

View Source
const ScopeName = "go.opentelemetry.io/otel/instrumentation/httptrace"

ScopeName is the instrumentation scope name.

Variables

View Source
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

Extract returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.

func Inject

func Inject(ctx context.Context, req *http.Request, opts ...Option)

Inject sets attributes, context entries, and span context from ctx into the request.

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

func SemVersion() string

SemVersion is the semantic version to be supplied to tracer/meter creation.

Deprecated: Use Version instead.

func Version added in v0.24.0

func Version() string

Version is the current release version of the httptrace instrumentation.

func W3C

W3C client.

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.

Directories

Path Synopsis
example module
internal
test module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL