Skip to content

Can't use an ObserverVec with promhttp.InstrumentHandlerDuration() #1258

Description

@mifisignal

I'm trying to instrument my http.Handler with promhttp.InstrumentHandlerDuration, like so:

duration :=  prometheus.NewSummaryVec(
	prometheus.SummaryOpts{
		Name:       "request_duration_seconds",
		Help:       "Request duration",
		Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
	},
	[]string{"code", "method"},
)

// ...
http.Handle("/", promhttp.InstrumentHandlerDuration(duration, handler))

However, this causes a runtime panic because prometheus.summary doesn't conform to the ExemplarObserver interface.

2023/04/22 14:47:25 http: panic serving 127.0.0.1:56256: interface conversion: *prometheus.summary is not prometheus.ExemplarObserver: missing method ObserveWithExemplar

It's not clear to me how to resolve this issue - unfortunately the documentation for InstrumentHandlerDuration doesn't discuss the matter, nor does the example provided (I'd be curious if the example as written even works!)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions