1
0
mirror of https://github.com/golang/go synced 2024-11-05 23:36:12 -07:00
go/internal/telemetry/event/trace.go
Ian Cottrell fd4102a86c internal/telemetry: minor improvement to span events
This changes span events to return a cheaper end function if there is
no exporter and also to deliver the end event to the same exporter
that the start even was delivered to rather than which was active
when the end event is triggered.

Change-Id: I831283da20e8cc991a0cf7490952ae194d125428
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225737
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-03-29 02:58:19 +00:00

43 lines
1.6 KiB
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"
)
// 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.
func StartSpan(ctx context.Context, name string, tags ...Tag) (context.Context, func()) {
return dispatchPair(ctx,
makeEvent(StartSpanType, sTags{Name.Of(name)}, tags),
makeEvent(EndSpanType, sTags{}, nil))
}
// 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()) {
return dispatchPair(ctx,
makeEvent(StartSpanType, sTags{Name.Of(name), t1}, nil),
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()) {
return dispatchPair(ctx,
makeEvent(StartSpanType, sTags{Name.Of(name), t1, t2}, nil),
makeEvent(EndSpanType, sTags{}, nil))
}
// 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 dispatch(ctx, makeEvent(DetachType, sTags{}, nil))
}