1
0
mirror of https://github.com/golang/go synced 2024-11-05 23:26:18 -07:00
go/internal/telemetry/event/label.go
Ian Cottrell b378960d5b internal/telemetry: replace event.TagList with event.TagSet
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>
2020-03-23 14:43:48 +00:00

35 lines
846 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"
)
// Label sends a label event to the exporter with the supplied tags.
func Label(ctx context.Context, tags ...Tag) context.Context {
ctx, _ = ProcessEvent(ctx, Event{
Type: LabelType,
At: time.Now(),
Tags: newTagSet(tags),
})
return ctx
}
// Query sends a query event to the exporter with the supplied keys.
// The returned tags will have up to date values if the exporter supports it.
func Query(ctx context.Context, keys ...Key) TagSet {
tags := make([]Tag, len(keys))
for i, k := range keys {
tags[i] = k.OfValue(nil)
}
_, ev := ProcessEvent(ctx, Event{
Type: QueryType,
Tags: newTagSet(tags),
})
return ev.Tags
}