Commit 52276c3
committed
feat: extract dialer to
Allowing the default dialing function to be wrapped allows for library
users to let the library continue to own the logic for dialing and let
users wrap the function for more observability.
My use case is to override `Options.Dialer` and add Jaeger tracing to
gain insight into the cost of new connections on a latency sensitive API.
```go
defDialer := redis.DefaultDialer(opts)
opts.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "cache-repo-redis: new redis connection")
defer span.Finish()
return defDialer(ctx, network, addr)
}
```
Without this, I end up needing to copy-paste the code from the internal
code, which is less-than-ideal since I don't want to own the maintenance
of this logic.DefaultDialer to allow wrapping1 parent f1dd3d5 commit 52276c3
1 file changed
+16
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 132 | + | |
142 | 133 | | |
143 | 134 | | |
144 | 135 | | |
| |||
189 | 180 | | |
190 | 181 | | |
191 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
192 | 198 | | |
193 | 199 | | |
194 | 200 | | |
| |||
0 commit comments