Documentation
¶
Overview ¶
Package instr provides instrumentation utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunSpan ¶
func RunSpan(ctx context.Context, name string, fn func(ctx context.Context, span *Span) error) error
RunSpan will wrap a function with a span to automatically handle error tracking and ending
func SpanLogger ¶
SpanLogger fetches a logger for the supplied span id. This will search up the context for a potential parent id, and properly set all attributes on the found logger.
The base logger used is the default logger from the passed context.
Types ¶
type PrometheusMetrics ¶
type PrometheusMetrics struct {
// contains filtered or unexported fields
}
func NewPrometheusMetrics ¶
func NewPrometheusMetrics(opts ...PrometheusMetricsOpt) (*PrometheusMetrics, error)
NewPrometheusMetrics creates a new prometheus metrics object. This will setup sane default prometheus metrics, with additional configuration with `...PrometheusMetricsOpt`.
func (*PrometheusMetrics) Handler ¶
func (p *PrometheusMetrics) Handler() http.Handler
Handler returns the HTTP handler for this specific instance of the Prometheus metrics registry. If the `WithDefaultRegistry` option was used, then calling `promhttp.Handler()` will return the same handler.
func (*PrometheusMetrics) Middleware ¶
func (p *PrometheusMetrics) Middleware(next http.Handler) http.Handler
Middleware returns an HTTP middleware handler that tracks request count and duration.
func (*PrometheusMetrics) SpanCtx ¶
func (p *PrometheusMetrics) SpanCtx(ctx context.Context, name string, fn func(ctx context.Context, id string) error) error
SpanCtx is an extremely basic span function wrapper to track execution time. This is NOT a replacement for otel, just a simple exercise that may prove useful in certain cases. The function provides the spanId as the argument `id` in the function.
In addition, this function transiently passes the error to the caller ¶
The context will contain a spanID key to track the current span, and if SpanCtx is called within the runtime of another span, the parent span id will be embeded into the span.
type PrometheusMetricsOpt ¶
type PrometheusMetricsOpt func(*PrometheusMetrics) error
func WithCustomRegistry ¶
func WithCustomRegistry(registry *prometheus.Registry) PrometheusMetricsOpt
func WithGlobalRegistry ¶
func WithGlobalRegistry() PrometheusMetricsOpt
func WithNoGoMetrics ¶
func WithNoGoMetrics() PrometheusMetricsOpt
func WithPromMetrics ¶
func WithPromMetrics(m ...prometheus.Collector) PrometheusMetricsOpt
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
func (*Span) End ¶
func (s *Span) End()
End ends the span and observes the underlying prometheus metric
func (*Span) GetDuration ¶
GetDuration returns the current duration of the span in seconds