Skip to content

Commit

Permalink
Extend instrumentation contract with span options
Browse files Browse the repository at this point in the history
  • Loading branch information
SodaDev committed Mar 15, 2024
1 parent 9e292cf commit 1314983
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frotel/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ func RecordError(ctx context.Context, err error) {
span.RecordError(err)
}

func InstrumentSpan[T interface{}](ctx context.Context, spanName string, consumer func(ctx context.Context) T) T {
func InstrumentSpan[T interface{}](ctx context.Context, spanName string, consumer func(ctx context.Context) T, opts ...trace.SpanStartOption) T {
if tracer == nil {
tracer = otel.GetTracerProvider().Tracer("fr-otel-tracer")
}
spanCtx, span := tracer.Start(ctx, spanName)
spanCtx, span := tracer.Start(ctx, spanName, opts...)
defer span.End()

return consumer(spanCtx)
}

func InstrumentSpanWithError(ctx context.Context, spanName string, consumer func(ctx context.Context) error) error {
func InstrumentSpanWithError(ctx context.Context, spanName string, consumer func(ctx context.Context) error, opts ...trace.SpanStartOption) error {
if tracer == nil {
tracer = otel.GetTracerProvider().Tracer("fr-otel-tracer")
}
spanCtx, span := tracer.Start(ctx, spanName)
spanCtx, span := tracer.Start(ctx, spanName, opts...)
defer span.End()

err := consumer(spanCtx)
Expand All @@ -49,11 +49,11 @@ func InstrumentSpanWithError(ctx context.Context, spanName string, consumer func
return err
}

func InstrumentSpanWithErr[T interface{}](ctx context.Context, spanName string, consumer func(ctx context.Context) (T, error)) (T, error) {
func InstrumentSpanWithErr[T interface{}](ctx context.Context, spanName string, consumer func(ctx context.Context) (T, error), opts ...trace.SpanStartOption) (T, error) {
if tracer == nil {
tracer = otel.GetTracerProvider().Tracer("fr-otel-tracer")
}
spanCtx, span := tracer.Start(ctx, spanName)
spanCtx, span := tracer.Start(ctx, spanName, opts...)
defer span.End()

result, err := consumer(spanCtx)
Expand Down

0 comments on commit 1314983

Please sign in to comment.