|
|
@@ -64,6 +64,7 @@ package trace // import "golang.org/x/net/trace"
|
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
+ "context"
|
|
|
"fmt"
|
|
|
"html/template"
|
|
|
"io"
|
|
|
@@ -124,6 +125,18 @@ func init() {
|
|
|
http.HandleFunc("/debug/events", Events)
|
|
|
}
|
|
|
|
|
|
+// NewContext returns a copy of the parent context
|
|
|
+// and associates it with a Trace.
|
|
|
+func NewContext(ctx context.Context, tr Trace) context.Context {
|
|
|
+ return context.WithValue(ctx, contextKey, tr)
|
|
|
+}
|
|
|
+
|
|
|
+// FromContext returns the Trace bound to the context, if any.
|
|
|
+func FromContext(ctx context.Context) (tr Trace, ok bool) {
|
|
|
+ tr, ok = ctx.Value(contextKey).(Trace)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// Traces responds with traces from the program.
|
|
|
// The package initialization registers it in http.DefaultServeMux
|
|
|
// at /debug/requests.
|