tracing

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tracing follows a request across nodes with OpenTelemetry.

Every request gets a W3C trace id: it is logged, returned to the client and passed on to the nodes the request reaches. Spans are only recorded and exported over OTLP/HTTP when tracing is enabled.

Index

Constants

View Source
const (
	// TraceIDHeader returns the trace id to the client.
	TraceIDHeader = "X-Trace-Id"
)

Variables

This section is empty.

Functions

func Extract

func Extract(ctx context.Context, header func(string) string) context.Context

Extract continues the trace the caller sent in its headers.

func SetStatus

func SetStatus(span trace.Span, code int)

SetStatus records an HTTP status code on span, 5xx marks it failed.

func Start

func Start(ctx context.Context, cfg Config) (func(context.Context) error, error)

Start sets up tracing, it must run before the server serves requests. The returned function flushes buffered spans on shutdown.

func TraceID

func TraceID(ctx context.Context) string

TraceID returns the trace id of ctx, empty when there is none.

func Tracer

func Tracer() trace.Tracer

Tracer creates the spans of this process.

func Transport

func Transport(base http.RoundTripper) http.RoundTripper

Transport traces the requests sent to other nodes: one client span per request, ended when the response body is closed, and the trace context in the request headers. A nil base uses http.DefaultTransport.

Types

type Config

type Config struct {
	// Enable records and exports spans.
	Enable bool
	// Endpoint is the full OTLP/HTTP traces URL, e.g.
	// http://localhost:4318/v1/traces. Empty uses the
	// OTEL_EXPORTER_OTLP_* environment, then localhost:4318.
	Endpoint string
	// Service and Version name this process, Node tells cluster nodes apart.
	Service, Version, Node string
}

Config selects where spans go.

type Hook

type Hook struct{}

Hook adds the trace id to log events given a context with Event.Ctx.

func (Hook) Run

func (Hook) Run(e *zerolog.Event, _ zerolog.Level, _ string)

Jump to

Keyboard shortcuts

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