chore: add telemetry
This commit is contained in:
		
							parent
							
								
									cb6abfc4ba
								
							
						
					
					
						commit
						165492e3ec
					
				@ -2,8 +2,10 @@ package locker
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/sour-is/ev/internal/lg"
 | 
						"github.com/sour-is/ev/internal/lg"
 | 
				
			||||||
 | 
						"go.opentelemetry.io/otel/attribute"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Locked[T any] struct {
 | 
					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
 | 
					// Modify will call the function with the locked value
 | 
				
			||||||
func (s *Locked[T]) Modify(ctx context.Context, fn func(context.Context, *T) error) error {
 | 
					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()
 | 
						defer span.End()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var t T
 | 
				
			||||||
 | 
						span.SetAttributes(
 | 
				
			||||||
 | 
							attribute.String("typeOf", fmt.Sprintf("%T", t)),
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ctx.Err() != nil {
 | 
						if ctx.Err() != nil {
 | 
				
			||||||
		return ctx.Err()
 | 
							return ctx.Err()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user