@@ -39,7 +39,12 @@ function Agent (options) {
3939 config : this . config
4040 } )
4141
42- this . edgeMetrics = Metrics . edge . create ( {
42+ this . externalEdgeMetrics = Metrics . externalEdge . create ( {
43+ collectorApi : this . collectorApi ,
44+ config : this . config
45+ } )
46+
47+ this . incomingEdgeMetrics = Metrics . incomingEdge . create ( {
4348 collectorApi : this . collectorApi ,
4449 config : this . config
4550 } )
@@ -78,10 +83,19 @@ Agent.prototype.getConfig = function () {
7883Agent . prototype . serverReceive = function ( data ) {
7984 this . totalRequestCount ++
8085 var spanId = data . spanId
81- var parentId = data . parentId
8286 var originTime = data . originTime
83-
8487 var span = this . openSpan ( data )
88+ var parentId
89+
90+ if ( ! isNaN ( data . parentId ) ) {
91+ parentId = parseInt ( data . parentId , 10 )
92+ }
93+
94+ this . incomingEdgeMetrics . report ( {
95+ serviceKey : data . parentId ,
96+ protocol : data . protocol ,
97+ transportDelay : data . time - data . originTime
98+ } )
8599
86100 span . events . push ( {
87101 time : data . time || microtime . now ( ) ,
@@ -182,17 +196,17 @@ Agent.prototype.clientSend = function (data) {
182196Agent . prototype . clientReceive = function ( data ) {
183197 var span = this . findSpan ( data . id )
184198
185- this . edgeMetrics . report ( {
186- targetHost : data . host ,
187- targetServiceKey : data . targetServiceKey ,
188- protocol : data . protocol ,
189- networkDelay : {
190- incoming : data . networkDelayIncoming ,
191- outgoing : data . networkDelayOutgoing
192- } ,
193- status : data . status ,
194- responseTime : data . responseTime
195- } )
199+ // report external edges only if service is not instrumented by Trace
200+ if ( typeof data . targetServiceKey === 'undefined' ) {
201+ if ( ! data . statusCode || data . statusCode < 500 ) {
202+ this . externalEdgeMetrics . report ( {
203+ targetHost : data . host ,
204+ protocol : data . protocol ,
205+ status : data . status ,
206+ responseTime : data . responseTime
207+ } )
208+ }
209+ }
196210
197211 if ( ! span ) {
198212 return
0 commit comments