### Create Client with Metric Function Source: https://github.com/luckytea/httpclient/blob/main/README.md Use this to create a new http client that uses a provided function to record latency metrics. The function should accept the start time and domain, and handle the metric observation. ```go // metric func var latencyFunc = func(start time.Time, domain string) { latencyMetric.WithLabelValues(domain).Observe(float64(time.Since(start).Nanoseconds()) / 1000000) } // func client := httpclient.NewWithMetricFunc("domain", latencyFunc) // request if err := p.client.DoTimeout(req, resp); err != nil { // error handling } ``` -------------------------------- ### Create Client with Prometheus Metric Source: https://github.com/luckytea/httpclient/blob/main/README.md Use this to create a new http client that automatically collects latency metrics using a Prometheus HistogramVec. Ensure the metric is registered before creating the client. ```go // metric var netSourcesLatencyHistogram = func() *prometheus.HistogramVec { var metric = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Namespace: "service", Subsystem: "net", Name: "sources_latency", Help: "Third party response latency histogram.", Buckets: prometheus.ExponentialBuckets(0.05, 2, 8), }, []string{"source"}) prometheus.MustRegister(metric) return metric }() // create client := httpclient.NewWithMetric("domain", netSourcesLatencyHistogram) // request if err := p.client.DoTimeout(req, resp); err != nil { // error handling } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.