Skip to content

Commit

Permalink
Small fix.
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Aug 2, 2022
1 parent da8f44d commit 094f97f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions prometheus/promhttp/instrument_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func InstrumentHandlerInFlight(g prometheus.Gauge, next http.Handler) http.Handl
// Note that this method is only guaranteed to never observe negative durations
// if used with Go1.9+.
func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler, opts ...Option) http.HandlerFunc {
mwOpts := &option{getExemplarFn: func(ctx context.Context) map[string]string { return nil }}
mwOpts := &option{getExemplarFn: func(ctx context.Context) prometheus.Labels { return nil }}
for _, o := range opts {
o(mwOpts)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func InstrumentHandlerDuration(obs prometheus.ObserverVec, next http.Handler, op
//
// See the example for InstrumentHandlerDuration for example usage.
func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler, opts ...Option) http.HandlerFunc {
mwOpts := &option{getExemplarFn: func(ctx context.Context) map[string]string { return nil }}
mwOpts := &option{getExemplarFn: func(ctx context.Context) prometheus.Labels { return nil }}
for _, o := range opts {
o(mwOpts)
}
Expand Down
13 changes: 9 additions & 4 deletions prometheus/promhttp/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@

package promhttp

import "context"
import (
"context"

"github.com/prometheus/client_golang/prometheus"
)

// Option are used to configure a middleware or round tripper.
type Option func(*option)

type option struct {
extraMethods []string
getExemplarFn func(ctx context.Context) map[string]string
getExemplarFn func(ctx context.Context) prometheus.Labels
}

// WithExtraMethods adds additional HTTP methods to the list of allowed methods.
Expand All @@ -34,8 +38,9 @@ func WithExtraMethods(methods ...string) Option {
}

// WithExemplarFromRequestContext adds allows to put a hook to all counter and histogram metrics.
// If the hook function returns non-nil map representing key values, exemplars will be added for that request.
func WithExemplarFromRequestContext(getExemplarFn func(ctx context.Context) map[string]string) Option {
// If the hook function returns non-nil labels, exemplars will be added for that request, otherwise metric will get instrumented
// without exemplar.
func WithExemplarFromRequestContext(getExemplarFn func(ctx context.Context) prometheus.Labels) Option {
return func(o *option) {
o.getExemplarFn = getExemplarFn
}
Expand Down

0 comments on commit 094f97f

Please sign in to comment.