telemetry

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package telemetry is the framework's OpenTelemetry integration.

The framework instruments execution boundaries, not business code: HTTP requests, scheduled jobs, queue attempts, and event handlers. Business code can use Start or Run for any function and gets the same provider, propagator, resource, error recording, and shutdown behavior.

Exporters remain pluggable. Services may provide any OpenTelemetry SDK exporter through Config, or supply their own providers when they need more advanced sampling, views, or multiple pipelines.

Index

Constants

View Source
const InstrumentationName = "github.com/IncepTools/go"

InstrumentationName is the stable scope used by framework spans and meters.

Variables

This section is empty.

Functions

func Extract

Extract reads a propagated span context from an inbound carrier.

func Inject

func Inject(ctx context.Context, carrier propagation.TextMapCarrier)

Inject writes the current span context into an outbound carrier. Use it for HTTP, messaging, or any other transport that supports a text map.

func RecordError

func RecordError(span trace.Span, err error)

RecordError applies the OpenTelemetry error convention. Cancellation during a normal shutdown is not marked as an application failure.

func Run

func Run(ctx context.Context, name string, fn func(context.Context) error, attrs ...attribute.KeyValue) error

Run traces one arbitrary execution and records a returned error on the span.

func Start

func Start(ctx context.Context, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

Start starts a span in the framework instrumentation scope.

Types

type Config

type Config struct {
	ServiceName    string
	ServiceVersion string
	// OTLP enables the standard OTLP/HTTP exporters when an endpoint is
	// configured explicitly or through OTEL_EXPORTER_OTLP_* environment
	// variables. It is deliberately opt-in by endpoint: New never attempts to
	// connect to localhost just because telemetry was enabled.
	OTLP           OTLPConfig
	SpanExporter   sdktrace.SpanExporter
	MetricReader   sdkmetric.Reader
	TracerProvider trace.TracerProvider
	MeterProvider  metric.MeterProvider
	Propagator     propagation.TextMapPropagator
}

Config configures the built-in providers. SpanExporter and MetricReader are optional SDK hooks; custom providers take precedence when supplied.

type OTLPConfig

type OTLPConfig struct {
	Endpoint        string
	TracesEndpoint  string
	MetricsEndpoint string
	Headers         map[string]string
	Insecure        bool
	Timeout         time.Duration
}

OTLPConfig is the small, vendor-neutral configuration surface shared by SigNoz, an OpenTelemetry Collector, Elastic APM, Jaeger, Grafana, Honeycomb, and other OTLP-compatible backends. Signal-specific endpoints override the common endpoint. Standard OTEL_* environment variables are also honored by the exporters.

type Telemetry

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

Telemetry owns providers created by New and flushes them during shutdown.

func New

func New(cfg Config) (*Telemetry, error)

New creates providers, installs them as the process globals, and returns a lifecycle-ready telemetry component. The default SDK providers are active even without exporters; instrumentation call sites never change when an exporter or backend is added.

func (*Telemetry) Middleware

func (t *Telemetry) Middleware() fiber.Handler

Middleware creates automatic HTTP spans, context extraction, and standard request metrics. It is safe to install alongside the framework request-ID middleware; request IDs remain available to logs while OTel owns trace IDs.

func (*Telemetry) OnShutdown

func (t *Telemetry) OnShutdown(ctx context.Context) error

OnShutdown flushes and closes providers created by New.

Jump to

Keyboard shortcuts

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