-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver2.go
52 lines (47 loc) · 1.28 KB
/
server2.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
package main
import (
"fmt"
"net/http"
"github.com/gin-contrib/opengintracing"
"github.com/gin-gonic/gin"
"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/zipkin"
)
func main() {
// Configure tracing
propagator := zipkin.NewZipkinB3HTTPHeaderPropagator()
trace, closer := jaeger.NewTracer(
"server02",
jaeger.NewConstSampler(true),
jaeger.NewNullReporter(),
jaeger.TracerOptions.Injector(opentracing.HTTPHeaders, propagator),
jaeger.TracerOptions.Extractor(opentracing.HTTPHeaders, propagator),
jaeger.TracerOptions.ZipkinSharedRPCSpan(true),
)
defer closer.Close()
opentracing.SetGlobalTracer(trace)
var fn opengintracing.ParentSpanReferenceFunc
fn = func(sc opentracing.SpanContext) opentracing.StartSpanOption {
return opentracing.ChildOf(sc)
}
// Set up routes
r := gin.Default()
r.POST("",
opengintracing.SpanFromHeadersHTTPFmt(trace, "service2", fn, false),
handler)
r.Run(":8002")
}
func handler(c *gin.Context) {
_, found := opengintracing.GetSpan(c)
if found == false {
fmt.Println("Span not found")
c.AbortWithStatus(http.StatusInternalServerError)
return
}
fmt.Println("Incoming Headers")
for k, v := range c.Request.Header {
fmt.Printf("%s: %s\n", k, v)
}
c.Status(http.StatusOK)
}