-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
31 lines (26 loc) · 920 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @Author: steven
* @Description:
* @File: helpers
* @Date: 25/12/23 09.21
*/
package queue
import (
"context"
"go.opentelemetry.io/otel/trace"
)
func wrapTelemetry(ctx context.Context, tc trace.Tracer, spanName string, spanAttr []trace.SpanStartOption, task func(ctx context.Context)) {
newCtx, span := tc.Start(ctx, spanName, spanAttr...)
defer span.End()
task(newCtx)
}
func wrapTelemetryTuple1[T any](ctx context.Context, tc trace.Tracer, spanName string, spanAttr []trace.SpanStartOption, task func(ctx context.Context) T) T {
newCtx, span := tc.Start(ctx, spanName, spanAttr...)
defer span.End()
return task(newCtx)
}
func wrapTelemetryTuple2[T any, T2 any](ctx context.Context, tc trace.Tracer, spanName string, spanAttr []trace.SpanStartOption, task func(ctx context.Context) (T, T2)) (T, T2) {
newCtx, span := tc.Start(ctx, spanName, spanAttr...)
defer span.End()
return task(newCtx)
}