Skip to content

Commit b9e8795

Browse files
committed
fix(agent): report network error
1 parent 3b808ad commit b9e8795

File tree

3 files changed

+126
-41
lines changed

3 files changed

+126
-41
lines changed

lib/agent/index.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -232,37 +232,18 @@ Agent.prototype.clientSend = function (data) {
232232
return
233233
}
234234

235-
if (data.err) {
236-
span.isForceSampled = true
237-
}
238-
239235
var event = {
240-
time: data.time || microtime.now()
241-
}
242-
243-
if (data.err) {
244-
assign(event, {
245-
type: Agent.ERROR,
246-
data: {
236+
time: data.time || microtime.now(),
237+
type: Agent.CLIENT_SEND,
238+
data: assign({}, data.protocolData
239+
? data.protocolData
240+
: {}, {
241+
protocol: data.protocol,
247242
rpcId: data.childCommId,
248-
type: data.err.type,
249-
message: data.err.message,
250-
raw: data.err.raw
251-
}
252-
})
253-
} else {
254-
assign(event, {
255-
type: Agent.CLIENT_SEND,
256-
data: assign({}, data.protocolData
257-
? data.protocolData
258-
: {}, {
259-
protocol: data.protocol,
260-
rpcId: data.childCommId,
261-
host: data.host,
262-
endpoint: data.url,
263-
method: data.method
264-
})
265-
})
243+
host: data.host,
244+
endpoint: data.url,
245+
method: data.method
246+
})
266247
}
267248

268249
span.events.push(event)
@@ -302,18 +283,39 @@ Agent.prototype.clientReceive = function (data) {
302283

303284
data.time = data.time || this.getMicrotime()
304285

305-
span.events.push({
306-
time: data.time,
307-
type: Agent.CLIENT_RECV,
308-
data: assign({}, data.protocolData
309-
? data.protocolData
310-
: {}, {
311-
protocol: data.protocol,
286+
if (data.err) {
287+
span.isForceSampled = true
288+
}
289+
290+
var event = {
291+
time: data.time || this.getMicrotime()
292+
}
293+
294+
if (data.err) {
295+
assign(event, {
296+
type: Agent.ERROR,
297+
data: {
312298
rpcId: data.childCommId,
313-
status: data.status === consts.EDGE_STATUS.OK ? 'ok' : 'bad',
314-
statusDescription: data.statusDescription
315-
})
316-
})
299+
type: 'network-error',
300+
message: data.err.message,
301+
raw: data.err.raw
302+
}
303+
})
304+
} else {
305+
assign(event, {
306+
type: Agent.CLIENT_RECV,
307+
data: assign({}, data.protocolData
308+
? data.protocolData
309+
: {}, {
310+
protocol: data.protocol,
311+
rpcId: data.childCommId,
312+
status: data.status === consts.EDGE_STATUS.OK ? 'ok' : 'bad',
313+
statusDescription: data.statusDescription
314+
})
315+
})
316+
}
317+
318+
span.events.push(event)
317319
}
318320

319321
Agent.prototype.onCrash = function (data) {

lib/agent/index.spec.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,90 @@ describe('The Trace agent', function () {
314314
}])
315315
})
316316

317+
it('does network error', function () {
318+
agent.sampleRate = 1
319+
agent.serverReceive({
320+
requestId: requestId,
321+
parentCommId: parentCommId,
322+
parentServiceId: parentServiceId,
323+
url: url,
324+
protocol: 'http',
325+
host: host,
326+
method: 'GET'
327+
})
328+
agent.clientSend({
329+
requestId: requestId,
330+
childCommId: childCommId,
331+
method: 'POST',
332+
host: 'remote-host',
333+
url: '/products',
334+
protocol: 'http'
335+
})
336+
337+
agent.clientReceive({
338+
requestId: requestId,
339+
childCommId: childCommId,
340+
host: 'remote-host',
341+
url: '/products',
342+
protocol: 'http',
343+
status: 1,
344+
err: {
345+
message: 'Message',
346+
raw: {
347+
code: 'ECONNRESET',
348+
host: 'localhsot',
349+
port: 80,
350+
syscall: 'connect'
351+
}
352+
}
353+
})
354+
355+
expect(agent.totalRequestCount).to.eql(1)
356+
expect(agent.reservoirSampler.getItems()).to.eql([])
357+
expect(agent.partials[requestId]).to.eql({
358+
requestId: requestId,
359+
isForceSampled: true,
360+
isSampled: false,
361+
events: [{
362+
type: 'sr',
363+
time: time,
364+
data: {
365+
host: host,
366+
protocol: 'http',
367+
rpcId: parentCommId,
368+
endpoint: url,
369+
method: 'GET',
370+
parent: 0,
371+
originTime: undefined
372+
}
373+
}, {
374+
type: 'cs',
375+
time: time,
376+
data: {
377+
protocol: 'http',
378+
rpcId: childCommId,
379+
method: 'POST',
380+
host: 'remote-host',
381+
endpoint: '/products'
382+
}
383+
}, {
384+
data: {
385+
message: 'Message',
386+
raw: {
387+
code: 'ECONNRESET',
388+
host: 'localhsot',
389+
port: 80,
390+
syscall: 'connect'
391+
},
392+
rpcId: '23',
393+
type: 'network-error'
394+
},
395+
time: 12345678,
396+
type: 'err'
397+
}]
398+
})
399+
})
400+
317401
it('does client send', function () {
318402
agent.sampleRate = 1
319403
agent.serverReceive({

lib/instrumentations/core/http/request.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ function wrapRequest (originalHttpRequest, agent, mustCollectStore) {
8585
protocol: consts.PROTOCOLS.HTTP,
8686
status: consts.EDGE_STATUS.NOT_OK,
8787
err: {
88-
type: 'network-error',
8988
message: err.message,
9089
raw: {
9190
code: err.code,

0 commit comments

Comments
 (0)