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

Add SpanID tag to all non-entry events #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions v1/ao/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
keyQueryString = "Query-String"
keyRemoteStatus = "RemoteStatus"
keyContentLength = "ContentLength"
keySpanID = "SpanID"
)

// Span is used to measure a span of time associated with an activity
Expand Down Expand Up @@ -231,6 +232,7 @@ func (s *span) End(args ...interface{}) {
for _, prof := range s.childProfiles {
prof.End()
}
args = append([]interface{}{keySpanID, s.spanID}, args)
args = append(args, s.endArgs...)
for _, edge := range s.childEdges { // add Edge KV for each joined child
args = append(args, keyEdge, edge)
Expand Down Expand Up @@ -268,6 +270,7 @@ func (s *layerSpan) Info(args ...interface{}) {
// InfoWithOptions reports a new info event with the KVs and options provided
func (s *layerSpan) InfoWithOptions(opts SpanOptions, args ...interface{}) {
if s.ok() {
args = append([]interface{}{keySpanID, s.spanID}, args)
kvs := addKVsFromOpts(opts, args...)
s.aoCtx.ReportEvent(reporter.LabelInfo, s.layerName(), kvs...)
}
Expand Down Expand Up @@ -328,6 +331,7 @@ func (s *span) GetTransactionName() string {
func (s *span) Error(class, msg string) {
if s.ok() {
s.aoCtx.ReportEvent(reporter.LabelError, s.layerName(),
keySpanID, s.spanID,
keySpec, "error",
keyErrorClass, class,
keyErrorMsg, msg,
Expand All @@ -343,10 +347,18 @@ func (s *span) Err(err error) {
s.Error("error", err.Error())
}

func spanIDFromContext(aoCtx reporter.Context) string {
if s := aoCtx.MetadataString(); len(s) >= 58 {
return s[42:58]
}
return ""
}

// span satisfies the Extent interface and consolidates common reporting routines used by
// both Span and Profile interfaces.
type span struct {
labeler
spanID string
aoCtx reporter.Context
parent Span
childEdges []reporter.Context // for reporting in exit event
Expand Down Expand Up @@ -431,7 +443,7 @@ func newSpan(aoCtx reporter.Context, spanName string, parent Span, args ...inter
if err := aoCtx.ReportEvent(ll.entryLabel(), ll.layerName(), args...); err != nil {
return nullSpan{}
}
return &layerSpan{span: span{aoCtx: aoCtx.Copy(), labeler: ll, parent: parent}}
return &layerSpan{span: span{spanID: spanIDFromContext(aoCtx), aoCtx: aoCtx.Copy(), labeler: ll, parent: parent}}

}

Expand All @@ -449,7 +461,7 @@ func newProfile(aoCtx reporter.Context, profileName string, parent Span, args ..
); err != nil {
return nullSpan{}
}
p := &profileSpan{span{aoCtx: aoCtx.Copy(), labeler: pl, parent: parent,
p := &profileSpan{span{spanID: spanIDFromContext(aoCtx), aoCtx: aoCtx.Copy(), labeler: pl, parent: parent,
endArgs: []interface{}{keyLanguage, "go", keyProfileName, profileName}}}
if parent != nil && parent.ok() {
parent.addProfile(p)
Expand Down
7 changes: 4 additions & 3 deletions v1/ao/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewTraceFromID(spanName, mdStr string, cb func() KVMap) Trace {
return NewNullTrace()
}
t := &aoTrace{
layerSpan: layerSpan{span: span{aoCtx: ctx, labeler: spanLabeler{spanName}}},
layerSpan: layerSpan{span: span{spanID: spanIDFromContext(ctx), aoCtx: ctx, labeler: spanLabeler{spanName}}},
}
t.SetStartTime(time.Now())
return t
Expand Down Expand Up @@ -200,10 +200,11 @@ func (t *aoTrace) reportExit() {
for _, edge := range t.childEdges { // add Edge KV for each joined child
t.endArgs = append(t.endArgs, keyEdge, edge)
}
args := append([]interface{}{keySpanID, t.spanID}, t.endArgs)
if t.exitEvent != nil { // use exit event, if one was provided
t.exitEvent.ReportContext(t.aoCtx, true, t.endArgs...)
t.exitEvent.ReportContext(t.aoCtx, true, args...)
} else {
t.aoCtx.ReportEvent(reporter.LabelExit, t.layerName(), t.endArgs...)
t.aoCtx.ReportEvent(reporter.LabelExit, t.layerName(), args...)
}

t.childEdges = nil // clear child edge list
Expand Down