Documentation ¶
Index ¶
- func GetViews() []metric.View
- func HTTPMetrics(opts ...Option) echo.MiddlewareFunc
- type HTTPLabels
- type HTTPMetricsRecorder
- func (h *HTTPMetricsRecorder) AddInFlightRequest(ctx context.Context, values HTTPLabels)
- func (h *HTTPMetricsRecorder) AddRequestDuration(ctx context.Context, duration time.Duration, values HTTPLabels)
- func (h *HTTPMetricsRecorder) AddRequestError(ctx context.Context, values HTTPLabels)
- func (h *HTTPMetricsRecorder) AddRequestSize(ctx context.Context, request *http.Request, values HTTPLabels)
- func (h *HTTPMetricsRecorder) AddRequestSuccess(ctx context.Context, values HTTPLabels)
- func (h *HTTPMetricsRecorder) AddRequestToTotal(ctx context.Context, values HTTPLabels)
- func (h *HTTPMetricsRecorder) AddResponseSize(ctx context.Context, response *echo.Response, values HTTPLabels)
- func (h *HTTPMetricsRecorder) RemInFlightRequest(ctx context.Context, values HTTPLabels)
- type Option
- func WithDurMetric(enabled bool) Option
- func WithInFlightMetric(enabled bool) Option
- func WithInstrumentationName(v string) Option
- func WithMeterProvider(provider metric.MeterProvider) Option
- func WithNamespace(v string) Option
- func WithServiceName(v string) Option
- func WithSkipper(skipper middleware.Skipper) Option
- func WithTotalMetric(enabled bool) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPMetrics ¶
func HTTPMetrics(opts ...Option) echo.MiddlewareFunc
HTTPMetrics is a middleware for adding otel metrics for a given request If recorder config is nil, the middleware will use a recorder with default configuration.
Types ¶
type HTTPLabels ¶
type HTTPLabels struct { // Method should be the HTTP method in the HTTP request. Method string // Code should be the HTTP status code in the HTTP response. If there is no response, the Code should be 0. Code int // Path is the request URL's path. Should not contain the query string, and ideally it should only be the route // definition. For example `/users/{ID}` instead of `/users/100`. Path string Host string }
HTTPLabels will contain HTTP label values for each added metric. Not all labels apply to all metrics, read the documentation in each metric method to find out which labels are available for that metric.
type HTTPMetricsRecorder ¶
type HTTPMetricsRecorder struct {
// contains filtered or unexported fields
}
HTTPMetricsRecorder is a recorder of HTTP metrics for prometheus. Use NewHTTPMetricsRecorder to initialize it.
func NewHTTPMetricsRecorder ¶
func NewHTTPMetricsRecorder(cfg config) *HTTPMetricsRecorder
NewHTTPMetricsRecorder creates a new HTTPMetricsRecorder. Calling this function will automatically register the new metrics to reg.
func (*HTTPMetricsRecorder) AddInFlightRequest ¶
func (h *HTTPMetricsRecorder) AddInFlightRequest( ctx context.Context, values HTTPLabels, )
AddInFlightRequest Adds 1 to the number of current in-flight requests. All labels should be specified except for `Code`, as it will just be ignored. To remove a request use RemInFlightRequest.
func (*HTTPMetricsRecorder) AddRequestDuration ¶
func (h *HTTPMetricsRecorder) AddRequestDuration( ctx context.Context, duration time.Duration, values HTTPLabels, )
AddRequestDuration registers a request along with its duration. All labels should be specified.
func (*HTTPMetricsRecorder) AddRequestError ¶
func (h *HTTPMetricsRecorder) AddRequestError( ctx context.Context, values HTTPLabels, )
func (*HTTPMetricsRecorder) AddRequestSize ¶
func (h *HTTPMetricsRecorder) AddRequestSize( ctx context.Context, request *http.Request, values HTTPLabels, )
func (*HTTPMetricsRecorder) AddRequestSuccess ¶
func (h *HTTPMetricsRecorder) AddRequestSuccess( ctx context.Context, values HTTPLabels, )
func (*HTTPMetricsRecorder) AddRequestToTotal ¶
func (h *HTTPMetricsRecorder) AddRequestToTotal( ctx context.Context, values HTTPLabels, )
AddRequestToTotal adds 1 to the total number of requests. All labels should be specified.
func (*HTTPMetricsRecorder) AddResponseSize ¶
func (h *HTTPMetricsRecorder) AddResponseSize( ctx context.Context, response *echo.Response, values HTTPLabels, )
func (*HTTPMetricsRecorder) RemInFlightRequest ¶
func (h *HTTPMetricsRecorder) RemInFlightRequest( ctx context.Context, values HTTPLabels, )
RemInFlightRequest Remove 1 from the number of current in-flight requests. All labels should be specified except for `Code`, as it will just be ignored. Labels should match the ones passed to the equivalent AddInFlightRequest call.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithDurMetric ¶
func WithInFlightMetric ¶
func WithInstrumentationName ¶
func WithMeterProvider ¶
func WithMeterProvider(provider metric.MeterProvider) Option
WithMeterProvider specifies a meter provider to use for creating a metrics. If none is specified, the global provider is used.
func WithNamespace ¶
WithNamespace will set the metrics namespace that will be added to all metric configurations. It will be a prefix to each metric name. For example, if namespace is "myapp", then requests_total metric will be myapp_http_requests_total (after namespace there is also the subsystem prefix, "http" in this case).
func WithServiceName ¶
func WithSkipper ¶
func WithSkipper(skipper middleware.Skipper) Option
WithSkipper specifies a skipper for allowing requests to skip generating spans.