blob: 64e63b425d73e7260562961fa74692d69a32a3e7 [file] [log] [blame]
// 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 export
import (
"context"
"golang.org/x/tools/internal/telemetry/event"
)
// Tag manipulates the context using the event.
// If the event is type IsTag or IsStartSpan then it returns a context updated
// with tag values from the event.
// For all other event types the event tags will be updated with values from the
// context if they are missing.
func Tag(ctx context.Context, ev event.Event) (context.Context, event.Event) {
//TODO: Do we need to do something more efficient than just store tags
//TODO: directly on the context?
switch {
case ev.IsLabel(), ev.IsStartSpan():
for _, t := range ev.Tags {
ctx = context.WithValue(ctx, t.Key, t.Value)
}
default:
// all other types want the tags filled in if needed
for i := range ev.Tags {
if ev.Tags[i].Value == nil {
ev.Tags[i].Value = ctx.Value(ev.Tags[i].Key)
}
}
}
return ctx, ev
}