From 17212a1eb20d483e888a559d7abf0491187e43aa Mon Sep 17 00:00:00 2001 From: themez Date: Thu, 14 Mar 2019 17:27:39 +0800 Subject: [PATCH 1/5] use host header as hostname if exists in http outbound --- lib/instrumentation/core/http-outbound.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/instrumentation/core/http-outbound.js b/lib/instrumentation/core/http-outbound.js index 721b6a96ba..199aa993ca 100644 --- a/lib/instrumentation/core/http-outbound.js +++ b/lib/instrumentation/core/http-outbound.js @@ -37,7 +37,7 @@ module.exports = function instrumentOutbound(agent, opts, makeRequest) { opts = copy.shallow(opts) } - let hostname = opts.hostname || opts.host || DEFAULT_HOST + let hostname = opts.getHeader && opts.getHeader('Host') || opts.headers && opts.headers['Host'] || opts.hostname || opts.host || DEFAULT_HOST let port = opts.port || opts.defaultPort if (!port) { port = (!opts.protocol || opts.protocol === 'http:') ? DEFAULT_PORT : DEFAULT_SSL_PORT From 04bdb6efc48f826a4ce7a6c63d0be488aa0d1a45 Mon Sep 17 00:00:00 2001 From: themez Date: Thu, 14 Mar 2019 17:57:33 +0800 Subject: [PATCH 2/5] prevent duplicated port appending for hostname --- lib/instrumentation/core/http-outbound.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/instrumentation/core/http-outbound.js b/lib/instrumentation/core/http-outbound.js index 199aa993ca..2c29caba3b 100644 --- a/lib/instrumentation/core/http-outbound.js +++ b/lib/instrumentation/core/http-outbound.js @@ -55,7 +55,7 @@ module.exports = function instrumentOutbound(agent, opts, makeRequest) { // but due to legacy issues we can't do that without moving customer's cheese. // // TODO: Move customers cheese by not appending the default port for https. - if (port && port !== DEFAULT_PORT) { + if (port && port !== DEFAULT_PORT && !hostname.includes(':')) { hostname += ':' + port } From 11c30ffa665caeba8d698a37f88541f59fb18a29 Mon Sep 17 00:00:00 2001 From: themez Date: Thu, 14 Mar 2019 18:01:02 +0800 Subject: [PATCH 3/5] fix lint --- lib/instrumentation/core/http-outbound.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/instrumentation/core/http-outbound.js b/lib/instrumentation/core/http-outbound.js index 2c29caba3b..5d44cecb11 100644 --- a/lib/instrumentation/core/http-outbound.js +++ b/lib/instrumentation/core/http-outbound.js @@ -37,7 +37,12 @@ module.exports = function instrumentOutbound(agent, opts, makeRequest) { opts = copy.shallow(opts) } - let hostname = opts.getHeader && opts.getHeader('Host') || opts.headers && opts.headers['Host'] || opts.hostname || opts.host || DEFAULT_HOST + let hostname = + (opts.getHeader && opts.getHeader("Host")) || + (opts.headers && opts.headers.Host) || + opts.hostname || + opts.host || + DEFAULT_HOST let port = opts.port || opts.defaultPort if (!port) { port = (!opts.protocol || opts.protocol === 'http:') ? DEFAULT_PORT : DEFAULT_SSL_PORT From f7c5c4300707ce38fe359d4d84f436baf905fb0e Mon Sep 17 00:00:00 2001 From: JowayWang Date: Mon, 1 Apr 2019 21:01:38 +0800 Subject: [PATCH 4/5] try catch callback --- lib/harvest.js | 20 +++++++++++++------- package.json | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/harvest.js b/lib/harvest.js index e104776d43..aa66c0d782 100644 --- a/lib/harvest.js +++ b/lib/harvest.js @@ -2,7 +2,7 @@ const a = require('async') const CollectorResponse = require('./collector/response') -const logger = require('./logger').child({component: 'Harvest'}) +const logger = require('./logger').child({ component: 'Harvest' }) const FROM_MILLIS = 1e-3 const NAMES = require('./metrics/names') @@ -194,7 +194,13 @@ class HarvestStep { _trySend(payload, callback) { try { - this.agent.collector[this._endpoint](payload, callback) + this.agent.collector[this._endpoint](payload, function (err, response) { + try { + callback(err, response) + } catch (err) { + console.warn(err, 'Failed to call callback') + } + }) } catch (err) { logger.warn(err, 'Failed to call collector method %s', this._endpoint) callback(err) @@ -426,7 +432,7 @@ class TransactionTraceHarvest extends HarvestStep { constructor(harvest) { const traceAggr = harvest.agent.traces const maxTraceSegments = harvest.agent.config.max_trace_segments - const traces = [].concat(traceAggr.syntheticsTraces) + const traces = [].concat(traceAggr.syntheticsTraces) if (traceAggr.trace) { const trace = traceAggr.trace @@ -611,7 +617,7 @@ class Harvest { // Pull out and log any errors from harvest steps. const errors = results.map((r) => r.error).filter((e) => !!e) if (errors.length > 0) { - logger.warn({errors}, 'Errors during harvest!') + logger.warn({ errors }, 'Errors during harvest!') } // See if any endpoints told us to shutdown or restart. A shutdown trumps @@ -654,7 +660,7 @@ function _splitPayload(runId, queue) { toMerge: queue, payload: [ runId, - {reservoir_size: queue.limit, events_seen: queue.seen}, + { reservoir_size: queue.limit, events_seen: queue.seen }, queue.toArray() ] }] @@ -672,14 +678,14 @@ function _splitPayload(runId, queue) { toMerge: firstHalf, payload: [ runId, - {reservoir_size: limit, events_seen: seen}, + { reservoir_size: limit, events_seen: seen }, firstHalf.map(rawEventsToValues) ] }, { toMerge: events, payload: [ runId, - {reservoir_size: queue.limit - limit, events_seen: queue.seen - seen}, + { reservoir_size: queue.limit - limit, events_seen: queue.seen - seen }, events.map(rawEventsToValues) ] }] diff --git a/package.json b/package.json index eff7ddad5f..b0e5bcf836 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "newrelic", - "version": "5.6.1", + "name": "@ruguoapp/newrelic", + "version": "5.6.1-jike.alhpa.1", "author": "New Relic Node.js agent team ", "licenses": [ { From cbb1c45973c723c2b1e28108611311fe9f7621fc Mon Sep 17 00:00:00 2001 From: JowayWang Date: Mon, 1 Apr 2019 21:48:32 +0800 Subject: [PATCH 5/5] change try location --- lib/harvest.js | 15 +++++++-------- package.json | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/harvest.js b/lib/harvest.js index aa66c0d782..dd970e5096 100644 --- a/lib/harvest.js +++ b/lib/harvest.js @@ -188,19 +188,18 @@ class HarvestStep { // Done! self.result = response self.payload = response.payload - callback() + + try { + callback() + } catch (err) { + console.warn(err, 'Failed to call callback') + } }) } _trySend(payload, callback) { try { - this.agent.collector[this._endpoint](payload, function (err, response) { - try { - callback(err, response) - } catch (err) { - console.warn(err, 'Failed to call callback') - } - }) + this.agent.collector[this._endpoint](payload, callback) } catch (err) { logger.warn(err, 'Failed to call collector method %s', this._endpoint) callback(err) diff --git a/package.json b/package.json index b0e5bcf836..dc36985425 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ruguoapp/newrelic", - "version": "5.6.1-jike.alhpa.1", + "version": "5.6.1-jike-alpha.2", "author": "New Relic Node.js agent team ", "licenses": [ {