Skip to content

Commit b98f985

Browse files
committed
misc
1 parent 8d899dd commit b98f985

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

scouterx/netio/tracecontext.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ type TraceContext struct {
1313
LastMethod string
1414
IsStream bool
1515

16+
Inherit bool
17+
InheritStartTime time.Time
18+
1619
Goid int
1720
Parent *TraceContext
1821
Profile *ProfileCollector
@@ -57,7 +60,7 @@ type TraceContext struct {
5760
IsChildTx bool
5861
Caller int64
5962
Callee int64
60-
CallerObjHash int64
63+
CallerObjHash int32
6164

6265
Login string
6366
Desc string

scouterx/strace/tracemain.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,63 @@ func EndService(ctx context.Context) {
210210
endAnyService(ctx)
211211
}
212212

213+
func StartNewInheritanceService(ctx context.Context, parentTctx *netio.TraceContext) (newCtx context.Context, newTctx *netio.TraceContext) {
214+
common.ReportScouterPanic()
215+
if ctx == nil {
216+
ctx = context.Background()
217+
}
218+
newCtx, newTctx = startService(ctx, parentTctx.ServiceName, parentTctx.RemoteIp)
219+
newTctx = inheritTctx(newTctx, parentTctx)
220+
221+
return newCtx, newTctx
222+
}
223+
224+
func inheritTctx(newTctx *netio.TraceContext, parentTctx *netio.TraceContext) *netio.TraceContext {
225+
newTctx.Inherit = true
226+
newTctx.InheritStartTime = newTctx.StartTime
227+
newTctx.StartTime = parentTctx.StartTime
228+
newTctx.XType = parentTctx.XType
229+
newTctx.Profile = parentTctx.Profile
230+
newTctx.ProfileCount = parentTctx.ProfileCount
231+
newTctx.ProfileSize = parentTctx.ProfileSize
232+
newTctx.Profile.Add(netdata.NewMessageStep("scouter inheritance step", 0))
233+
newTctx.IsStream = parentTctx.IsStream
234+
235+
newTctx.Error = parentTctx.Error
236+
newTctx.HttpMethod = parentTctx.HttpMethod
237+
newTctx.HttpQuery = parentTctx.HttpQuery
238+
newTctx.HttpContentType = parentTctx.HttpContentType
239+
240+
newTctx.SqlCount = parentTctx.SqlCount
241+
newTctx.SqlTime = parentTctx.SqlTime
242+
newTctx.Sqltext = parentTctx.Sqltext
243+
244+
newTctx.ApicallName = parentTctx.ApicallName
245+
newTctx.ApicallCount = parentTctx.ApicallCount
246+
newTctx.ApicallTime = parentTctx.ApicallTime
247+
newTctx.ApicallTarget = parentTctx.ApicallTarget
248+
249+
newTctx.Userid = parentTctx.Userid
250+
newTctx.UserAgent = parentTctx.UserAgent
251+
newTctx.UserAgentString = parentTctx.UserAgentString
252+
newTctx.Referer = parentTctx.Referer
253+
254+
newTctx.IsChildTx = true
255+
newTctx.Caller = parentTctx.Txid
256+
newTctx.CallerObjHash = ac.ObjHash
257+
258+
newTctx.Login = parentTctx.Login
259+
newTctx.Desc = parentTctx.Desc
260+
261+
newTctx.Text1 = parentTctx.Text1
262+
newTctx.Text2 = parentTctx.Text2
263+
newTctx.Text3 = parentTctx.Text3
264+
newTctx.Text4 = parentTctx.Text4
265+
newTctx.Text5 = parentTctx.Text5
266+
267+
return newTctx
268+
}
269+
213270
//<usage> for chained goroutine tracing
214271
//
215272
//GoWithTrace(ctx, "myFuncName()", func(cascadeGoCtx context.Context) {
@@ -307,6 +364,9 @@ func endAnyServiceOfTraceContext(tctx *netio.TraceContext) {
307364
tctxmanager.End(tctx)
308365

309366
elapsed := util.MillisToNow(tctx.StartTime)
367+
if tctx.Inherit {
368+
elapsed = util.MillisToNow(tctx.InheritStartTime)
369+
}
310370
discardType := findXLogDiscard(tctx, elapsed)
311371
xlog := tctx.ToXlog(discardType, elapsed)
312372

0 commit comments

Comments
 (0)