-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspan.go
29 lines (23 loc) · 886 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
package work
import (
"runtime"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
)
// StartSpan will start a new span with no parent span.
func StartSpan(operationName string) opentracing.Span {
return StartSpanWithParent(nil, operationName)
}
// StartSpanWithParent will start a new span with a parent span.
// example:
// span:= StartSpanWithParent(c.Get("tracing-context"),
func StartSpanWithParent(parent opentracing.SpanContext, operationName string) opentracing.Span {
options := []opentracing.StartSpanOption{
opentracing.Tag{Key: ext.SpanKindRPCServer.Key, Value: ext.SpanKindRPCServer.Value},
opentracing.Tag{Key: "current-goroutines", Value: runtime.NumGoroutine()},
}
if parent != nil {
options = append(options, opentracing.ChildOf(parent))
}
return opentracing.StartSpan(operationName, options...)
}