RecordConnectionClosed records redis.client.connection.closed metric
( ctx context.Context, cn redis.ConnInfo, reason string, err error, )
| 697 | |
| 698 | // RecordConnectionClosed records redis.client.connection.closed metric |
| 699 | func (r *metricsRecorder) RecordConnectionClosed( |
| 700 | ctx context.Context, |
| 701 | cn redis.ConnInfo, |
| 702 | reason string, |
| 703 | err error, |
| 704 | ) { |
| 705 | if r.connectionClosed == nil { |
| 706 | return |
| 707 | } |
| 708 | |
| 709 | // Build attributes |
| 710 | attrs := []attribute.KeyValue{ |
| 711 | attribute.String(AttrDBSystemName, DBSystemRedis), |
| 712 | getLibraryVersionAttr(), |
| 713 | } |
| 714 | |
| 715 | // Use pool name from connection (set when connection was created) |
| 716 | if cn != nil { |
| 717 | poolName := cn.PoolName() |
| 718 | if poolName != "" { |
| 719 | attrs = append(attrs, attribute.String(AttrDBClientConnectionPoolName, poolName)) |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | // Add error type and category (always required per spec) |
| 724 | // Use classifyError to normalize error messages and prevent high cardinality |
| 725 | if err != nil { |
| 726 | // Normalize the close reason to prevent high cardinality from variable data |
| 727 | // (e.g., port numbers, connection IDs in error messages) |
| 728 | normalizedReason := classifyError(err) |
| 729 | attrs = append(attrs, attribute.String(AttrRedisClientConnectionCloseReason, normalizedReason)) |
| 730 | attrs = append(attrs, attribute.String(AttrErrorType, normalizedReason)) |
| 731 | attrs = append(attrs, attribute.String(AttrRedisClientErrorsCategory, getErrorCategory(err))) |
| 732 | } else { |
| 733 | // For non-error closures, use reason directly (these are controlled strings like "pool_closed") |
| 734 | attrs = append(attrs, attribute.String(AttrRedisClientConnectionCloseReason, reason)) |
| 735 | attrs = append(attrs, attribute.String(AttrErrorType, reason)) |
| 736 | attrs = append(attrs, attribute.String(AttrRedisClientErrorsCategory, getErrorCategoryFromString(reason))) |
| 737 | } |
| 738 | |
| 739 | // Record the counter |
| 740 | r.connectionClosed.Add(ctx, 1, metric.WithAttributes(attrs...)) |
| 741 | } |
| 742 | |
| 743 | // RecordPubSubMessage records redis.client.pubsub.messages metric |
| 744 | func (r *metricsRecorder) RecordPubSubMessage( |
nothing calls this directly
no test coverage detected