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 ¶
- type Options
- type PgxTracer
- type Provider
- func (p *Provider) ForceFlush(ctx context.Context) error
- func (p *Provider) Meter(scope string, opts ...metric.MeterOption) metric.Meter
- func (p *Provider) MeterProvider() metric.MeterProvider
- func (p *Provider) Propagator() propagation.TextMapPropagator
- func (p *Provider) Resource() *resource.Resource
- func (p *Provider) Shutdown(ctx context.Context) error
- func (p *Provider) Tracer(scope string, opts ...trace.TracerOption) trace.Tracer
- func (p *Provider) TracerProvider() trace.TracerProvider
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 ¶
NewPgxTracer returns a pgx.QueryTracer backed by p.
func (*PgxTracer) RegisterPoolStats ¶
RegisterPoolStats registers async gauge instruments that scrape pgxpool.Stat on every metrics export. Call once after the pool is dialled.
func (*PgxTracer) TraceQueryEnd ¶
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 ¶
New initialises a Provider according to opts. Call Shutdown when the process exits to flush pending telemetry.
func (*Provider) 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) Shutdown ¶
Shutdown flushes and stops all exporters. It should be called once, typically via defer, before the process exits.
func (*Provider) 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.