| 59 | var _ redis.Hook = (*tracingHook)(nil) |
| 60 | |
| 61 | func newTracingHook(connString string, opts ...TracingOption) *tracingHook { |
| 62 | baseOpts := make([]baseOption, len(opts)) |
| 63 | for i, opt := range opts { |
| 64 | baseOpts[i] = opt |
| 65 | } |
| 66 | conf := newConfig(baseOpts...) |
| 67 | |
| 68 | if conf.tracer == nil { |
| 69 | conf.tracer = conf.tp.Tracer( |
| 70 | instrumName, |
| 71 | trace.WithInstrumentationVersion("semver:"+redis.Version()), |
| 72 | ) |
| 73 | } |
| 74 | if connString != "" { |
| 75 | conf.attrs = append(conf.attrs, semconv.DBConnectionString(connString)) |
| 76 | } |
| 77 | |
| 78 | return &tracingHook{ |
| 79 | conf: conf, |
| 80 | |
| 81 | spanOpts: []trace.SpanStartOption{ |
| 82 | trace.WithSpanKind(trace.SpanKindClient), |
| 83 | trace.WithAttributes(conf.attrs...), |
| 84 | }, |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func (th *tracingHook) DialHook(hook redis.DialHook) redis.DialHook { |
| 89 | return func(ctx context.Context, network, addr string) (net.Conn, error) { |