apm

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package apm combines traces/metrics/logs and error aggregators to provide app observability

Index

Constants

This section is empty.

Variables

View Source
var (
	// TimeBucketsFast suits if expected response time is very high: 1ms..100ms
	// This buckets suits for cache storages (in-memory cache, Memcache, Redis)
	TimeBucketsFast = []float64{1, 3, 7, 15, 50, 100, 200, 500, 1000, 2000, 5000}

	// TimeBucketsMedium suits for most of GO APIs, where response time is between 50ms..500ms.
	// Works for wide range of systems because provides near-logarithmic buckets distribution.
	TimeBucketsMedium = []float64{1, 5, 15, 50, 100, 250, 500, 750, 1000, 1500, 2000, 3500, 5000}

	// TimeBucketsSlow suits for relatively slow services, where expected response time is > 500ms.
	TimeBucketsSlow = []float64{50, 100, 200, 500, 750, 1000, 1250, 1500, 1750, 2000, 2500, 3000, 4000, 5000}
)

Functions

func OtelGRPCNewServerHandler

func OtelGRPCNewServerHandler(ignoredMethods ...string) stats.Handler

func SetGlobal

func SetGlobal(apm *APM)

SetGlobal sets global apm instance

Types

type APM

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

APM is the application performance monitoring service

func Global

func Global() *APM

Global gets global apm instance

func New

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

New initializes APM service using options provided It has an internal tracer and meter created for the application It can also access the tracerprovider and meteterprovider, so we can integrate otel with other client (redis/kakfa...)

func (*APM) AppMeter

func (s *APM) AppMeter() *Meter

AppMeter gets provided appMeter for metrics

func (*APM) AppTracer

func (s *APM) AppTracer() *Tracer

AppTracer gets provided appTracer for traces

func (*APM) GetMeterProvider

func (s *APM) GetMeterProvider() metric.MeterProvider

Use this to integrate otel with other client pkg (redis/kafka)

func (*APM) GetTracerProvider

func (s *APM) GetTracerProvider() trace.TracerProvider

Use this to integrate otel with other client pkg (redis/kafka)

func (*APM) Shutdown

func (s *APM) Shutdown(ctx context.Context) error

Shutdown gracefully switch off apm, flushing any data it have

type HTTPMiddleware

type HTTPMiddleware func(h http.Handler) http.Handler

func NewHTTPMiddleware

func NewHTTPMiddleware(opts ...otelhttp.Option) HTTPMiddleware

type Meter

type Meter struct {
	metric.Meter
}

Meter - metric service

func NewMeter

func NewMeter(config Options, reader sdkmetric.Reader) (metric.MeterProvider, *Meter, error)

NewMeter create a global meter provider and a custom meter obj for the application's own usage we need both obj because the provider helps us integrate with other third party sdk like redis/kafka

func (*Meter) CounterAdd

func (m *Meter) CounterAdd(ctx context.Context, name string, amount float64, attrs ...attribute.KeyValue)

CounterAdd lazily increments certain counter metric. The label set passed on the first time should be present every time, no sparse keys

func (*Meter) HistogramRecord

func (m *Meter) HistogramRecord(ctx context.Context, name string, value float64, attrs ...attribute.KeyValue)

HistogramRecord records value to histogram with predefined boundaries (e.g. request latency) The same rules apply as for counter - no sparse label structure

func (*Meter) Observe

func (m *Meter) Observe(name string, collect func() float64, attrs ...attribute.KeyValue)

Observe function collect will be called each time the metric is scraped, it should be go-routine safe

type Options

type Options struct {
	Debug                bool
	Environment          string
	ServiceName          string
	ServiceVersion       string
	TracesSampleRate     float64
	CollectorURL         string
	PrometheusScrapePort uint16
	// UseStdOut if true, will set the metrics exporter and trace exporter as stdout
	UseStdOut bool
}

Options used for apm initialization

type Tracer

type Tracer struct {
	// So far no custom behavior, export all sdk for convenience
	trace.Tracer
}

Tracer represents common wrapper on any customTracer

func NewTracer

func NewTracer(ctx context.Context, opts *Options, exporter sdktrace.SpanExporter) (trace.TracerProvider, *Tracer)

New create a global tracerProvider and a custom tracer for the application own usage we need both obj because tracerProvider is the way to integrate with other otel sdk

Jump to

Keyboard shortcuts

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