diff options
Diffstat (limited to 'plugin/metrics/context.go')
-rw-r--r-- | plugin/metrics/context.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/plugin/metrics/context.go b/plugin/metrics/context.go index da6bdb12d..ae2856dd5 100644 --- a/plugin/metrics/context.go +++ b/plugin/metrics/context.go @@ -22,3 +22,16 @@ func WithServer(ctx context.Context) string { } return srv.(*dnsserver.Server).Addr } + +// WithView returns the name of the view currently handling the request, if a view is defined. +// +// Basic usage with a metric: +// +// <metric>.WithLabelValues(metrics.WithView(ctx), labels..).Add(1) +func WithView(ctx context.Context) string { + v := ctx.Value(dnsserver.ViewKey{}) + if v == nil { + return "" + } + return v.(string) +} |