Skip to content

Commit 257190d

Browse files
committed
chore(): more descriptive logging
1 parent b948c44 commit 257190d

4 files changed

Lines changed: 48 additions & 9 deletions

File tree

lib/instrumentations/core/http/request.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ function httpClient (originalHttpRequest, agent) {
3030
return originalHttpRequest.apply(this, arguments)
3131
}
3232

33+
var resource = util.formatDataUrl(requestParams.path)
34+
3335
var cs = collector.clientSend({
3436
protocol: 'http',
3537
host: requestParams.host,
36-
resource: util.formatDataUrl(requestParams.path),
38+
resource: resource,
3739
action: requestParams.method
3840
}, {
3941
communication: communication,
@@ -63,13 +65,15 @@ function httpClient (originalHttpRequest, agent) {
6365
requestParams.headers['x-client-send'] = String(cs.duffelBag.timestamp)
6466
requestParams.headers['x-span-id'] = cs.duffelBag.communicationId
6567

66-
debug('#httpClient', format('CS(%s) [must-collect: %s]', csCtx.communicationId, mustCollect))
68+
debug('#httpClient', format('CS(%s) [%s %s %s %s] [must-collect: %s]',
69+
csCtx.communicationId, 'http', requestParams.method, resource,
70+
requestParams.host, mustCollect))
6771

6872
var returned = originalHttpRequest.apply(this, arguments)
6973

7074
// returns with error
7175
returned.on('error', function (err) {
72-
debug('#httpClient', format('CS(%s) network error: %s', csCtx.communicationId, err.code))
76+
debug('#httpClient', format('NE(%s) [%s]', csCtx.communicationId, err.code))
7377
collector.networkError(cs.briefcase, err)
7478
})
7579

@@ -90,11 +94,14 @@ function httpClient (originalHttpRequest, agent) {
9094
targetServiceKey: serviceKey
9195
}
9296

93-
debug('#httpClient', format('CR(%s) [severity: %s]', csCtx.communicationId, severity))
97+
var status = incomingMessage.statusCode > 399 ? 'bad' : 'ok'
98+
99+
debug('#httpClient', format('CR(%s) [%s %s %s] [severity: %s]', csCtx.communicationId,
100+
'http', status, incomingMessage.statusCode, severity))
94101

95102
collector.clientRecv({
96103
protocol: 'http',
97-
status: incomingMessage.statusCode > 399 ? 'bad' : 'ok',
104+
status: status,
98105
data: {
99106
statusCode: incomingMessage.statusCode
100107
}

lib/instrumentations/core/http/server.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var debug = require('debug')('risingstack/trace:agent:instrumentations')
33
var Shimmer = require('../../../utils/shimmer')
44

55
var util = require('./util')
6+
var format = require('util').format
67

78
function isPathIgnored (ignorePaths, currentPath) {
89
if (!ignorePaths || !ignorePaths.length) {
@@ -71,15 +72,21 @@ function httpServer (listener, agent) {
7172
timestamp: timestamp
7273
}
7374

75+
var resource = util.formatDataUrl(requestUrl)
76+
7477
var payload = {
7578
host: headers.host,
7679
action: request.method,
77-
resource: util.formatDataUrl(requestUrl),
80+
resource: resource,
7881
protocol: 'http'
7982
}
8083

8184
var sr = collector.serverRecv(payload, duffelBag)
8285

86+
debug('#httpServer', format('SR(%s) [%s %s %s %s] [must-collect: %s]',
87+
sr.briefcase.communication.id, 'http', request.method, resource,
88+
headers.host, !!headers['x-must-collect']))
89+
8390
incomingEdgeMetrics.report({
8491
serviceKey: parentServiceKey,
8592
protocol: 'http',
@@ -106,21 +113,29 @@ function httpServer (listener, agent) {
106113
tracerBriefcase = sr.briefcase
107114
}
108115
var skipCollecting = isStatusCodeIgnored(ignoreStatusCodes, statusCode)
116+
var status = statusCode >= 400 ? 'bad' : 'ok'
109117
var ss = collector.serverSend({
110118
protocol: 'http',
111-
status: statusCode >= 400 ? 'bad' : 'ok',
119+
status: status,
112120
data: {
113121
statusCode: statusCode
114122
}
115123
}, tracerBriefcase, { skip: skipCollecting })
124+
125+
var mustCollect = collector.LEVELS.gte(ss.duffelBag.severity, collector.mustCollectSeverity)
126+
127+
debug('#httpServer', format('SS(%s) [%s %s %s] [must-collect: %s]',
128+
tracerBriefcase.communication && tracerBriefcase.communication.id, 'http', status, statusCode,
129+
mustCollect))
130+
116131
if (!ss.error) {
117132
if (ss.duffelBag.targetServiceKey != null) {
118133
response.setHeader('x-parent', String(ss.duffelBag.targetServiceKey))
119134
}
120135
if (ss.duffelBag.timestamp != null) {
121136
response.setHeader('x-server-send', String(ss.duffelBag.timestamp))
122137
}
123-
if (collector.LEVELS.gte(ss.duffelBag.severity, collector.mustCollectSeverity)) {
138+
if (mustCollect) {
124139
response.setHeader('x-must-collect', '1')
125140
}
126141
} else {

lib/instrumentations/utils/wrapQuery.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var microtime = require('../../optionalDependencies/microtime')
22
var consts = require('../../consts')
33
var EventEmitter = require('events')
4+
var debug = require('debug')('risingstack/trace:agent:instrumentations')
5+
var format = require('util').format
46

57
function wrapQuery (original, args, agent, params) {
68
var _params = params || {}
@@ -13,7 +15,8 @@ function wrapQuery (original, args, agent, params) {
1315
var briefcase = agent.storage.get('tracer.briefcase')
1416
var communication = briefcase && briefcase.communication
1517
var severity = briefcase && briefcase.severity
16-
return agent.tracer.collector.clientSend({
18+
19+
var cs = agent.tracer.collector.clientSend({
1720
protocol: _params.protocol,
1821
action: _params.method,
1922
resource: _params.url,
@@ -23,12 +26,25 @@ function wrapQuery (original, args, agent, params) {
2326
communication: communication,
2427
severity: severity
2528
})
29+
30+
debug('#wrapQuery', format('CS(%s) [%s %s %s %s]',
31+
cs.briefcase.csCtx.communicationId, _params.protocol,
32+
_params.method, _params.url,
33+
_params.host))
34+
35+
return cs
2636
},
37+
2738
reportReceive: function (err, cs) {
2839
var severity = err
2940
? collector.mustCollectSeverity
3041
: collector.defaultSeverity
3142

43+
var status = err ? 'bad' : 'ok'
44+
45+
debug('#wrapQuery', format('CR(%s) [%s %s] [severity: %s]',
46+
cs.briefcase.csCtx.communicationId, _params.protocol, status, severity))
47+
3248
collector.clientRecv({
3349
protocol: _params.protocol,
3450
status: err ? 'bad' : 'ok'

lib/trace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var traceNoop = {
1818
}
1919

2020
function Trace (config) {
21+
debug('#Trace', 'constructing with configuration', config)
2122
this._agent = Agent.create({
2223
config: config
2324
})

0 commit comments

Comments
 (0)