MCPcopy
hub / github.com/redis/go-redis / DialHook

Method DialHook

extra/redisotel/metrics.go:280–296  ·  view source on GitHub ↗
(hook redis.DialHook)

Source from the content-addressed store, hash-verified

278var _ redis.Hook = (*metricsHook)(nil)
279
280func (mh *metricsHook) DialHook(hook redis.DialHook) redis.DialHook {
281 return func(ctx context.Context, network, addr string) (net.Conn, error) {
282 start := time.Now()
283
284 conn, err := hook(ctx, network, addr)
285
286 dur := time.Since(start)
287
288 attrs := make([]attribute.KeyValue, 0, len(mh.attrs)+2)
289 attrs = append(attrs, mh.attrs...)
290 attrs = append(attrs, statusAttr(err))
291 attrs = append(attrs, errorTypeAttribute(err))
292
293 mh.createTime.Record(ctx, milliseconds(dur), metric.WithAttributeSet(attribute.NewSet(attrs...)))
294 return conn, err
295 }
296}
297
298func (mh *metricsHook) ProcessHook(hook redis.ProcessHook) redis.ProcessHook {
299 return func(ctx context.Context, cmd redis.Cmder) error {

Callers

nothing calls this directly

Calls 5

hookStruct · 0.85
statusAttrFunction · 0.85
errorTypeAttributeFunction · 0.85
millisecondsFunction · 0.85
RecordMethod · 0.80

Tested by

no test coverage detected