Skip to content

Commit 767165e

Browse files
committed
misc
1 parent 9734f7d commit 767165e

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

scouterx/netio/tracecontext.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
)
1010

1111
type TraceContext struct {
12-
Closed bool
13-
LastMethod string
14-
IsStream bool
12+
Closed bool
13+
LastMethod string
14+
IsStream bool
1515

16-
Inherit bool
16+
Inherit bool
1717
InheritStartTime time.Time
1818

1919
Goid int
@@ -42,6 +42,7 @@ type TraceContext struct {
4242
SqlTime int32
4343
Sqltext string
4444

45+
Status int32
4546
ApicallName string
4647
ApicallCount int32
4748
ApicallTime int32
@@ -99,6 +100,8 @@ func (tctx (TraceContext)) ToXlog(discardType netdata.XlogDiscardType, elapsed i
99100
xlog.HasDump = 0
100101
xlog.Error = tctx.Error
101102

103+
xlog.Status = tctx.Status
104+
102105
xlog.DiscardType = discardType
103106
xlog.ProfileSize = int32(tctx.ProfileSize)
104107
xlog.ProfileCount = int32(tctx.ProfileCount)

scouterx/strace/tracemain.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func AddPMessageStep(ctx context.Context, level netdata.PMessageLevel, message s
149149
tctx.Profile.Add(step)
150150
}
151151

152-
func StartHttpService(ctx context.Context, req http.Request) (newCtx context.Context) {
152+
func StartHttpService(ctx context.Context, req *http.Request) (newCtx context.Context) {
153153
defer common.ReportScouterPanic()
154154
if ctx == nil {
155155
return context.Background()
@@ -174,7 +174,7 @@ func StartHttpService(ctx context.Context, req http.Request) (newCtx context.Con
174174
return newCtx
175175
}
176176

177-
func getRemoteIp(req http.Request) string {
177+
func getRemoteIp(req *http.Request) string {
178178
ip := req.RemoteAddr
179179
if ac.TraceHttpClientIpHeaderKey != "" {
180180
headerIp := req.Header.Get(ac.TraceHttpClientIpHeaderKey)
@@ -185,9 +185,20 @@ func getRemoteIp(req http.Request) string {
185185
return strings.Split(ip, ":")[0]
186186
}
187187

188-
func EndHttpService(ctx context.Context, req http.Request, res http.Response) {
189-
//TODO body (of specific service) profile from req.body
188+
func EndHttpService(ctx context.Context, req *http.Request, res *http.Response) {
190189
common.ReportScouterPanic()
190+
//TODO body (of specific service) profile from req.body
191+
192+
if res != nil {
193+
if ctx == nil {
194+
return
195+
}
196+
tctx := tctxmanager.GetTraceContext(ctx)
197+
if tctx == nil || tctx.Closed {
198+
return
199+
}
200+
tctx.Status = int32(res.StatusCode)
201+
}
191202
endAnyService(ctx)
192203
}
193204

@@ -454,7 +465,7 @@ func EndMethod(ctx context.Context, step *netdata.MethodStep) {
454465
tctx.Profile.Pop(step)
455466
}
456467

457-
func profileHttpHeaders(r http.Request, tctx *netio.TraceContext) {
468+
func profileHttpHeaders(r *http.Request, tctx *netio.TraceContext) {
458469
startTime := util.MillisToNow(tctx.StartTime)
459470
if ac.ProfileHttpHeaderEnabled {
460471
notAll := len(ac.ProfileHttpHeaderKeys) > 0

0 commit comments

Comments
 (0)