otel

package
v0.0.0-...-4f234ec Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package otel provides a shared, env-driven OpenTelemetry tracing bootstrap for rest-api binaries. It installs a global SDK tracer provider exporting over OTLP, configured through standard OTEL_* environment variables plus bounded batch-processor settings, so the instrumentation libraries already wired throughout the codebase (otelecho, otelhttp, otelgrpc, bunotel, Temporal interceptors) emit real spans.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bootstrap

func Bootstrap(ctx context.Context, enabled bool, serviceNameFallback string) (func(context.Context) error, error)

Bootstrap installs a global OTLP-exporting tracer provider and the OTEL_PROPAGATORS-configured propagator (W3C trace-context by default). Propagation remains active when enabled is false or no OTLP endpoint is configured, allowing non-exporting services to preserve distributed traces. serviceNameFallback is used only when the environment does not provide service.name.

The returned shutdown function flushes pending spans and is always non-nil.

func EndSpan

func EndSpan(span trace.Span, err error)

EndSpan records an error when err is non-nil and ends the span. Intended for use with named returns: defer func() { cotel.EndSpan(span, retErr) }().

func ExporterConfigured

func ExporterConfigured() bool

ExporterConfigured reports whether an OTLP trace exporter endpoint is configured via the standard environment variables. It is intended for binaries whose tracing enablement is entirely environment-driven.

func LoggerWithTrace

func LoggerWithTrace(ctx context.Context, logger zerolog.Logger) zerolog.Logger

LoggerWithTrace returns logger enriched with trace_id/span_id fields when ctx carries a valid span context, enabling log/trace correlation.

func Propagator

func Propagator() propagation.TextMapPropagator

Propagator returns the installed global propagator, or the environment- configured propagator for clients constructed before Bootstrap. Invalid pre-bootstrap configuration is reported through the global OTel error handler and falls back to W3C trace-context propagation.

func RecordError

func RecordError(span trace.Span, err error)

RecordError records err and marks the span as failed without ending it.

func RecordHTTPError

func RecordHTTPError(ctx context.Context, statusCode int)

RecordHTTPError records stable HTTP failure metadata without exporting response messages or internal error details. Server failures mark the span as failed; client failures are recorded as events.

func RecordSuccess

func RecordSuccess(span trace.Span)

RecordSuccess marks a span as successfully completed.

func SetAttribute

func SetAttribute(span trace.Span, attr attribute.KeyValue)

SetAttribute sets an attribute on the span.

func StartSpan

func StartSpan(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartSpan starts a child span using the global TracerProvider; the parent is taken from ctx via its W3C span context, so it works under otelecho, Temporal workers, gRPC handlers — anywhere a context flows. It never returns a nil span: when no provider is installed the returned span is a no-op.

func TracingEnabled

func TracingEnabled() bool

TracingEnabled reports whether Bootstrap successfully installed a tracer provider. Recording-only instrumentation such as database hooks must use this gate. Transport instrumentation must use TransportEnabled so context can cross a service that does not export spans locally.

func TransportEnabled

func TransportEnabled() bool

TransportEnabled reports whether Bootstrap configured transport instrumentation. It remains true when local export is disabled so an intermediate service can still extract and forward incoming trace context.

OTEL_PROPAGATORS=none is asymmetric: without export it disables transport instrumentation entirely, since there is nothing to record or forward. With export it keeps transport instrumentation on so local spans still record, and only injection and extraction are disabled.

Types

This section is empty.

Jump to

Keyboard shortcuts

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