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:
parent
e8dd451b4b
commit
f30ed8521d
@ -16,6 +16,7 @@ const (
|
||||
EventStartSpan
|
||||
EventEndSpan
|
||||
EventTag
|
||||
EventDetach
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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(),
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user