1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:54:40 -07:00

internal/telemetry: change detach to be an event

deliver detach to the exporter as an event rather than hard coding the
span detach behavior.

Change-Id: I87b6e2a3596fea338908c11ba0b219176b6305bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222542
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Ian Cottrell 2020-03-07 18:12:58 -05:00
parent e8dd451b4b
commit f30ed8521d
3 changed files with 7 additions and 7 deletions

View File

@ -16,6 +16,7 @@ const (
EventStartSpan
EventEndSpan
EventTag
EventDetach
)
type Event struct {

View File

@ -70,16 +70,12 @@ func ContextSpan(ctx context.Context, event telemetry.Event) context.Context {
if span := GetSpan(ctx); span != nil {
span.Finish = event.At
}
case telemetry.EventDetach:
return context.WithValue(ctx, spanContextKey, nil)
}
return ctx
}
// Detach returns a context without an associated span.
// This allows the creation of spans that are not children of the current span.
func Detach(ctx context.Context) context.Context {
return context.WithValue(ctx, spanContextKey, nil)
}
func (s *SpanContext) Format(f fmt.State, r rune) {
fmt.Fprintf(f, "%v:%v", s.TraceID, s.SpanID)
}

View File

@ -31,5 +31,8 @@ func StartSpan(ctx context.Context, name string, tags ...telemetry.Tag) (context
// Detach returns a context without an associated span.
// This allows the creation of spans that are not children of the current span.
func Detach(ctx context.Context) context.Context {
return export.Detach(ctx)
return export.ProcessEvent(ctx, telemetry.Event{
Type: telemetry.EventDetach,
At: time.Now(),
})
}