chore: add telemetry

This commit is contained in:
Jon Lundy 2022-11-20 10:21:06 -07:00
parent cb6abfc4ba
commit 165492e3ec
Signed by untrusted user who does not match committer: xuu
GPG Key ID: C63E6D61F3035024

View File

@ -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()
}