File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
lib/instrumentations/trace-instrumentation-http Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ function httpServer (listener, agent) {
123123 alreadyEnded = true
124124 writeHeadAlreadyCalled = true
125125 var ssTime = microtime . now ( )
126- var statusCode = response . statusCode || arguments [ 0 ]
126+ var statusCode = arguments [ 0 ] || response . statusCode
127127 var skipCollecting = isStatusCodeIgnored ( ignoreStatusCodes , statusCode )
128128 var status = statusCode >= 400 ? 'bad' : 'ok'
129129 var ss = collector . serverSend ( {
@@ -157,7 +157,7 @@ function httpServer (listener, agent) {
157157 debug . warn ( 'httpServer' , '[Warning] failed to create SS, cannot intrument headers' )
158158 }
159159 agent . rpmMetrics . addResponseTime ( ssTime - srTime )
160- agent . rpmMetrics . addStatusCode ( response . statusCode )
160+ agent . rpmMetrics . addStatusCode ( statusCode )
161161 } else {
162162 debug . warn ( 'httpServer' , 'writeHead called multiple times, wrongly reported status codes may occur' )
163163 }
Original file line number Diff line number Diff line change @@ -263,6 +263,34 @@ describe('The http.Server.prototype wrapper module', function () {
263263 } )
264264 } )
265265
266+ it ( 'calls agent.tracer.collector.serverSend with expected payload: status code in writeHead' , function ( ) {
267+ this . sandbox . stub ( microtime , 'now' ) . returns ( 5 )
268+ var s = server ( original , agent )
269+
270+ var request = {
271+ headers : {
272+ host : 'host' ,
273+ 'x-span-id' : 'comm-id' ,
274+ 'x-request-id' : 'tr-id' ,
275+ 'x-parent' : '1'
276+ } ,
277+ url : '/' ,
278+ method : 'GET'
279+ }
280+ response . statusCode = 401
281+
282+ s ( request , response )
283+
284+ response . writeHead ( 200 )
285+
286+ expect ( agent . tracer . collector . serverSend . args [ 0 ] [ 0 ] ) . to . eql ( {
287+ data : { statusCode : 200 } ,
288+ protocol : 'http' ,
289+ status : 'ok' ,
290+ severity : agent . tracer . collector . defaultSeverity
291+ } )
292+ } )
293+
266294 it ( 'calls agent.tracer.collector.serverSend with expected briefcase' , function ( ) {
267295 this . sandbox . stub ( microtime , 'now' ) . returns ( 5 )
268296 var s = server ( original , agent )
You can’t perform that action at this time.
0 commit comments