Add constructors

This commit is contained in:
Vladimir Mihailenco 2021-04-16 15:00:10 +03:00
parent 24c92382c9
commit ef568e261e
2 changed files with 10 additions and 2 deletions

View File

@ -10,7 +10,11 @@ import (
type TracingHook struct{} type TracingHook struct{}
var _ redis.Hook = TracingHook{} var _ redis.Hook = (*TracingHook)(nil)
func NewTracingHook() *TracingHook {
return new(TracingHook)
}
func (TracingHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) { func (TracingHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) {
ctx, span := trace.StartSpan(ctx, cmd.FullName()) ctx, span := trace.StartSpan(ctx, cmd.FullName())

View File

@ -15,7 +15,11 @@ var tracer = otel.Tracer("github.com/go-redis/redis")
type TracingHook struct{} type TracingHook struct{}
var _ redis.Hook = TracingHook{} var _ redis.Hook = (*TracingHook)(nil)
func NewTracingHook() *TracingHook {
return new(TracingHook)
}
func (TracingHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) { func (TracingHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) {
if !trace.SpanFromContext(ctx).IsRecording() { if !trace.SpanFromContext(ctx).IsRecording() {