Skip to content

Commit 48e12cf

Browse files
committed
fix(agent): check for serviceKey uses lodash.isNumber
1 parent 0a98229 commit 48e12cf

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

lib/agent/api/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var https = require('https')
22
var url = require('url')
33
var util = require('util')
44
var requestSync = require('sync-request')
5+
var isNumber = require('lodash.isnumber')
56
var debug = require('debug')('risingstack/trace')
67
var format = require('util').format
78

@@ -69,7 +70,7 @@ CollectorApi.prototype._send = function (destinationUrl, data) {
6970
}
7071

7172
CollectorApi.prototype.sendRpmMetrics = function (data) {
72-
if (isNaN(this.serviceKey)) {
73+
if (!isNumber(this.serviceKey)) {
7374
debug('Service id not present, cannot send rpm metrics')
7475
return
7576
}
@@ -79,7 +80,7 @@ CollectorApi.prototype.sendRpmMetrics = function (data) {
7980
}
8081

8182
CollectorApi.prototype.sendApmMetrics = function (data) {
82-
if (isNaN(this.serviceKey)) {
83+
if (!isNumber(this.serviceKey)) {
8384
debug('Service id not present, cannot send metrics')
8485
return
8586
}

lib/agent/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var microtime = require('microtime')
33
var uuid = require('node-uuid')
44
var cls = require('continuation-local-storage')
55
var defaults = require('lodash.defaults')
6+
var isNumber = require('lodash.isnumber')
67

78
var CollectorApi = require('./api')
89
var Metrics = require('./metrics')
@@ -310,7 +311,7 @@ Agent.prototype.openSpan = function (data) {
310311
dataTrace.host = data.host
311312

312313
// fallback to appName if service id is not present
313-
if (isNaN(this.serviceKey)) {
314+
if (!isNumber(this.serviceKey)) {
314315
dataTrace.serviceName = this.serviceName
315316
}
316317

lib/instrumentations/core/http/server.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var url = require('url')
22

33
var qs = require('qs')
44
var microtime = require('microtime')
5+
var isNumber = require('lodash.isnumber')
56
var debug = require('debug')('risingstack/trace')
67

78
var util = require('./util')
@@ -100,7 +101,7 @@ function wrapListener (listener, agent, mustCollectStore) {
100101

101102
/* Service name may be unavailable due to uninitialized reporter */
102103
var serviceKey = agent.getServiceKey()
103-
if (!isNaN(serviceKey)) {
104+
if (isNumber(serviceKey)) {
104105
debug('trace event (ss); request: %s, x-parent header has been set %s', requestId, serviceKey)
105106
response.setHeader('x-parent', serviceKey)
106107
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"event-loop-stats": "1.0.0",
5050
"gc-stats": "1.0.0",
5151
"lodash.defaults": "4.0.1",
52+
"lodash.isnumber": "3.0.3",
5253
"microtime": "2.0.0",
5354
"node-uuid": "1.4.7",
5455
"qs": "4.0.0",

0 commit comments

Comments
 (0)