chore: get files from lab6

This commit is contained in:
Голиков Maximillian Антон
2026-11-24 22:32:11 +03:00
parent 20afc2c790
commit 9b88c6f0bd
118 changed files with 9682 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package redis
import (
"context"
"errors"
"github.com/redis/go-redis/v9"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
type tracingHook struct{ tracer trace.Tracer }
func (h tracingHook) DialHook(next redis.DialHook) redis.DialHook { return next }
func (h tracingHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
return func(ctx context.Context, cmd redis.Cmder) error {
return h.run(ctx, cmd.Name(), func(ctx context.Context) error { return next(ctx, cmd) })
}
}
func (h tracingHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {
return func(ctx context.Context, cmds []redis.Cmder) error {
return h.run(ctx, "pipeline", func(ctx context.Context) error { return next(ctx, cmds) })
}
}
func (h tracingHook) run(ctx context.Context, op string, call func(context.Context) error) error {
ctx, span := h.tracer.Start(ctx, "redis."+op, trace.WithSpanKind(trace.SpanKindClient),
trace.WithAttributes(attribute.String("db.system.name", "redis"), attribute.String("db.operation.name", op)))
defer span.End()
err := call(ctx)
if err != nil && !errors.Is(err, redis.Nil) {
span.SetStatus(codes.Error, "операция Redis не выполнена")
}
return err
}