Skip to content

Instantly share code, notes, and snippets.

@bg451
Last active July 14, 2016 18:15
Show Gist options
  • Save bg451/523986fb286d93aaf33ce8b1fcb072ad to your computer and use it in GitHub Desktop.
Save bg451/523986fb286d93aaf33ce8b1fcb072ad to your computer and use it in GitHub Desktop.
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Request started"))
span := opentracing.StartSpan("/home")
defer span.Finish()
// Since we have to inject our span into the HTTP headers, we create a request
asyncReq, _ := http.NewRequest("GET", "http://localhost:8080/async", nil)
// Inject the span context into the header
err := span.Tracer().Inject(span.Context(),
opentracing.TextMap,
opentracing.HTTPHeaderTextMapCarrier(asyncReq.Header))
if err != nil {
log.Fatalf("Could not inject span context into header: %v", err)
}
go func() {
if _, err := http.DefaultClient.Do(asyncReq); err != nil {
span.SetTag("error", true)
span.LogEvent(fmt.Sprintf("GET /async error: %v", err))
}
}()
// Repeat for the /service call.
// ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment