Skip to content

Commit

Permalink
fix(instrumenation/httpServer): status code getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton authored and hekike committed May 17, 2017
1 parent 9a9e994 commit b463c22
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/instrumentations/trace-instrumentation-http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function httpServer (listener, agent) {
alreadyEnded = true
writeHeadAlreadyCalled = true
var ssTime = microtime.now()
var statusCode = response.statusCode || arguments[0]
var statusCode = arguments[0] || response.statusCode
var skipCollecting = isStatusCodeIgnored(ignoreStatusCodes, statusCode)
var status = statusCode >= 400 ? 'bad' : 'ok'
var ss = collector.serverSend({
Expand Down Expand Up @@ -157,7 +157,7 @@ function httpServer (listener, agent) {
debug.warn('httpServer', '[Warning] failed to create SS, cannot intrument headers')
}
agent.rpmMetrics.addResponseTime(ssTime - srTime)
agent.rpmMetrics.addStatusCode(response.statusCode)
agent.rpmMetrics.addStatusCode(statusCode)
} else {
debug.warn('httpServer', 'writeHead called multiple times, wrongly reported status codes may occur')
}
Expand Down
28 changes: 28 additions & 0 deletions lib/instrumentations/trace-instrumentation-http/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,34 @@ describe('The http.Server.prototype wrapper module', function () {
})
})

it('calls agent.tracer.collector.serverSend with expected payload: status code in writeHead', function () {
this.sandbox.stub(microtime, 'now').returns(5)
var s = server(original, agent)

var request = {
headers: {
host: 'host',
'x-span-id': 'comm-id',
'x-request-id': 'tr-id',
'x-parent': '1'
},
url: '/',
method: 'GET'
}
response.statusCode = 401

s(request, response)

response.writeHead(200)

expect(agent.tracer.collector.serverSend.args[0][0]).to.eql({
data: { statusCode: 200 },
protocol: 'http',
status: 'ok',
severity: agent.tracer.collector.defaultSeverity
})
})

it('calls agent.tracer.collector.serverSend with expected briefcase', function () {
this.sandbox.stub(microtime, 'now').returns(5)
var s = server(original, agent)
Expand Down

0 comments on commit b463c22

Please sign in to comment.