From 165492e3ec4747f9c447a4cfa3e4a7ee0ce79ac2 Mon Sep 17 00:00:00 2001 From: Jon Lundy Date: Sun, 20 Nov 2022 10:21:06 -0700 Subject: [PATCH] chore: add telemetry --- pkg/locker/locker.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/locker/locker.go b/pkg/locker/locker.go index b9ef6de..ba015b6 100644 --- a/pkg/locker/locker.go +++ b/pkg/locker/locker.go @@ -2,8 +2,10 @@ package locker import ( "context" + "fmt" "github.com/sour-is/ev/internal/lg" + "go.opentelemetry.io/otel/attribute" ) type Locked[T any] struct { @@ -20,9 +22,18 @@ func New[T any](initial *T) *Locked[T] { // Modify will call the function with the locked value func (s *Locked[T]) Modify(ctx context.Context, fn func(context.Context, *T) error) error { - _, span := lg.Span(ctx) + if s == nil { + return fmt.Errorf("locker not initialized") + } + + ctx, span := lg.Span(ctx) defer span.End() + var t T + span.SetAttributes( + attribute.String("typeOf", fmt.Sprintf("%T", t)), + ) + if ctx.Err() != nil { return ctx.Err() }