Skip to content

Instantly share code, notes, and snippets.

@bg451
Last active July 14, 2016 18:17
Show Gist options
  • Save bg451/ee74cbf0e2279eb46dd59e2f1f7bca63 to your computer and use it in GitHub Desktop.
Save bg451/ee74cbf0e2279eb46dd59e2f1f7bca63 to your computer and use it in GitHub Desktop.
func serviceHandler(w http.ResponseWriter, r *http.Request) {
var sp opentracing.Span
opName := r.URL.Path
// Attempt to join a trace by getting trace context from the headers.
wireContext, err := opentracing.GlobalTracer().Extract(
opentracing.TextMap,
opentracing.HTTPHeaderTextMapCarrier(r.Header))
if err != nil {
// If for whatever reason we can't join, go ahead an start a new root span.
sp = opentracing.StartSpan(opName)
} else {
sp = opentracing.StartSpan(opName, opentracing.ChildOf(wireContext))
}
defer sp.Finish()
// ... rest of the function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment