tracing

package
v1.0.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: 11 Imported by: 0

Documentation

Overview

Package tracing sets up OpenTelemetry tracing for the server and the demo programs from the standard OTEL_* environment variables (design §18.3). The Go SDK never imports it: libraries leave exporter setup to the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enabled

func Enabled(getenv func(string) string) bool

Enabled reports whether an OTLP endpoint is configured and tracing is not switched off. The standard OTEL_SDK_DISABLED=true and OTEL_TRACES_EXPORTER=none win over an endpoint, so an operator can turn tracing off without removing the endpoint from a shared environment.

func ParentOnly

func ParentOnly(next pgx.QueryTracer) pgx.QueryTracer

ParentOnly passes a query to next only when the context already carries a span: queries made for an RPC nest under its span, while the reaper, pruner and depth refresh, which run every second or minute with no job in them, create no traces (design §18.1, decision 2).

func Setup

func Setup(ctx context.Context, getenv func(string) string, serviceName string) (trace.TracerProvider, func(context.Context) error, error)

Setup returns a tracer provider and a shutdown function that flushes buffered spans. Without an OTLP endpoint the provider is a no-op and costs nothing. Otherwise spans go to the endpoint over OTLP/gRPC in batches; the exporter, the sampler (OTEL_TRACES_SAMPLER, default parentbased_always_on) and OTEL_SERVICE_NAME are read from the environment by the OpenTelemetry SDK itself. serviceName is the default when OTEL_SERVICE_NAME is unset.

Types

type LogHandler

type LogHandler struct{ slog.Handler }

LogHandler adds trace_id and span_id to records logged with a context that carries a span, so a log line can be found from its trace and back.

func (LogHandler) Handle

func (h LogHandler) Handle(ctx context.Context, r slog.Record) error

func (LogHandler) WithAttrs

func (h LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (LogHandler) WithGroup

func (h LogHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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