newrelic 9.0.0 → 9.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,6 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const a = require('async')
9
8
  const fetchSystemInfo = require('../system-info')
10
9
  const logger = require('../logger').child({ component: 'facts' })
11
10
  const os = require('os')
@@ -19,94 +18,95 @@ const LOG_LIBRARIES = ['winston', 'bunyan', 'pino', 'loglevel', 'npmlog', 'fancy
19
18
 
20
19
  module.exports = facts
21
20
 
22
- function facts(agent, callback) {
21
+ async function facts(agent, callback) {
23
22
  const startTime = Date.now()
24
- a.parallel(
25
- {
26
- systemInfo: a.apply(fetchSystemInfo, agent),
27
- environment: agent.environment.getJSON
28
- },
29
- function factMapCb(err, data) {
30
- logger.trace('Facts gathering finished in %dms', Date.now() - startTime)
31
23
 
32
- if (err) {
33
- logger.debug(err, 'Failed to load system facts!')
34
- }
35
- data = data || Object.create(null)
36
- const systemInfo = data.systemInfo || Object.create(null)
37
- const environment = data.environment || []
38
-
39
- countSupportabilityForLogLibraries(environment, agent)
40
-
41
- const hostname = agent.config.getHostnameSafe()
42
- const results = {
43
- utilization: {
44
- metadata_version: 5,
45
- logical_processors: systemInfo.logicalProcessors || null,
46
- total_ram_mib: systemInfo.memory || null,
47
- hostname: hostname
48
- },
49
- pid: process.pid,
50
- host: hostname,
51
- display_host: agent.config.getDisplayHost() || hostname,
52
- language: 'nodejs',
53
- app_name: agent.config.applications(),
54
- agent_version: agent.version,
55
- environment: environment,
56
- settings: agent.config.publicSettings(),
57
- high_security: agent.config.high_security,
58
- labels: parseLabels(agent.config.labels),
59
- metadata: Object.keys(process.env).reduce((obj, key) => {
60
- if (key.startsWith('NEW_RELIC_METADATA_')) {
61
- obj[key] = process.env[key]
62
- }
63
- return obj
64
- }, {})
65
- }
24
+ const systemInfoPromise = new Promise((resolve) => {
25
+ fetchSystemInfo(agent, (_, data) => {
26
+ resolve(data)
27
+ })
28
+ })
66
29
 
67
- logger.debug('New Relic metadata %o', results.metadata)
68
-
69
- /**
70
- * WARNING: This may not make sense if you are familiar with our config
71
- * and updating of config from server. But the intention here is to always
72
- * send the values from user config of harvest limits because on connect these
73
- * values get reconfigured based on harvest cycle intervals. So if you originally
74
- * had 1000 and a harvest of 5 seconds the new value of the harvest limit would be 83.
75
- * Then every subsequent connect request it would continue to decrease until it eventually hit 0
76
- * and we would never be sampling a certain piece of data.
77
- */
78
- results.event_harvest_config = {
79
- harvest_limits: {
80
- analytic_event_data: agent.config.transaction_events.max_samples_stored,
81
- custom_event_data: agent.config.custom_insights_events.max_samples_stored,
82
- error_event_data: agent.config.error_collector.max_event_samples_stored,
83
- span_event_data: agent.config.span_events.max_samples_stored,
84
- log_event_data: agent.config.application_logging.forwarding.max_samples_stored
85
- }
86
- }
30
+ const environmentPromise = agent.environment.getJSON()
31
+ let [systemInfo, environment] = await Promise.all([systemInfoPromise, environmentPromise])
32
+ logger.trace('Facts gathering finished in %dms', Date.now() - startTime)
87
33
 
88
- results.identifier = getIdentifierOverride(results.app_name)
34
+ if (environment.failed) {
35
+ logger.debug(environment.err, 'Failed to load system facts!')
36
+ }
89
37
 
90
- const ipAddresses = getAllIPAddresses()
91
- if (ipAddresses.length) {
92
- results.utilization.ip_address = ipAddresses
93
- }
38
+ systemInfo = systemInfo || Object.create(null)
39
+ environment = environment || []
94
40
 
95
- if (systemInfo.bootId) {
96
- results.utilization.boot_id = systemInfo.bootId
97
- }
41
+ countSupportabilityForLogLibraries(environment, agent)
98
42
 
99
- if (systemInfo.vendors) {
100
- results.utilization.vendors = systemInfo.vendors
43
+ const hostname = agent.config.getHostnameSafe()
44
+ const results = {
45
+ utilization: {
46
+ metadata_version: 5,
47
+ logical_processors: systemInfo.logicalProcessors || null,
48
+ total_ram_mib: systemInfo.memory || null,
49
+ hostname: hostname
50
+ },
51
+ pid: process.pid,
52
+ host: hostname,
53
+ display_host: agent.config.getDisplayHost() || hostname,
54
+ language: 'nodejs',
55
+ app_name: agent.config.applications(),
56
+ agent_version: agent.version,
57
+ environment: environment,
58
+ settings: agent.config.publicSettings(),
59
+ high_security: agent.config.high_security,
60
+ labels: parseLabels(agent.config.labels),
61
+ metadata: Object.keys(process.env).reduce((obj, key) => {
62
+ if (key.startsWith('NEW_RELIC_METADATA_')) {
63
+ obj[key] = process.env[key]
101
64
  }
65
+ return obj
66
+ }, {})
67
+ }
68
+
69
+ logger.debug('New Relic metadata %o', results.metadata)
70
+
71
+ /**
72
+ * WARNING: This may not make sense if you are familiar with our config
73
+ * and updating of config from server. But the intention here is to always
74
+ * send the values from user config of harvest limits because on connect these
75
+ * values get reconfigured based on harvest cycle intervals. So if you originally
76
+ * had 1000 and a harvest of 5 seconds the new value of the harvest limit would be 83.
77
+ * Then every subsequent connect request it would continue to decrease until it eventually hit 0
78
+ * and we would never be sampling a certain piece of data.
79
+ */
80
+ results.event_harvest_config = {
81
+ harvest_limits: {
82
+ analytic_event_data: agent.config.transaction_events.max_samples_stored,
83
+ custom_event_data: agent.config.custom_insights_events.max_samples_stored,
84
+ error_event_data: agent.config.error_collector.max_event_samples_stored,
85
+ span_event_data: agent.config.span_events.max_samples_stored,
86
+ log_event_data: agent.config.application_logging.forwarding.max_samples_stored
87
+ }
88
+ }
102
89
 
103
- if (systemInfo.config) {
104
- results.utilization.config = systemInfo.config
105
- }
90
+ results.identifier = getIdentifierOverride(results.app_name)
106
91
 
107
- return callback(results)
108
- }
109
- )
92
+ const ipAddresses = getAllIPAddresses()
93
+ if (ipAddresses.length) {
94
+ results.utilization.ip_address = ipAddresses
95
+ }
96
+
97
+ if (systemInfo.bootId) {
98
+ results.utilization.boot_id = systemInfo.bootId
99
+ }
100
+
101
+ if (systemInfo.vendors) {
102
+ results.utilization.vendors = systemInfo.vendors
103
+ }
104
+
105
+ if (systemInfo.config) {
106
+ results.utilization.config = systemInfo.config
107
+ }
108
+
109
+ callback(results)
110
110
  }
111
111
 
112
112
  function getAllIPAddresses() {
@@ -5,7 +5,6 @@
5
5
 
6
6
  'use strict'
7
7
 
8
- const a = require('async')
9
8
  const logger = require('../logger').child({ component: 'query_tracer' })
10
9
  const Aggregator = require('../aggregators/base-aggregator')
11
10
  const SlowQuery = require('./slow-query')
@@ -132,8 +131,26 @@ class QueryTraceAggregator extends Aggregator {
132
131
  this.samples = new Map()
133
132
  }
134
133
 
135
- prepareJSON(done) {
136
- a.map(this.samples.values(), (sample, cb) => sample.prepareJSON(cb), done)
134
+ async prepareJSON(done) {
135
+ const samplePromises = []
136
+ for (const sample of this.samples.values()) {
137
+ const samplePromise = new Promise((resolve, reject) => {
138
+ sample.prepareJSON((err, data) => {
139
+ if (err) {
140
+ reject(err)
141
+ }
142
+ resolve(data)
143
+ })
144
+ })
145
+ samplePromises.push(samplePromise)
146
+ }
147
+
148
+ try {
149
+ const data = await Promise.all(samplePromises)
150
+ done(null, data)
151
+ } catch (err) {
152
+ done(err)
153
+ }
137
154
  }
138
155
 
139
156
  prepareJSONSync() {