Skip to content

Commit f1378b2

Browse files
committed
misc
1 parent 84847ff commit f1378b2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

scouterx/strace/tracemain.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ func AddStep(ctx context.Context, step netdata.Step) {
108108
return
109109
}
110110
tctx := tctxmanager.GetTraceContext(ctx)
111+
if tctx == nil {
112+
return
113+
}
111114
tctx.Profile.Add(step)
112115
}
113116

@@ -117,6 +120,9 @@ func AddMessageStep(ctx context.Context, message string) {
117120
return
118121
}
119122
tctx := tctxmanager.GetTraceContext(ctx)
123+
if tctx == nil {
124+
return
125+
}
120126

121127
step := netdata.NewMessageStep(message, util.MillisToNow(tctx.StartTime))
122128
tctx.Profile.Add(step)
@@ -128,6 +134,9 @@ func AddHashedMessageStep(ctx context.Context, message string, value, elapsed in
128134
return
129135
}
130136
tctx := tctxmanager.GetTraceContext(ctx)
137+
if tctx == nil {
138+
return
139+
}
131140

132141
step := netdata.NewHashedMessageStep(netio.SendHashedMessage(message), util.MillisToNow(tctx.StartTime))
133142
step.Value = value
@@ -141,6 +150,9 @@ func AddPMessageStep(ctx context.Context, level netdata.PMessageLevel, message s
141150
return
142151
}
143152
tctx := tctxmanager.GetTraceContext(ctx)
153+
if tctx == nil {
154+
return
155+
}
144156

145157
step := netdata.NewPMessageStep(util.MillisToNow(tctx.StartTime))
146158
step.SetMessage(netio.SendHashedMessage(message), params...)
@@ -182,6 +194,11 @@ func getRemoteIp(req *http.Request) string {
182194
ip = headerIp
183195
}
184196
}
197+
return ip
198+
}
199+
200+
func normalizeIp(ip string) string {
201+
185202
return strings.Split(ip, ":")[0]
186203
}
187204

@@ -334,7 +351,7 @@ func startService(ctx context.Context, serviceName, remoteAddr string) (context.
334351

335352
tctx.ServiceName = serviceName
336353
tctx.ServiceHash = netio.SendServiceName(serviceName)
337-
tctx.RemoteIp = remoteAddr
354+
tctx.RemoteIp = normalizeIp(remoteAddr)
338355
return newCtx, tctx
339356
}
340357

0 commit comments

Comments
 (0)