/
tag.go
34 lines (29 loc) · 1.06 KB
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 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 tag provides support for telemetry tagging.
// This package is a thin shim over contexts with the main addition being the
// the ability to observe when contexts get tagged with new values.
package tag
import (
"context"
"time"
"github.com/anz-bank/sysl/pkg/lspimpl/lspframework/telemetry"
"github.com/anz-bank/sysl/pkg/lspimpl/lspframework/telemetry/export"
)
// With delivers the tag list to the telemetry exporter.
func With(ctx context.Context, tags ...telemetry.Tag) context.Context {
return export.ProcessEvent(ctx, telemetry.Event{
Type: telemetry.EventTag,
At: time.Now(),
Tags: tags,
})
}
// Get collects a set of values from the context and returns them as a tag list.
func Get(ctx context.Context, keys ...interface{}) telemetry.TagList {
tags := make(telemetry.TagList, len(keys))
for i, key := range keys {
tags[i] = telemetry.Tag{Key: key, Value: ctx.Value(key)}
}
return tags
}