Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

API Usage pseudocode (Option 1)

Joel Unzain edited this page Jun 6, 2018 · 7 revisions
# Provide a "Report" interface with methods
# - Report(data string)
# - ReportHeader(data string) 
#  We cannot merge these different methods because we do not want duplicate log entries among the different systems, do we?

#This is a way to know where to delegate all the work of reporting on the spans
#Additionally, it allows users to implement it however they want. 
#They could implement it so span reports are written back to http.Headers, loggers, etc.
#It's possible for us to even provide common out-of-the-box solutions.

spanFactory = money.NewSpanFactory(UserDefinedReporter())

var moneyTraceCtx

#Case 1: First span in this system
rawMoneyTraceCtx = incomingRequest.Header.Get("X-Money-Trace")
moneyTraceCtx = money.DecodeTraceContext(rawMoneyTraceCtx) #Use case 2

#Case 2: Child of an existing span
moneyTraceCtx = existingSpan.ChildMoneyTraceContext() 
#moneyTraceCtx has a new SID and the PID = existingSpan.SID()

span = spanFactory.NewSpan(moneyTraceCtx)
end = span.Start()
anyProcessToMonitor()  #Use case 1
end(SpanResults)

# We want to make a remote call and pass money trace information in the outgoing request
# We identify what the parent span should be for such remote call and encode it 

#Use case 2
outgoingRequest.Header.Add("X-Money-Trace", money.EncodeContext(span.ChildMoneyTraceTxt()))

#Use case 3
for all X-MoneyTrace headers in outgoingRequestResponse.Header:
  spanFactory.ReportHeader(header) 
Clone this wiki locally