Skip to content

Commit

Permalink
addressing/removing TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
muir committed Sep 24, 2022
1 parent bec82ef commit 6613fbd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ That is beginning to change. There is now a
Xop is currently the only Go structured logs and tracing system. Performance-wise,
it's better that Zap, and about on par with Zerolog.

Where Xop shines is in API design.
Where Xop shines is in it's API design.

## The problem with the existing model

The industry model of tracing as documented in the W3C spec requires that spans
have full identifiers. If you give each part of dealing with a request inside
a single server, lots of different spans, then how can you quickly reference the
request-level span from one the sub-spans or one of the other requests that
is a child of the main request. There is no standard way to distinguish a span
is a child of the main request? There is no standard way to distinguish a span
that is simply a separate thread of execution or one that is a related
request on a different server.

Expand Down
3 changes: 0 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ type Config struct {
// too high. It would discourage logging. That said,
// there is a an error, we don't want to completely
// ignore it.
//
// TODO: If ErrorReporter is called too frequently,
// it will automatically be throttled
ErrorReporter func(error)
}

Expand Down
20 changes: 18 additions & 2 deletions xoptest/testlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"regexp"
"runtime"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -121,6 +122,7 @@ type Line struct {
Message string // Prefill text + line text (template evaluated)
Text string // Complete text of line including key=value pairs
Tmpl string // un-evaluated template
Stack []runtime.Frame
}

type Event struct {
Expand Down Expand Up @@ -286,9 +288,8 @@ func (p *Prefilling) PrefillComplete(m string) xopbase.Prefilled {
}
}

func (p *Prefilled) Line(level xopnum.Level, t time.Time, _ []uintptr) xopbase.Line {
func (p *Prefilled) Line(level xopnum.Level, t time.Time, pc []uintptr) xopbase.Line {
atomic.StoreInt64(&p.Span.EndTime, t.UnixNano())
// TODO: stack traces
line := &Line{
Builder: Builder{
Data: make(map[string]interface{}),
Expand All @@ -298,6 +299,21 @@ func (p *Prefilled) Line(level xopnum.Level, t time.Time, _ []uintptr) xopbase.L
Level: level,
Timestamp: t,
}
if len(pc) > 0 {
frames := runtime.CallersFrames(pc)
stack := make([]runtime.Frame, 0, len(pc))
for {
frame, more := frames.Next()
if !strings.Contains(frame.File, "runtime/") {
break
}
stack = append(stack, frame)
if !more {
break
}
}
line.Stack = stack
}
for k, v := range p.Data {
line.Data[k] = v
line.DataType[k] = p.DataType[k]
Expand Down
19 changes: 17 additions & 2 deletions xoptest/testlogger.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ type Line struct {
Message string // Prefill text + line text (template evaluated)
Text string // Complete text of line including key=value pairs
Tmpl string // un-evaluated template
Stack []runtime.Frame
}

type Event struct {
Expand Down Expand Up @@ -282,9 +283,8 @@ func (p *Prefilling) PrefillComplete(m string) xopbase.Prefilled {
}
}

func (p *Prefilled) Line(level xopnum.Level, t time.Time, _ []uintptr) xopbase.Line {
func (p *Prefilled) Line(level xopnum.Level, t time.Time, pc []uintptr) xopbase.Line {
atomic.StoreInt64(&p.Span.EndTime, t.UnixNano())
// TODO: stack traces
line := &Line{
Builder: Builder{
Data: make(map[string]interface{}),
Expand All @@ -294,6 +294,21 @@ func (p *Prefilled) Line(level xopnum.Level, t time.Time, _ []uintptr) xopbase.L
Level: level,
Timestamp: t,
}
if len(pc) > 0 {
frames := runtime.CallersFrames(pc)
stack := make([]runtime.Frame, 0, len(pc))
for {
frame, more := frames.Next()
if !strings.Contains(frame.File, "runtime/") {
break
}
stack = append(stack, frame)
if !more {
break
}
}
line.Stack = stack
}
for k, v := range p.Data {
line.Data[k] = v
line.DataType[k] = p.DataType[k]
Expand Down
4 changes: 1 addition & 3 deletions xoptest/xoptestutil/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ var (
ExampleMetadataDistinctXEnum = xopat.Make{Key: "d-xenum", Multiple: true, Distinct: true, Namespace: "test"}.EnumAttribute(xopconst.SpanKindServer)
)

// TODO: why the skips?
var ExampleMetadataSingleBool = xopat.Make{Key: "s-bool", Namespace: "test"}.BoolAttribute()

var (
ExampleMetadataSingleBool = xopat.Make{Key: "s-bool", Namespace: "test"}.BoolAttribute()
ExampleMetadataLockedBool = xopat.Make{Key: "l-bool", Locked: true, Namespace: "test"}.BoolAttribute()
ExampleMetadataMultipleBool = xopat.Make{Key: "m-bool", Multiple: true, Namespace: "test"}.BoolAttribute()
ExampleMetadataDistinctBool = xopat.Make{Key: "d-bool", Multiple: true, Distinct: true, Namespace: "test"}.BoolAttribute()
Expand Down
1 change: 0 additions & 1 deletion xoptest/xoptestutil/enums.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ var ExampleMetadataLockedXEnum = xopat.Make{Key: "l-xenum", Locked: true, Namesp
var ExampleMetadataMultipleXEnum = xopat.Make{Key: "m-xenum", Multiple: true, Namespace: "test"}.EnumAttribute(xopconst.SpanKindServer)
var ExampleMetadataDistinctXEnum = xopat.Make{Key: "d-xenum", Multiple: true, Distinct: true, Namespace: "test"}.EnumAttribute(xopconst.SpanKindServer)

// TODO: why the skips?
// MACRO ZZZAttribute SKIP:Any,Enum
var ExampleMetadataSingleZZZ = xopat.Make{Key: "s-zzz", Namespace: "test"}.ZZZAttribute()
var ExampleMetadataLockedZZZ = xopat.Make{Key: "l-zzz", Locked: true, Namespace: "test"}.ZZZAttribute()
Expand Down

0 comments on commit 6613fbd

Please sign in to comment.