otel

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package otel wires OpenTelemetry traces and logs for the MCP server.

OTel is opt-in: if neither CRDB_MCP_OTEL_FILE nor OTEL_EXPORTER_OTLP_ENDPOINT is set, Setup installs no exporters and the global providers stay no-op.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachZapBridge

func AttachZapBridge(logger *zap.Logger, serviceName string) *zap.Logger

AttachZapBridge wraps logger so each record is also exported as an OTel log record via the global LoggerProvider. Call only after Setup returned a non-nil shutdown (i.e. an exporter is actually configured).

func SafeSpanError

func SafeSpanError(err error) error

SafeSpanError strips pgx error Message/Detail/Where fields, which can echo the offending SQL and user data into span events and status descriptions, undermining the query-text redaction applied to span attributes.

Types

type ShutdownFunc

type ShutdownFunc func(context.Context) error

ShutdownFunc flushes and closes any registered exporters.

func Setup

func Setup(
	ctx context.Context, cfg *config.Config, serviceName, serviceVersion string,
) (ShutdownFunc, error)

Setup installs trace and log providers based on cfg:

  • cfg.OTelFile set: stdout exporters write JSON to that file (good for local dev or file-based shippers like Filebeat, Vector).
  • cfg.OTLPEndpoint set: OTLP gRPC exporters honor the standard OTEL_* env vars (Datadog Agent, OTel Collector, Tempo, Honeycomb, ELK).
  • neither set: returns a no-op shutdown and the global providers stay no-op.

File mode takes precedence when both are configured.

Jump to

Keyboard shortcuts

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