-
Notifications
You must be signed in to change notification settings - Fork 2
/
span.go
53 lines (41 loc) · 1.35 KB
/
span.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package goagent // import "github.com/Traceableai/goagent"
import (
"context"
"time"
"github.com/hypertrace/goagent/instrumentation/hypertrace"
"github.com/hypertrace/goagent/sdk"
)
func SpanFromContext(ctx context.Context) sdk.Span {
return hypertrace.SpanFromContext(ctx)
}
type Option func(o *sdk.SpanOptions)
type SpanKind string
const (
SpanKindUndetermined SpanKind = SpanKind(sdk.SpanKindUndetermined)
SpanKindClient SpanKind = SpanKind(sdk.SpanKindClient)
SpanKindServer SpanKind = SpanKind(sdk.SpanKindServer)
SpanKindProducer SpanKind = SpanKind(sdk.SpanKindProducer)
SpanKindConsumer SpanKind = SpanKind(sdk.SpanKindConsumer)
)
func WithSpanKind(kind SpanKind) Option {
return func(o *sdk.SpanOptions) {
o.Kind = sdk.SpanKind(kind)
}
}
func WithTimestamp(ts time.Time) Option {
return func(o *sdk.SpanOptions) {
o.Timestamp = ts
}
}
type SpanStarter func(ctx context.Context, name string, opts ...Option) (context.Context, sdk.Span, func())
func translateSpanStarter(s sdk.StartSpan) SpanStarter {
return func(ctx context.Context, name string, opts ...Option) (context.Context, sdk.Span, func()) {
o := &sdk.SpanOptions{}
for _, opt := range opts {
opt(o)
}
return s(ctx, name, o)
}
}
var StartSpan = translateSpanStarter(hypertrace.StartSpan)
var NoopStartSpan = translateSpanStarter(hypertrace.NoopStartSpan)