2020-03-07 16:02:27 -07:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
2020-03-25 20:50:00 -06:00
|
|
|
// StartSpan sends a span start event with the supplied tag list to the exporter.
|
|
|
|
// It also returns a function that will end the span, which should normally be
|
|
|
|
// deferred.
|
2020-03-07 16:02:27 -07:00
|
|
|
func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, func()) {
|
2020-03-20 10:00:56 -06:00
|
|
|
ctx = dispatch(ctx, makeEvent(StartSpanType, sTags{Name.Of(name)}, tags))
|
|
|
|
return ctx, func() { dispatch(ctx, makeEvent(EndSpanType, sTags{}, nil)) }
|
2020-03-07 16:02:27 -07:00
|
|
|
}
|
|
|
|
|
2020-03-25 20:50:00 -06:00
|
|
|
// StartSpan1 sends a span start event with the supplied tag list to the exporter.
|
|
|
|
// It also returns a function that will end the span, which should normally be
|
|
|
|
// deferred.
|
|
|
|
func StartSpan1(ctx context.Context, name string, t1 Tag) (context.Context, func()) {
|
|
|
|
ctx = dispatch(ctx, makeEvent(StartSpanType, sTags{Name.Of(name), t1}, nil))
|
|
|
|
return ctx, func() {
|
|
|
|
dispatch(ctx, makeEvent(EndSpanType, sTags{}, nil))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartSpan2 sends a span start event with the supplied tag list to the exporter.
|
|
|
|
// It also returns a function that will end the span, which should normally be
|
|
|
|
// deferred.
|
|
|
|
func StartSpan2(ctx context.Context, name string, t1, t2 Tag) (context.Context, func()) {
|
|
|
|
ctx = dispatch(ctx, makeEvent(StartSpanType, sTags{Name.Of(name), t1, t2}, nil))
|
|
|
|
return ctx, func() {
|
|
|
|
dispatch(ctx, makeEvent(EndSpanType, sTags{}, nil))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 16:02:27 -07:00
|
|
|
// 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 {
|
2020-03-20 10:00:56 -06:00
|
|
|
return dispatch(ctx, makeEvent(DetachType, sTags{}, nil))
|
2020-03-07 16:02:27 -07:00
|
|
|
}
|