Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seventeen #22

Merged
merged 3 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ This logger is inspired by a proprietary logger at [BlueOwl](https://blueowl.xyz
and
[Jaeger](https://www.jaegertracing.io/).

Special thanks to [phuslog](https://github.com/phuslu/log) as some of its
code was used.

### Open Telementry

Expand Down
20 changes: 20 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,28 @@
"LossyPool" that queues upto 32 items (tossing any extra) and returning immedately if
there aren't any availble. Use generics so no casting is needed.

- AttributeBuilder needs a JSON-specific version

- per-key buffers
- 64 buffers?
- 64 bytes each?

- Standard tracing

- figure out a way to modify trace State
- add methods to query trace State
- figure out a way to modify trace Baggage
- add methods to query trace Baggage

# Not build ready

- benchmarking

Aside from building basic benchmarking (separate item)...

- figure out how much time is spent for `time.Now()`
- figure out how much time is spent formatting timestamps

- send the spanSequenceCode as a xop: attribute

- Base loggers:
Expand Down
18 changes: 9 additions & 9 deletions basegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ var (
_ xopbase.Prefilling = prefillings{}
)

func (l baseLoggers) StartRequests(span trace.Bundle, descriptionOrName string) (xopbase.Request, map[string]xopbase.Request) {
func (l baseLoggers) StartRequests(ts time.Time, span trace.Bundle, descriptionOrName string) (xopbase.Request, map[string]xopbase.Request) {
if len(l) == 1 {
req := l[0].Request(span, descriptionOrName)
req := l[0].Request(ts, span, descriptionOrName)
return req, map[string]xopbase.Request{l[0].ID(): req}
}
m := make(map[string]xopbase.Request)
Expand All @@ -49,7 +49,7 @@ func (l baseLoggers) StartRequests(span trace.Bundle, descriptionOrName string)
// duplicate!
continue
}
req := logger.Request(span, descriptionOrName)
req := logger.Request(ts, span, descriptionOrName)
r.baseRequests = append(r.baseRequests, req)
r.baseSpans = append(r.baseSpans, req.(xopbase.Span))
m[id] = req
Expand Down Expand Up @@ -221,9 +221,9 @@ func (p prefillings) Link(k string, v trace.Trace) {
}
}

func (p prefillings) Str(k string, v string) {
func (p prefillings) String(k string, v string) {
for _, prefilling := range p {
prefilling.Str(k, v)
prefilling.String(k, v)
}
}

Expand Down Expand Up @@ -281,9 +281,9 @@ func (l lines) Link(k string, v trace.Trace) {
}
}

func (l lines) Str(k string, v string) {
func (l lines) String(k string, v string) {
for _, line := range l {
line.Str(k, v)
line.String(k, v)
}
}

Expand Down Expand Up @@ -335,9 +335,9 @@ func (s baseSpans) MetadataLink(k *xopconst.LinkAttribute, v trace.Trace) {
}
}

func (s baseSpans) MetadataStr(k *xopconst.StrAttribute, v string) {
func (s baseSpans) MetadataString(k *xopconst.StringAttribute, v string) {
for _, span := range s {
span.MetadataStr(k, v)
span.MetadataString(k, v)
}
}

Expand Down
6 changes: 3 additions & 3 deletions basegroup.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ var _ xopbase.Line = lines{}
var _ xopbase.Prefilled = prefilleds{}
var _ xopbase.Prefilling = prefillings{}

func (l baseLoggers) StartRequests(span trace.Bundle, descriptionOrName string) (xopbase.Request, map[string]xopbase.Request) {
func (l baseLoggers) StartRequests(ts time.Time, span trace.Bundle, descriptionOrName string) (xopbase.Request, map[string]xopbase.Request) {
if len(l) == 1 {
req := l[0].Request(span, descriptionOrName)
req := l[0].Request(ts, span, descriptionOrName)
return req, map[string]xopbase.Request{l[0].ID(): req}
}
m := make(map[string]xopbase.Request)
Expand All @@ -41,7 +41,7 @@ func (l baseLoggers) StartRequests(span trace.Bundle, descriptionOrName string)
// duplicate!
continue
}
req := logger.Request(span, descriptionOrName)
req := logger.Request(ts, span, descriptionOrName)
r.baseRequests = append(r.baseRequests, req)
r.baseSpans = append(r.baseSpans, req.(xopbase.Span))
m[id] = req
Expand Down
9 changes: 5 additions & 4 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s Seed) Request(descriptionOrName string) *Log {
alloc.Log.shared = &alloc.shared
log := &alloc.Log

combinedBaseRequest, flushers := log.span.seed.loggers.List.StartRequests(log.span.seed.traceBundle, descriptionOrName)
combinedBaseRequest, flushers := log.span.seed.loggers.List.StartRequests(time.Now(), log.span.seed.traceBundle, descriptionOrName)
log.shared.Flushers = flushers
combinedBaseRequest.SetErrorReporter(s.config.ErrorReporter)
log.span.referencesKept = log.span.seed.loggers.List.ReferencesKept()
Expand Down Expand Up @@ -158,6 +158,7 @@ func (old *Log) newChildLog(spanSeed spanSeed, description string, settings LogS
for _, removed := range spanSeed.loggers.Removed {
delete(spanSet, removed.ID())
}
ts := time.Now()
for _, added := range spanSeed.loggers.Added {
id := added.ID()
if _, ok := spanSet[id]; ok {
Expand All @@ -171,7 +172,7 @@ func (old *Log) newChildLog(spanSeed spanSeed, description string, settings LogS
}() {
continue
}
req := added.Request(log.request.seed.traceBundle, log.shared.Description)
req := added.Request(ts, log.request.seed.traceBundle, log.shared.Description)
req.SetErrorReporter(log.span.seed.config.ErrorReporter)
func() {
log.shared.FlusherLock.Lock()
Expand All @@ -194,7 +195,7 @@ func (old *Log) newChildLog(spanSeed spanSeed, description string, settings LogS
log.span.referencesKept = log.span.seed.loggers.List.ReferencesKept()
}
log.span.base.Boring(true)
log.Span().Str(xopconst.SpanSequeneCode, log.span.seed.spanSequenceCode) // TODO: improve (not efficient)
log.Span().String(xopconst.SpanSequeneCode, log.span.seed.spanSequenceCode) // TODO: improve (not efficient)
log.sendPrefill()
return log
}
Expand Down Expand Up @@ -393,7 +394,7 @@ func (ll *LogLine) Uint8(k string, v uint8) *LogLine { ll.line.Uint(k
func (ll *LogLine) Uint16(k string, v uint16) *LogLine { ll.line.Uint(k, uint64(v)); return ll }
func (ll *LogLine) Uint32(k string, v uint32) *LogLine { ll.line.Uint(k, uint64(v)); return ll }
func (ll *LogLine) Uint64(k string, v uint64) *LogLine { ll.line.Uint(k, v); return ll }
func (ll *LogLine) Str(k string, v string) *LogLine { ll.line.Str(k, v); return ll }
func (ll *LogLine) String(k string, v string) *LogLine { ll.line.String(k, v); return ll }
func (ll *LogLine) Bool(k string, v bool) *LogLine { ll.line.Bool(k, v); return ll }
func (ll *LogLine) Time(k string, v time.Time) *LogLine { ll.line.Time(k, v); return ll }
func (ll *LogLine) Error(k string, v error) *LogLine { ll.line.Error(k, v); return ll }
Expand Down
2 changes: 1 addition & 1 deletion rest/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func makeChildSpan(parent xop.Log, r *http.Request) *xop.Log {
log := parent.Span().Seed(xop.WithBundle(bundle)).Request(r.Method + " " + name)
log.Span().Enum(xopconst.SpanKind, xopconst.SpanKindClient)
log.Span().EmbeddedEnum(xopconst.SpanTypeHTTPClientRequest)
log.Span().Str(xopconst.URL, r.URL.String())
log.Span().String(xopconst.URL, r.URL.String())
return log
}

Expand Down
14 changes: 7 additions & 7 deletions rest/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func Log(log xop.Log) *rest.RequestOpts {
step = log.Sub().Step(o.Description)
step.Span().EmbeddedEnum(xopconst.SpanTypeHTTPClientRequest)
step.Span().Enum(xopconst.SpanKind, xopconst.SpanKindClient)
step.Span().Str(xopconst.URL, r.URL.String())
step.Span().Str(xopconst.HTTPMethod, r.Method)
step.Span().String(xopconst.URL, r.URL.String())
step.Span().String(xopconst.HTTPMethod, r.Method)
r.Header.Set("traceparent", step.Span().Trace().HeaderString())
if !step.Span().TraceBaggage().IsZero() {
r.Header.Set("baggage", step.Span().TraceBaggage().String())
Expand All @@ -53,9 +53,9 @@ func Log(log xop.Log) *rest.RequestOpts {
line = step.Info()
}

line = line.Str(xopconst.HTTPMethod.Key(), result.Request.Method).
Str(xopconst.URL.Key(), result.Request.URL.String()).
Str("description", result.Options.Description)
line = line.String(xopconst.HTTPMethod.Key(), result.Request.Method).
String(xopconst.URL.Key(), result.Request.URL.String()).
String("description", result.Options.Description)

if result.Error != nil {
line = line.Error("error", result.Error)
Expand All @@ -64,12 +64,12 @@ func Log(log xop.Log) *rest.RequestOpts {
line = line.Int(xopconst.HTTPStatusCode.Key(), result.Response.StatusCode)
tr := result.Response.Header.Get("traceresponse")
if tr != "" {
line = line.Str(xopconst.TraceResponse.Key(), tr)
line = line.String(xopconst.TraceResponse.Key(), tr)
}
if !farSideSpan.IsZero() {
// TODO: standard name?
// TODO: use Link()
line = line.Str("b3.spanid", farSideSpan.String())
line = line.String("b3.spanid", farSideSpan.String())
}
if result.DecodeTarget != nil {
line = line.Any("response.data", result.DecodeTarget)
Expand Down
6 changes: 3 additions & 3 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func (s *Span) Link(k *xopconst.LinkAttribute, v trace.Trace) *Span {
return s.eft()
}

// Str adds a string key/value attribute to the current Span.
// String adds a string key/value attribute to the current Span.
// The return value does not need to be used.
func (s *Span) Str(k *xopconst.StrAttribute, v string) *Span {
s.base.MetadataStr(k, v)
func (s *Span) String(k *xopconst.StringAttribute, v string) *Span {
s.base.MetadataString(k, v)
return s.eft()
}

Expand Down
14 changes: 7 additions & 7 deletions sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (l *Log) sendPrefill() {
f(prefilling)
}
if l.settings.tagLinesWithSpanSequence {
prefilling.Str(xopconst.SpanSequeneCode.Key(), l.span.seed.spanSequenceCode)
prefilling.String(xopconst.SpanSequeneCode.Key(), l.span.seed.spanSequenceCode)
}
l.prefilled = prefilling.PrefillComplete(l.settings.prefillMsg)
}
Expand Down Expand Up @@ -277,18 +277,18 @@ func (s *LogSettings) PrefillLink(k string, v trace.Trace) {
})
}

// PrefillStr is used to set a data element that is included on every log
// PrefillString is used to set a data element that is included on every log
// line.
// PrefillStr is not threadsafe with respect to other calls on the same *Sub.
// PrefillString is not threadsafe with respect to other calls on the same *Sub.
// Should not be used after Step(), Fork(), or Log() is called.
func (s *Sub) PrefillStr(k string, v string) *Sub {
s.settings.PrefillStr(k, v)
func (s *Sub) PrefillString(k string, v string) *Sub {
s.settings.PrefillString(k, v)
return s
}

func (s *LogSettings) PrefillStr(k string, v string) {
func (s *LogSettings) PrefillString(k string, v string) {
s.prefillData = append(s.prefillData, func(line xopbase.Prefilling) {
line.Str(k, v)
line.String(k, v)
})
}

Expand Down
2 changes: 1 addition & 1 deletion sub.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (l *Log) sendPrefill() {
f(prefilling)
}
if l.settings.tagLinesWithSpanSequence {
prefilling.Str(xopconst.SpanSequeneCode.Key(), l.span.seed.spanSequenceCode)
prefilling.String(xopconst.SpanSequeneCode.Key(), l.span.seed.spanSequenceCode)
}
l.prefilled = prefilling.PrefillComplete(l.settings.prefillMsg)
}
Expand Down
13 changes: 7 additions & 6 deletions tools/xopzzz/xopzzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var macros = map[string]map[string]string{
"Int16": "int16",
"Int8": "int8",
"Int": "int",
"Str": "string",
"String": "string",
"Link": "trace.Trace",
"Any": "interface{}",
"Time": "time.Time",
Expand All @@ -42,7 +42,7 @@ var macros = map[string]map[string]string{
"Bool": "bool",
"Float64": "float64",
"Int64": "int64",
"Str": "string",
"String": "string",
"Link": "trace.Trace",
"Any": "interface{}",
"Time": "time.Time",
Expand All @@ -69,10 +69,11 @@ var macros = map[string]map[string]string{
"Uint16": "uint16",
"Uint32": "uint32",
},
// BaseData are the data types that are supported on a per-line basis
"BaseData": {
"Int": "int64",
"Uint": "uint64",
"Str": "string",
"Int": "int64", // TODO: change to Int64
"Uint": "uint64", // TODO: change to Uint64
"String": "string",
"Bool": "bool",
"Any": "interface{}",
"Link": "trace.Trace",
Expand All @@ -92,7 +93,7 @@ var macros = map[string]map[string]string{
"Uint16": "uint16",
"Uint32": "uint32",
"Uint64": "uint64",
"Str": "string",
"String": "string",
"Bool": "bool",
"Any": "interface{}",
"Link": "trace.Trace",
Expand Down
8 changes: 4 additions & 4 deletions xopbase/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Logger is the bottom half of a logger -- the part that actually
// outputs data somewhere. There can be many Logger implementations.
type Logger interface {
Request(span trace.Bundle, description string) Request
Request(ts time.Time, span trace.Bundle, description string) Request

// ID returns a unique id for this instance of a logger. This
// is used to prevent duplicate Requets from being created when
Expand Down Expand Up @@ -63,8 +63,8 @@ type Span interface {
MetadataInt64(*xopconst.Int64Attribute, int64)
// MetadataLink adds a key/value pair to describe the span.
MetadataLink(*xopconst.LinkAttribute, trace.Trace)
// MetadataStr adds a key/value pair to describe the span.
MetadataStr(*xopconst.StrAttribute, string)
// MetadataString adds a key/value pair to describe the span.
MetadataString(*xopconst.StringAttribute, string)
// MetadataTime adds a key/value pair to describe the span.
MetadataTime(*xopconst.TimeAttribute, time.Time)

Expand Down Expand Up @@ -135,7 +135,7 @@ type ObjectParts interface {
Float64(string, float64)
Int(string, int64)
Link(string, trace.Trace)
Str(string, string)
String(string, string)
Time(string, time.Time)
Uint(string, uint64)
}
Expand Down
2 changes: 1 addition & 1 deletion xopbase/base.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// Logger is the bottom half of a logger -- the part that actually
// outputs data somewhere. There can be many Logger implementations.
type Logger interface {
Request(span trace.Bundle, description string) Request
Request(ts time.Time, span trace.Bundle, description string) Request

// ID returns a unique id for this instance of a logger. This
// is used to prevent duplicate Requets from being created when
Expand Down
14 changes: 7 additions & 7 deletions xopconst/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ func (s Make) TryLinkAttribute() (_ *LinkAttribute, err error) {
return &LinkAttribute{Attribute: s.attribute(trace.Trace{}, &err, AttributeTypeLink)}, err
}

func (s Make) StrAttribute() *StrAttribute {
return &StrAttribute{Attribute: s.attribute("", nil, AttributeTypeStr)}
func (s Make) StringAttribute() *StringAttribute {
return &StringAttribute{Attribute: s.attribute("", nil, AttributeTypeString)}
}

func (s Make) TryStrAttribute() (_ *StrAttribute, err error) {
return &StrAttribute{Attribute: s.attribute("", &err, AttributeTypeStr)}, err
func (s Make) TryStringAttribute() (_ *StringAttribute, err error) {
return &StringAttribute{Attribute: s.attribute("", &err, AttributeTypeString)}, err
}

func (s Make) BoolAttribute() *BoolAttribute {
Expand Down Expand Up @@ -234,7 +234,7 @@ const (
AttributeTypeInt64
AttributeTypeInt8
AttributeTypeLink
AttributeTypeStr
AttributeTypeString
AttributeTypeTime
)

Expand Down Expand Up @@ -287,9 +287,9 @@ type Int64Attribute struct{ Attribute }
// with trace.Trace values.
type LinkAttribute struct{ Attribute }

// StrAttribute represents an attribute key that can be used
// StringAttribute represents an attribute key that can be used
// with string values.
type StrAttribute struct{ Attribute }
type StringAttribute struct{ Attribute }

// TimeAttribute represents an attribute key that can be used
// with time.Time values.
Expand Down
8 changes: 4 additions & 4 deletions xopconst/attributes.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (s Make) TryLinkAttribute() (_ *LinkAttribute, err error) {
return &LinkAttribute{Attribute: s.attribute(trace.Trace{}, &err, AttributeTypeLink)}, err
}

func (s Make) StrAttribute() *StrAttribute {
return &StrAttribute{Attribute: s.attribute("", nil, AttributeTypeStr)}
func (s Make) StringAttribute() *StringAttribute {
return &StringAttribute{Attribute: s.attribute("", nil, AttributeTypeString)}
}
func (s Make) TryStrAttribute() (_ *StrAttribute, err error) {
return &StrAttribute{Attribute: s.attribute("", &err, AttributeTypeStr)}, err
func (s Make) TryStringAttribute() (_ *StringAttribute, err error) {
return &StringAttribute{Attribute: s.attribute("", &err, AttributeTypeString)}, err
}

func (s Make) BoolAttribute() *BoolAttribute {
Expand Down
Loading