mirror of
https://github.com/golang/go
synced 2024-11-06 07:26:10 -07:00
b378960d5b
This allows us to hide the implementation details of how tags are stored on a context from the normal interface, to allow us to explore more efficient mechanisms. The current storage is not intended as the most efficient choice, this cl is about isolating the API so we can experiment with benchmarks in the future. Change-Id: Ib101416bccd8ecdee269cee636b1564d51e1da8a Reviewed-on: https://go-review.googlesource.com/c/tools/+/222854 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
36 lines
812 B
Go
36 lines
812 B
Go
// 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()) {
|
|
ctx, _ = ProcessEvent(ctx, Event{
|
|
Type: StartSpanType,
|
|
Message: name,
|
|
At: time.Now(),
|
|
Tags: newTagSet(tags),
|
|
})
|
|
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 {
|
|
ctx, _ = ProcessEvent(ctx, Event{
|
|
Type: DetachType,
|
|
At: time.Now(),
|
|
})
|
|
return ctx
|
|
}
|