Documentation ¶
Overview ¶
Package otelmetric provides middleware to add opentelemetry metrics and Prometheus exporter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MiddlewareConfig ¶ added in v0.3.7
type MiddlewareConfig struct { // Skipper defines a function to skip middleware. Skipper middleware.Skipper // Namespace is components of the fully-qualified name of the Metric (created by joining Namespace,Subsystem and Name components with "_") // Optional Namespace string // Subsystem is components of the fully-qualified name of the Metric (created by joining Namespace,Subsystem and Name components with "_") // Defaults to: "echo" Subsystem string ServiceVersion string // run as [echo prometheus middleware](https://github.com/labstack/echo-contrib/blob/master/echoprometheus) compatible mode CompatibleMode bool MetricsPath string RequestCounterURLLabelMappingFunc RequestCounterLabelMappingFunc RequestCounterHostLabelMappingFunc RequestCounterLabelMappingFunc // Registry is the prometheus registry that will be used as the default Registerer and // Gatherer if these are not specified. Registry *realprometheus.Registry // Registerer sets the prometheus.Registerer instance the middleware will register these metrics with. // Defaults to: prometheus.DefaultRegisterer Registerer realprometheus.Registerer // Gatherer is the prometheus gatherer to gather metrics with. // If not specified the Registry will be used as default. Gatherer realprometheus.Gatherer }
MiddlewareConfig contains the configuration for creating prometheus middleware collecting several default metrics.
type Prometheus ¶
type Prometheus struct { *MiddlewareConfig // contains filtered or unexported fields }
Prometheus contains the metrics gathered by the instance and its path
func NewPrometheus ¶
func NewPrometheus(config MiddlewareConfig) *Prometheus
NewPrometheus generates a new set of metrics with a certain subsystem name
func (*Prometheus) ExporterHandler ¶ added in v0.3.7
func (p *Prometheus) ExporterHandler() echo.HandlerFunc
func (*Prometheus) HandlerFunc ¶
func (p *Prometheus) HandlerFunc(next echo.HandlerFunc) echo.HandlerFunc
HandlerFunc defines handler function for middleware
func (*Prometheus) SetMetricsExporterRoute ¶ added in v0.3.7
func (p *Prometheus) SetMetricsExporterRoute(e *echo.Echo)
SetMetricsExporterRoute set metrics paths
func (*Prometheus) Setup ¶ added in v0.3.7
func (p *Prometheus) Setup(e *echo.Echo)
Setup adds the middleware to the Echo engine.
type RequestCounterLabelMappingFunc ¶
type RequestCounterLabelMappingFunc func(c echo.Context) string
RequestCounterLabelMappingFunc is a function which can be supplied to the middleware to control the cardinality of the request counter's "url" label, which might be required in some contexts. For instance, if for a "/customer/:name" route you don't want to generate a time series for every possible customer name, you could use this function:
func(c echo.Context) string { url := c.Request.URL.Path for _, p := range c.Params { if p.Key == "name" { url = strings.Replace(url, p.Value, ":name", 1) break } } return url }
which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name". It can also be applied for the "Host" label