Last active
July 14, 2016 18:15
-
-
Save bg451/523986fb286d93aaf33ce8b1fcb072ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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