go-redis
                                
                                
                                
                                    go-redis copied to clipboard
                            
                            
                            
                        [otel] Bugs when handling attributes
Expected Behavior
I was reviewing the source code of the OpenTelemetry hooks and found two possible bugs related to how the attributes are being handled.
The first one is that every time a new node is detected, then we attach the pool name to the list of attributes
https://github.com/redis/go-redis/blob/21bd40a47e56e61c0598ea1bdf8e02e67d1aa651/extra/redisotel/metrics.go#L54
The second bug happens in the function reportPoolStats
https://github.com/redis/go-redis/blob/21bd40a47e56e61c0598ea1bdf8e02e67d1aa651/extra/redisotel/metrics.go#L86-L88
In this case depending on whether the initial labels slice has enough capacity we could get unexpected results, as the code it's not copying the values into a new slice.
See for example this code in the playground that shows the bug https://go.dev/play/p/XBHgyYioH4s
Or check this code in the same file, which correctly handles the attributes https://github.com/redis/go-redis/blob/21bd40a47e56e61c0598ea1bdf8e02e67d1aa651/extra/redisotel/metrics.go#L215-L218