component-basek8s.io/component-base/tracing Index | Files | Directories

package tracing

import "k8s.io/component-base/tracing"

Index

Functions

func ContextWithSpan

func ContextWithSpan(ctx context.Context, s *Span) context.Context

ContextWithSpan returns a context with the Span included in the context.

func Propagators

func Propagators() propagation.TextMapPropagator

Propagators returns the recommended set of propagators.

func WithTracing

func WithTracing(handler http.Handler, tp oteltrace.TracerProvider, spanName string) http.Handler

WithTracing adds tracing to requests if the incoming request is sampled

func WrapperFor

WrapperFor can be used to add tracing to a *rest.Config. Example usage: tp := NewProvider(...) config, _ := rest.InClusterConfig() config.Wrap(WrapperFor(tp)) kubeclient, _ := clientset.NewForConfig(config)

Types

type Span

type Span struct {
	// contains filtered or unexported fields
}

Span is a component part of a trace. It represents a single named and timed operation of a workflow being observed. This Span is a combination of an OpenTelemetry and k8s.io/utils/trace span to facilitate the migration to OpenTelemetry.

func SpanFromContext

func SpanFromContext(ctx context.Context) *Span

SpanFromContext returns the *Span from the current context. It is composed of the active OpenTelemetry and k8s.io/utils/trace spans.

func Start

func Start(ctx context.Context, name string, attributes ...attribute.KeyValue) (context.Context, *Span)

Start creates spans using both OpenTelemetry, and the k8s.io/utils/trace package. It only creates an OpenTelemetry span if the incoming context already includes a span.

func (*Span) AddEvent

func (s *Span) AddEvent(name string, attributes ...attribute.KeyValue)

AddEvent adds a point-in-time event with a name and attributes.

func (*Span) End

func (s *Span) End(logThreshold time.Duration)

End ends the span, and logs if the span duration is greater than the logThreshold.

func (*Span) RecordError

func (s *Span) RecordError(err error, attributes ...attribute.KeyValue)

RecordError will record err as an exception span event for this span. If this span is not being recorded or err is nil then this method does nothing.

type TracerProvider

type TracerProvider interface {
	oteltrace.TracerProvider
	Shutdown(context.Context) error
}

TracerProvider is an OpenTelemetry TracerProvider which can be shut down

func NewNoopTracerProvider

func NewNoopTracerProvider() TracerProvider

func NewProvider

func NewProvider(ctx context.Context,
	tracingConfig *v1.TracingConfiguration,
	addedOpts []otlptracegrpc.Option,
	resourceOpts []resource.Option,
) (TracerProvider, error)

NewProvider creates a TracerProvider in a component, and enforces recommended tracing behavior

Source Files

tracing.go utils.go

Directories

PathSynopsis
tracing/api
tracing/api/v1
Version
v0.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
15 packages
Last checked
12 hours ago

Tools for package owners.