tracer

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OtelEnabled = false

OtelEnabled tells if OpenTelemetry tracing was activated. If OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_TRACES_ENDPOINT is set, then tracing is activated automatically. You may set OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG to set the sampling type and fraction. You may fine-tune batch exporting parameters with OTEL_BSP_* environment variables. See also

Functions

func GetOTel

func GetOTel() bool

GetOTel returns if Open Telemetry is enabled. It may be enabled automatically if OTEL_ environment variables are set.

func SetOTel

func SetOTel(enabled bool, tp *sdktrace.TracerProvider)

SetOTel enables/disables Open Telemetry. Tracer provider can be set with an exporter and collector endpoint you need.

func SetOTelGrpc added in v1.7.3

func SetOTelGrpc(target string, fraction float64) error

SetOTelGrpc enables Open Telemetry. Activates trace export to the OTLP gRPC collector target address defined. Port is 4317, unless defined otherwise in provided target string. E.g. "http://localhost:4317".

Fraction tells the fraction of spans to report, unless the parent is sampled.

  • Zero means no sampling.
  • Greater or equal 1 means sampling all the messages.
  • Else the sampling fraction, e.g. 0.01 for 1%.

Types

type Tracer

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

Tracer is a HTTP trace handler of various kinds.

func NewFromRequest

func NewFromRequest(r *http.Request) *Tracer

NewFromRequest creates new tracer object from request. Returns nil if not found.

func NewFromRequestOrRandom

func NewFromRequestOrRandom(r *http.Request) *Tracer

NewFromRequestOrRandom creates new tracer object. If no trace data, then create random. Never returns nil.

Warning: Does not return trace from request context.

func NewFromRequestWithContext added in v1.9.0

func NewFromRequestWithContext(parentCtx context.Context, r *http.Request) *Tracer

NewFromRequestWithContext creates new tracer object from request derived from parentCtx if otel. Returns nil if not found.

func NewRandom

func NewRandom() *Tracer

NewRandom creates a tracer object with random data.

func (*Tracer) IsReceived

func (t *Tracer) IsReceived() bool

IsReceived tells whether trace data was received (parsed from a request) or a random one.

func (*Tracer) SetHeader

func (t *Tracer) SetHeader(headers http.Header)

SetHeader sets request headers according to the trace data. Input headers object must not be nil.

func (*Tracer) Span

func (t *Tracer) Span(r *http.Request) (*http.Request, string, func())

Span spans the existing trace data and puts that into the request. Returns the updated request and a trace string for logging. Does not change the input trace data.

func (*Tracer) SpanID

func (t *Tracer) SpanID() string

SpanID returns the span ID of the trace data.

func (*Tracer) String

func (t *Tracer) String() string

String makes a log string from trace data.

func (*Tracer) TraceID

func (t *Tracer) TraceID() string

TraceID returns the trace ID of the trace data.

Jump to

Keyboard shortcuts

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