/
gorest_spn.go
36 lines (32 loc) · 907 Bytes
/
gorest_spn.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
package otintegration
import (
"github.com/ant0ine/go-json-rest/rest"
"github.com/opentracing/opentracing-go"
)
// GetGorestSpan extracts span from gorest request.
func GetGorestSpan(r *rest.Request) (opentracing.Span, error) {
spanI, _ := r.Env[spanContextKey]
span, ok := spanI.(opentracing.Span)
if span == nil || !ok {
return nil, ErrSpanNotFound
}
return span, nil
}
// GetGorestSubSpan extracts span and returns new span from gorest request.
func GetGorestSubSpan(r *rest.Request, operationName string) (opentracing.Span, error) {
s, err := GetGorestSpan(r)
if err != nil {
return nil, err
}
sub := GetSubSpan(s, operationName)
return sub, nil
}
func InjectGorestToBinary(r *rest.Request, inter TraceInfo) error {
span, err := GetGorestSpan(r)
if err != nil {
return err
}
tracer := span.Tracer()
err = tracer.Inject(span.Context(), opentracing.Binary, inter)
return err
}