Skip to content

Commit 2de5967

Browse files
committed
fix(windows): fallback if native modules cannot be complied
1 parent 1fa6b4f commit 2de5967

File tree

8 files changed

+66
-13
lines changed

8 files changed

+66
-13
lines changed

lib/agent/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var debug = require('debug')('risingstack/trace')
2-
var microtime = require('microtime')
2+
var microtime = require('../optionalDependencies/microtime')
33
var uuid = require('node-uuid')
44
var cls = require('@risingstack/continuation-local-storage')
55
var defaults = require('lodash.defaults')

lib/agent/metrics/apm/index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var os = require('os')
2-
var gc = require('gc-stats')()
3-
var eventLoopStats = require('event-loop-stats')
2+
var gc = require('../../../optionalDependencies/gc-stats')()
3+
var eventLoopStats = require('../../../optionalDependencies/event-loop-stats')
44

55
var BYTES_TO_MEGABYTES = 1024 * 1024
66

@@ -41,13 +41,24 @@ function ApmMetrics (options) {
4141
}
4242

4343
ApmMetrics.prototype.sendMetrics = function () {
44-
this.collectorApi.sendApmMetrics({
44+
var eventloop = this.getEventLoop()
45+
var gc = this.getGC()
46+
47+
var databag = {
4548
timestamp: (new Date()).toISOString(),
4649
memory: this.getMemory(),
47-
cpu: this.getCpu(),
48-
eventloop: this.getEventLoop(),
49-
gc: this.getGC()
50-
})
50+
cpu: this.getCpu()
51+
}
52+
53+
if (eventloop.stats) {
54+
databag.eventloop = eventloop
55+
}
56+
57+
if (gc) {
58+
databag.gc = gc
59+
}
60+
61+
this.collectorApi.sendApmMetrics(databag)
5162

5263
this.reset()
5364
}

lib/instrumentations/core/http/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var debug = require('debug')('risingstack/trace')
22
var url = require('url')
3-
var microtime = require('microtime')
3+
var microtime = require('../../../optionalDependencies/microtime')
44

55
var util = require('./util')
66
var consts = require('../../../consts')

lib/instrumentations/core/http/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var url = require('url')
22

33
var qs = require('qs')
4-
var microtime = require('microtime')
4+
var microtime = require('../../../optionalDependencies/microtime')
55
var isNumber = require('lodash.isnumber')
66
var debug = require('debug')('risingstack/trace')
77

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var eventLoopStats
2+
3+
try {
4+
eventLoopStats = require('event-loop-stats')
5+
} catch (ex) {
6+
console.log('event-loop-stats couldn\'t be required, possibly a compiler issue - continuing')
7+
eventLoopStats = {
8+
sense: function () {}
9+
}
10+
}
11+
12+
module.exports = eventLoopStats
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var gcStats
2+
3+
try {
4+
gcStats = require('gc-stats')
5+
} catch (ex) {
6+
gcStats = function () {
7+
console.log('gc-stats couldn\'t be required, possibly a compiler issue - continuing')
8+
return {
9+
on: function () {}
10+
}
11+
}
12+
}
13+
14+
module.exports = gcStats
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var microtime
2+
3+
try {
4+
microtime = require('microtime')
5+
} catch (ex) {
6+
console.log('microtime couldn\'t be required, possibly a compiler issue - continuing')
7+
microtime = {
8+
now: function () {
9+
return Date.now() * 1000
10+
}
11+
}
12+
}
13+
14+
module.exports = microtime

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@
4343
"@risingstack/continuation-local-storage": "1.0.2",
4444
"bl": "1.1.2",
4545
"debug": "2.2.0",
46-
"event-loop-stats": "1.0.0",
47-
"gc-stats": "1.0.0",
4846
"lodash.assign": "4.0.6",
4947
"lodash.defaults": "4.0.1",
5048
"lodash.isnumber": "3.0.3",
51-
"microtime": "2.0.0",
5249
"node-uuid": "1.4.7",
5350
"qs": "6.1.0",
5451
"sync-request": "3.0.0"
5552
},
53+
"optionalDependencies": {
54+
"microtime": "2.0.0",
55+
"event-loop-stats": "1.0.0",
56+
"gc-stats": "1.0.0"
57+
},
5658
"devDependencies": {
5759
"amqplib": "0.4.1",
5860
"async": "1.5.2",

0 commit comments

Comments
 (0)