mirror of
https://github.com/golang/go
synced 2024-11-06 07:36:13 -07:00
b378960d5b
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>
56 lines
1.3 KiB
Go
56 lines
1.3 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 provides support for event based telemetry.
|
|
package event
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type eventType uint8
|
|
|
|
const (
|
|
LogType = eventType(iota)
|
|
StartSpanType
|
|
EndSpanType
|
|
LabelType
|
|
QueryType
|
|
DetachType
|
|
)
|
|
|
|
type Event struct {
|
|
Type eventType
|
|
At time.Time
|
|
Message string
|
|
Error error
|
|
Tags TagSet
|
|
}
|
|
|
|
func (e Event) IsLog() bool { return e.Type == LogType }
|
|
func (e Event) IsEndSpan() bool { return e.Type == EndSpanType }
|
|
func (e Event) IsStartSpan() bool { return e.Type == StartSpanType }
|
|
func (e Event) IsLabel() bool { return e.Type == LabelType }
|
|
func (e Event) IsQuery() bool { return e.Type == QueryType }
|
|
func (e Event) IsDetach() bool { return e.Type == DetachType }
|
|
|
|
func (e Event) Format(f fmt.State, r rune) {
|
|
if !e.At.IsZero() {
|
|
fmt.Fprint(f, e.At.Format("2006/01/02 15:04:05 "))
|
|
}
|
|
fmt.Fprint(f, e.Message)
|
|
if e.Error != nil {
|
|
if f.Flag('+') {
|
|
fmt.Fprintf(f, ": %+v", e.Error)
|
|
} else {
|
|
fmt.Fprintf(f, ": %v", e.Error)
|
|
}
|
|
}
|
|
for i := e.Tags.Iterator(); i.Next(); {
|
|
tag := i.Value()
|
|
fmt.Fprintf(f, "\n\t%s = %v", tag.key.name, tag.value)
|
|
}
|
|
}
|