-
Notifications
You must be signed in to change notification settings - Fork 0
/
span.go
39 lines (33 loc) · 857 Bytes
/
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
package slslog
import (
"context"
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)
// Span wraps go.opentelemetry.io/otel/trace.Span.
type Span struct {
ctx context.Context
span trace.Span
}
// StartSpan starts a new span from the current span in the given context
// and returns it as Span.
// This span can be propagated to the subsequent process by using span's
// context.
func StartSpan(ctx context.Context, label string) *Span {
tp := sdktrace.NewTracerProvider()
otel.SetTracerProvider(tp)
ctx, span := otel.Tracer("github.com/slslog").Start(ctx, label)
return &Span{
ctx: ctx,
span: span,
}
}
// Context returns the span context attached to Span.
func (s *Span) Context() context.Context {
return s.ctx
}
// End ends the span.
func (s *Span) End() {
s.span.End()
}