observability

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package observability provides minimal-overhead OpenTelemetry bootstrap with a strict split between DEV (stdout+sync) and PROD (OTLP+batch). - DEV (exporter=stdout): WithSyncer(exp) prints immediately on span.End(). - PROD (exporter=grpc|http): WithBatcher(exp, ...) to reduce I/O overhead. Hot path remains lean: a single atomic toggle + dynamic Tracer fetch. No schema conflicts: resource is schemaless (plain attributes).

Index

Constants

View Source
const (
	AttrHTTPPathKey = "http.path"
	AttrHTTPRequest = "http.request"
	AttrReqID       = "http.request_id"
	AttrReqGUID     = "http.request_guid"

	AttrHTTPStatusCodeKey   = "http.status_code"
	AttrHTTPResponseSizeKey = "http.response_size"

	AttrCacheProxy = "cache.proxy"
	AttrCacheHit   = "cache.hit"
	AttrCacheKey   = "cache.key"

	AttrXTenantScope = "X_Scope_OTEL_Tenant"
)
View Source
const (
	XRequestIDHeader   = "X-Request-Id"
	XRequestGUIDHeader = "X-Request-Guid"
)

Variables

View Source
var (
	ErrExporterNotDefined = errors.New("exporter not defined")
	ErrEndpointEmpty      = errors.New("endpoint is empty for selected exporter")
	ErrServiceNameEmpty   = errors.New("service name is empty")
)

Functions

func Apply

func Apply(ctx context.Context, cfg *config.Observability) func(context.Context) error

Apply (re)installs a TracerProvider based on cfg and returns its shutdown func. - When disabled: installs a tiny provider with NeverSample (fast noop). - When enabled: stdout -> WithSyncer; grpc/http -> WithBatcher. It hot-swaps providers atomically and gracefully shuts down the previous one.

func DisableTracing

func DisableTracing()

func EnableTracing

func EnableTracing()

func Extract

func Extract(rCtx *fasthttp.RequestCtx) context.Context

Extract pulls trace context from incoming request headers.

func Inject

func Inject(parentTraceCtx context.Context, req *fasthttp.Request)

Inject writes trace context into outgoing upstream request headers.

func IsActiveTracing

func IsActiveTracing() bool

IsActiveTracing returns a fast-path toggle for hot code.

func SafeSetString

func SafeSetString(sp trace.Span, key, val string)

SafeSetString avoids work when span is not recording.

func SetBoolAttr

func SetBoolAttr(sp trace.Span, key string, v bool)

func SetBytesAttr

func SetBytesAttr(sp trace.Span, key string, b []byte)

func SetIntAttr

func SetIntAttr(sp trace.Span, key string, v int)

SetIntAttr avoids work when span is not recording.

func Start

func Start(ctx context.Context, name string, kind trace.SpanKind) (context.Context, trace.Span, func(...trace.SpanEndOption))

Start returns (ctx, span, endFn) with minimal overhead. It dynamically fetches a Tracer from the CURRENT global provider, avoiding stale (noop) tracers and eliminating global caches.

Types

This section is empty.

Jump to

Keyboard shortcuts

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