telemetry

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const ScopeName = "github.com/ingka-group/fastecho/"

ScopeName is the instrumentation scope name for fastecho's own spans.

Variables

This section is empty.

Functions

func SpanFunc

func SpanFunc(ctx context.Context, name string, fn func())

SpanFunc runs fn inside a span named name, for tracing work that has no context.Context to thread. A panic in fn is recorded on the span and re-raised. With tracing off, fn still runs under a no-op span.

func StartSpan

func StartSpan(ctx context.Context, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpan starts a child span named after the calling function (formatted as package.Type.Method, e.g. "forecast.Service.Recompute") and returns the updated context and span; end it with defer span.End(). It uses the fctx-seeded tracer, falling back to the global provider. For a custom name, call SpanFunc or the OTel tracer API directly.

func WrapClient

func WrapClient(c *http.Client) *http.Client

WrapClient decorates c's transport so every request propagates the caller's trace context (via otelhttp) and forwards fctx.RequestID as X-Request-Id. It mutates and returns c; a nil client is allocated. Only the transport changes.

func WrapTransport

func WrapTransport(base http.RoundTripper) http.RoundTripper

WrapTransport wraps base (nil → http.DefaultTransport) with trace-context propagation and X-Request-Id forwarding. Use this when you hold a RoundTripper directly (e.g. instrumenting a generated client). Wrapping an already-wrapped transport is a no-op, so double-wrapping cannot stack duplicate spans.

Types

type Config

type Config struct {
	SkipTraces  bool
	SkipMetrics bool
}

Config carries only wiring that has no env equivalent; behavior values (endpoint, sampling, exporter) come from OTEL_* env so there is one source of truth per setting.

type Providers

type Providers struct {
	TracerProvider trace.TracerProvider
	MeterProvider  metric.MeterProvider
	// PrometheusGatherer is non-nil when OTEL_METRICS_EXPORTER=prometheus; the
	// router serves it at /metrics on the main port. Nil otherwise.
	PrometheusGatherer prometheus.Gatherer
	// contains filtered or unexported fields
}

Providers holds the configured providers and a single shutdown closer.

func Init

func Init(ctx context.Context, cfg Config) (*Providers, error)

Init builds the providers from OTEL_* env and returns them with one shutdown. It registers each provider (and, with tracing, the propagator) as the process-global OTel singleton — but only for enabled signals, so skipping a signal leaves an application's own OTel setup untouched. Call PrintConfiguration to log what it resolved.

func (*Providers) PrintConfiguration

func (p *Providers) PrintConfiguration()

PrintConfiguration prints the resolved telemetry configuration at startup. It reads the exported env (not stored state), so it is safe on any Providers value.

func (*Providers) Shutdown

func (p *Providers) Shutdown(ctx context.Context) error

Shutdown flushes and stops all providers. Nil-safe.

Jump to

Keyboard shortcuts

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