mirror of
https://github.com/golang/go
synced 2024-11-18 12:14:42 -07:00
internal/lsp: make event directly implement TagMap
Makes Event implement TagMap directly, instead of having to build an entirely new object. Change-Id: I0c1e8638de3dc3347f60fd93af3df6b7f8387751 Reviewed-on: https://go-review.googlesource.com/c/tools/+/227300 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
parent
ff0df58207
commit
903869a827
@ -158,8 +158,7 @@ func (r *rpcs) getRPCSpan(ctx context.Context, ev event.Event) (*export.Span, *r
|
||||
}
|
||||
// use the span start event look up the correct stats block
|
||||
// we do this because it prevents us matching a sub span
|
||||
startMap := span.Start().Map()
|
||||
return span, r.getRPCStats(startMap)
|
||||
return span, r.getRPCStats(span.Start())
|
||||
}
|
||||
|
||||
func (r *rpcs) getRPCStats(tagMap event.TagMap) *rpcStats {
|
||||
@ -201,7 +200,7 @@ func (h *rpcTimeHistogram) Mean() timeUnits { return h.Sum / timeUnits(h.Count)
|
||||
|
||||
func getStatusCode(span *export.Span) string {
|
||||
for _, ev := range span.Events() {
|
||||
if status := tag.StatusCode.Get(ev.Map()); status != "" {
|
||||
if status := tag.StatusCode.Get(ev); status != "" {
|
||||
return status
|
||||
}
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ func makeGlobalExporter(stderr io.Writer) event.Exporter {
|
||||
|
||||
if ev.IsLog() {
|
||||
// Don't log context cancellation errors.
|
||||
if err := event.Err.Get(ev.Map()); xerrors.Is(err, context.Canceled) {
|
||||
if err := event.Err.Get(ev); xerrors.Is(err, context.Canceled) {
|
||||
return ctx
|
||||
}
|
||||
// Make sure any log messages without an instance go to stderr.
|
||||
|
@ -54,7 +54,7 @@ func (ev Event) IsDetach() bool { return ev.typ == DetachType }
|
||||
func (ev Event) IsRecord() bool { return ev.typ == RecordType }
|
||||
|
||||
func (ev Event) Format(f fmt.State, r rune) {
|
||||
tagMap := ev.Map()
|
||||
tagMap := TagMap(ev)
|
||||
if !ev.At.IsZero() {
|
||||
fmt.Fprint(f, ev.At.Format("2006/01/02 15:04:05 "))
|
||||
}
|
||||
@ -85,17 +85,13 @@ func (ev Event) Tags() TagIterator {
|
||||
NewTagIterator(ev.dynamic...))
|
||||
}
|
||||
|
||||
func (ev Event) Map() TagMap {
|
||||
return &eventTagMap{event: ev}
|
||||
}
|
||||
|
||||
func (m *eventTagMap) Find(key interface{}) Tag {
|
||||
for _, tag := range m.event.static {
|
||||
func (ev Event) Find(key interface{}) Tag {
|
||||
for _, tag := range ev.static {
|
||||
if tag.Key == key {
|
||||
return tag
|
||||
}
|
||||
}
|
||||
for _, tag := range m.event.dynamic {
|
||||
for _, tag := range ev.dynamic {
|
||||
if tag.Key == key {
|
||||
return tag
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func deliver(ctx context.Context, exporter Exporter, ev Event) context.Context {
|
||||
// add the current time to the event
|
||||
ev.At = time.Now()
|
||||
// hand the event off to the current exporter
|
||||
return exporter(ctx, ev, ev.Map())
|
||||
return exporter(ctx, ev, ev)
|
||||
}
|
||||
|
||||
// dispatch is called to deliver an event to the global exporter if set.
|
||||
|
@ -299,7 +299,7 @@ func convertAnnotation(ev event.Event) *wire.Annotation {
|
||||
if !tags.Valid() {
|
||||
return nil
|
||||
}
|
||||
tagMap := ev.Map()
|
||||
tagMap := event.TagMap(ev)
|
||||
description := event.Msg.Get(tagMap)
|
||||
tags = event.Filter(tags, event.Msg)
|
||||
if description == "" {
|
||||
|
@ -20,7 +20,7 @@ func Labels(output event.Exporter) event.Exporter {
|
||||
stored, _ := ctx.Value(labelContextKey).(event.TagMap)
|
||||
if ev.IsLabel() || ev.IsStartSpan() {
|
||||
// update the tag source stored in the context
|
||||
fromEvent := ev.Map()
|
||||
fromEvent := event.TagMap(ev)
|
||||
if stored == nil {
|
||||
stored = fromEvent
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user