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"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, func()) {
|
2020-03-20 06:29:48 -06:00
|
|
|
ctx = ProcessEvent(ctx, Event{
|
2020-03-07 16:02:27 -07:00
|
|
|
Type: StartSpanType,
|
|
|
|
Message: name,
|
|
|
|
At: time.Now(),
|
2020-03-20 06:29:48 -06:00
|
|
|
tags: tags,
|
2020-03-07 16:02:27 -07:00
|
|
|
})
|
|
|
|
return ctx, func() {
|
|
|
|
ProcessEvent(ctx, Event{
|
|
|
|
Type: EndSpanType,
|
|
|
|
At: time.Now(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 06:29:48 -06:00
|
|
|
return ProcessEvent(ctx, Event{
|
2020-03-07 16:02:27 -07:00
|
|
|
Type: DetachType,
|
|
|
|
At: time.Now(),
|
|
|
|
})
|
|
|
|
}
|