@@ -39,7 +39,12 @@ function Agent (options) {
39
39
config : this . config
40
40
} )
41
41
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 ( {
43
48
collectorApi : this . collectorApi ,
44
49
config : this . config
45
50
} )
@@ -78,10 +83,19 @@ Agent.prototype.getConfig = function () {
78
83
Agent . prototype . serverReceive = function ( data ) {
79
84
this . totalRequestCount ++
80
85
var spanId = data . spanId
81
- var parentId = data . parentId
82
86
var originTime = data . originTime
83
-
84
87
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
+ } )
85
99
86
100
span . events . push ( {
87
101
time : data . time || microtime . now ( ) ,
@@ -182,17 +196,17 @@ Agent.prototype.clientSend = function (data) {
182
196
Agent . prototype . clientReceive = function ( data ) {
183
197
var span = this . findSpan ( data . id )
184
198
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
+ }
196
210
197
211
if ( ! span ) {
198
212
return
0 commit comments