otelx

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package otelx initialises OpenTelemetry traces and metrics over OTLP/gRPC.

p, _ := otelx.New(ctx, otelx.Options{ServiceName: "svc", Traces: true, Metrics: true, Insecure: true})
defer p.Shutdown(ctx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// ServiceName is the logical name of the service, e.g. "pigo".
	// Defaults to "unknown_service" if empty.
	ServiceName string

	// ServiceVersion is the semver string of the service, e.g. "1.2.3".
	ServiceVersion string

	// Traces enables the OTLP gRPC trace exporter.
	Traces bool

	// Metrics enables the OTLP gRPC metrics exporter.
	Metrics bool

	// Insecure disables TLS for the OTLP gRPC connection (useful in dev).
	Insecure bool

	// OTLPEndpoint overrides the OTLP collector endpoint.
	// Defaults to "localhost:4317" when Insecure is true, or the SDK default otherwise.
	// The OTEL_EXPORTER_OTLP_ENDPOINT env var takes precedence over this field.
	OTLPEndpoint string

	// TracerProvider allows injecting a pre-built provider (e.g. for testing).
	// When set, Traces, Metrics and exporter options are ignored.
	TracerProvider trace.TracerProvider

	// MeterProvider allows injecting a pre-built provider (e.g. for testing).
	MeterProvider metric.MeterProvider
}

Options configures the OTel provider.

type PgxTracer

type PgxTracer struct {
	// contains filtered or unexported fields
}

PgxTracer implements pgx.QueryTracer using the Provider's tracer and meter.

func NewPgxTracer

func NewPgxTracer(p *Provider) (*PgxTracer, error)

NewPgxTracer returns a pgx.QueryTracer backed by p.

func (*PgxTracer) RegisterPoolStats

func (t *PgxTracer) RegisterPoolStats(pool *pgxpool.Pool) error

RegisterPoolStats registers async gauge instruments that scrape pgxpool.Stat on every metrics export. Call once after the pool is dialled.

func (*PgxTracer) TraceQueryEnd

func (t *PgxTracer) TraceQueryEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryEndData)

func (*PgxTracer) TraceQueryStart

func (t *PgxTracer) TraceQueryStart(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryStartData) context.Context

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider wraps the SDK trace and meter providers and exposes helpers for creating named tracers and meters. It is safe for concurrent use.

func New

func New(ctx context.Context, opts Options) (*Provider, error)

New initialises a Provider according to opts. Call Shutdown when the process exits to flush pending telemetry.

func (*Provider) ForceFlush

func (p *Provider) ForceFlush(ctx context.Context) error

func (*Provider) Meter

func (p *Provider) Meter(scope string, opts ...metric.MeterOption) metric.Meter

Meter returns a named metric.Meter. scope follows the same convention as Tracer.

func (*Provider) MeterProvider

func (p *Provider) MeterProvider() metric.MeterProvider

MeterProvider returns the underlying metric.MeterProvider.

func (*Provider) Propagator

func (p *Provider) Propagator() propagation.TextMapPropagator

func (*Provider) Resource

func (p *Provider) Resource() *resource.Resource

func (*Provider) Shutdown

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

Shutdown flushes and stops all exporters. It should be called once, typically via defer, before the process exits.

func (*Provider) Tracer

func (p *Provider) Tracer(scope string, opts ...trace.TracerOption) trace.Tracer

Tracer returns a named trace.Tracer. scope is typically the import path of the package that owns the instrumentation, e.g. "github.com/edgeflare/pigo/pkg/pg".

func (*Provider) TracerProvider

func (p *Provider) TracerProvider() trace.TracerProvider

TracerProvider returns the underlying trace.TracerProvider.

Jump to

Keyboard shortcuts

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