newrelic 6.3.0 → 6.5.0

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.
Files changed (39) hide show
  1. package/{.eslintrc → .eslintrc.js} +4 -2
  2. package/.travis.yml +0 -1
  3. package/NEWS.md +136 -0
  4. package/README.md +1 -0
  5. package/api.js +75 -4
  6. package/bin/publish-docs.sh +1 -1
  7. package/bin/travis-node.sh +4 -1
  8. package/index.js +3 -3
  9. package/lib/aggregators/base-aggregator.js +1 -1
  10. package/lib/attributes.js +15 -6
  11. package/lib/config/default.js +11 -1
  12. package/lib/config/env.js +3 -1
  13. package/lib/config/hsm.js +6 -1
  14. package/lib/config/index.js +29 -8
  15. package/lib/config/lasp.js +16 -1
  16. package/lib/errors/error-collector.js +51 -90
  17. package/lib/errors/helper.js +13 -13
  18. package/lib/errors/index.js +36 -18
  19. package/lib/feature_flags.js +3 -3
  20. package/lib/header-processing.js +75 -0
  21. package/lib/instrumentation/core/child_process.js +12 -0
  22. package/lib/instrumentation/core/http-outbound.js +6 -28
  23. package/lib/instrumentation/core/http.js +100 -170
  24. package/lib/instrumentation/hapi/hapi-17.js +10 -3
  25. package/lib/metrics/names.js +1 -0
  26. package/lib/serverless/aws-lambda.js +79 -33
  27. package/lib/serverless/event-sources.json +128 -0
  28. package/lib/shim/transaction-shim.js +10 -33
  29. package/lib/spans/span-event-aggregator.js +2 -2
  30. package/lib/spans/span-event.js +33 -11
  31. package/lib/transaction/handle.js +73 -4
  32. package/lib/transaction/index.js +182 -34
  33. package/lib/transaction/trace/index.js +6 -5
  34. package/lib/transaction/trace/segment.js +12 -1
  35. package/lib/transaction/tracecontext.js +409 -163
  36. package/lib/util/get.js +16 -0
  37. package/lib/util/hashes.js +55 -6
  38. package/package.json +8 -10
  39. package/stub_api.js +5 -0
@@ -1,4 +1,4 @@
1
- {
1
+ module.exports = {
2
2
  "env": {
3
3
  "es6": true,
4
4
  "node": true,
@@ -7,6 +7,7 @@
7
7
  "parserOptions": {
8
8
  "ecmaVersion": 6
9
9
  },
10
+ "ignorePatterns": ["invalid-json/"],
10
11
  "rules": {
11
12
  "indent": ["warn", 2, {"SwitchCase": 1}],
12
13
  "brace-style": "error",
@@ -21,7 +22,7 @@
21
22
  "func-names": "error",
22
23
  "guard-for-in": "error",
23
24
  "key-spacing": ["off", { "beforeColon": false }],
24
- "max-len": ["error", 90, { "ignoreUrls": true }],
25
+ "max-len": ["error", 100, { "ignoreUrls": true }],
25
26
  "max-nested-callbacks": ["error", 3],
26
27
  "max-params": ["error", 5],
27
28
  "new-cap": "error",
@@ -52,6 +53,7 @@
52
53
  "strict": "error",
53
54
  "quote-props": [ "off", "consistent-as-needed" ],
54
55
  "quotes": ["off", "single"],
56
+ "use-isnan": "error",
55
57
  "wrap-iife": "error"
56
58
  },
57
59
  "overrides": [
package/.travis.yml CHANGED
@@ -18,7 +18,6 @@ env:
18
18
  - NR_NODE_VERSION=12 SUITE=unit
19
19
  - NR_NODE_VERSION=12 SUITE=integration
20
20
  - NR_NODE_VERSION=12 SUITE=lint
21
- - NR_NODE_VERSION=12 SUITE=security
22
21
  - NR_NODE_VERSION=12 SUITE=versioned
23
22
  services:
24
23
  - memcached
package/NEWS.md CHANGED
@@ -1,3 +1,139 @@
1
+ ### 6.5.0 (2020-03-18):
2
+
3
+ * Added error attributes to spans.
4
+ * The public api method `noticeError()` now attaches exception details to the currently executing
5
+ span. Spans with error details are now highlighted red in the Distributed Tracing UI. Also, the
6
+ attributes `error.class` and `error.message` are added to the span. If multiple errors are
7
+ recorded for a single span, only the final error's attributes will be added to the span.
8
+
9
+ * Added ID of the span in which an error occurred to the corresponding transaction error event.
10
+
11
+ * Added new public API methods `addCustomSpanAttribute` and `addCustomSpanAttributes` to add
12
+ attributes to the currently executing span.
13
+
14
+ * Added new attributes to http outbound spans: `http.statusCode` and `http.statusText`.
15
+
16
+ * Updated W3C Trace Context "Known Issues and Workaround" notes with latest accurate consideration.
17
+
18
+ * Converted unit tests to run via `tap`. Removes `mocha` dependency.
19
+
20
+ * Fixed route naming when hapi's `pre` route handlers share functions.
21
+
22
+ * Fixed `child_process` instrumentation so that handlers can be effectively removed
23
+ when attached via `.once()` or manually removed via `removeListener()`.
24
+
25
+ ### 6.4.2 (2020-02-27):
26
+
27
+ * Support new http[s] get/request function signature in Node v10+
28
+
29
+ * Added the following Span Event attributes:
30
+ - http.statusCode
31
+ - http.statusText
32
+
33
+ The above attributes will be replacing the following *deprecated* attributes:
34
+ - httpResponseCode
35
+ - response.status
36
+ - response.statusMessage
37
+
38
+ The deprecated attributes will be removed with the next major release of the Agent.
39
+
40
+ * Updates version check to be in alignment with [our stated support
41
+ policy](https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent)
42
+ and the version constraints in package.json
43
+
44
+ * Redacts individual certificates configuration values before sending to server
45
+ settings. When configured, these values will now appear like: `{certificates.0: ****}`.
46
+
47
+ ### 6.4.1 (2020-02-20):
48
+
49
+ * Bumped `@newrelic/aws-sdk` version to `v1.1.2` from `v1.1.1`.
50
+ https://github.com/newrelic/node-newrelic-aws-sdk/blob/master/CHANGELOG.md
51
+
52
+ Notable improvements include:
53
+ * Fixed issue where instrumentation would crash pulling `host` and `port` values
54
+ when `AmazonDaxClient` was used as the service for `DocumentClient`.
55
+
56
+ * Prevented passing CI with `.only()` in mocha tests.
57
+
58
+ * Removed CI restriction for Node `12.15`. Node shipped a fix for the `12.16`
59
+ breakage in `12.16.1`.
60
+
61
+ * Removed calls to `OutgoingMessage.prototype._headers` in favor of using public
62
+ `getHeaders` API (thanks to @adityasabnis for bringing this to our attention).
63
+
64
+ * Removed engine upper-bound to enable easier experimentation of newer Node versions
65
+ with the agent for customers.
66
+
67
+ Please see https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent for officially supported versions.
68
+ Incompatibilities are expected for odd-numbered releases, which are not supported,
69
+ and even-numbered releases before "official" support has been released.
70
+
71
+ * Reduced "... Aggregator data send." log messages to `debug` level to reduce noise
72
+ of default logs.
73
+
74
+ * Fixed issue where disabled agent would return an empty string instead of an empty
75
+ object from API#getLinkingMetadata().
76
+
77
+ This issue would cause the `@newrelic/winston-enricher` module to crash when
78
+ attempting to inject log metatdata.
79
+
80
+ * Reduced logging level of raw `x-queue-start` or `x-request-start` header values
81
+ to avoid logging very large values at default logging levels.
82
+
83
+ ### 6.4.0 (2020-02-12):
84
+
85
+ * Added support for W3C Trace Context, with easy upgrade from New Relic trace
86
+ context.
87
+
88
+ * Distributed Tracing now supports W3C Trace Context headers for HTTP protocols
89
+ when distributed tracing is enabled. Our implementation can accept and emit both
90
+ the W3C trace header format and the New Relic trace header format. This simplifies
91
+ agent upgrades, allowing trace context to be propagated between services with older
92
+ and newer releases of New Relic agents. W3C trace header format will always be
93
+ accepted and emitted. New Relic trace header format will be accepted, and you can
94
+ optionally disable emission of the New Relic trace header format.
95
+
96
+ * When distributed tracing is enabled with `distributed_tracing.enabled: true`,
97
+ the Node agent will now accept W3C's `traceparent` and `tracestate` headers when
98
+ calling `TransactionHandle#acceptDistributedTraceHeaders` or automatically via
99
+ `http` instrumentation. When calling `Transaction#insertDistributedTraceHeaders`,
100
+ or automatically via `http` instrumentation, the Node agent will include the W3C
101
+ headers along with the New Relic distributed tracing header, unless the New Relic
102
+ trace header format is disabled using `distributed_tracing.exclude_newrelic_header:true`.
103
+
104
+ * Added `TransactionHandle#acceptDistributedTraceHeaders` API for accepting both
105
+ New Relic and W3C TraceContext distributed traces.
106
+
107
+ Deprecated `TransactionHandle#acceptDistributedTracePayload` which will be removed
108
+ in a future major release.
109
+
110
+ * Added `TransactionHandle#insertDistributedTraceHeaders` API for adding outbound
111
+ distributed trace headers. Both W3C TraceContext and New Relic formats will be
112
+ included unless `distributed_tracing.exclude_newrelic_header: true`.
113
+
114
+ Deprecated `TransactionHandle#createDistributedTracePayload` which will be removed
115
+ in a future major release.
116
+
117
+ Known Issues and Workarounds
118
+
119
+ * If a .NET agent is initiating distributed traces as the root service, you must update
120
+ that .NET agent to version `8.24` or later before upgrading your downstream Node
121
+ New Relic agents to this agent release.
122
+
123
+ * Pins Node 12 version to `v12.15` to avoid breakages with `v12.16.0` until cause(s)
124
+ resolved.
125
+
126
+ * AWS Lambda Improvements
127
+
128
+ * Fixed issue where lambda invocation errors were not noticed in Node 10 or Node 12 environments.
129
+ * Added collection of additional AWS Lambda event source meta data.
130
+ * Added event type detection for lambda invocation events.
131
+ * Expanded ARN harvest to include ALB and CloudWatch.
132
+
133
+ * Improved Transaction and Trace ID generation.
134
+
135
+ * Updated publish-docs script to use `npm run` instead of `make`.
136
+
1
137
  ### 6.3.0 (2020-01-27):
2
138
 
3
139
  * Bumped `@newrelic/aws-sdk` to `v1.1.1` from `v1.0.0`.
package/README.md CHANGED
@@ -741,3 +741,4 @@ license and the licenses of its dependencies.
741
741
  [5]: https://newrelic.com/application-monitoring/features
742
742
  [6]: https://github.com/newrelic/node-newrelic/blob/master/lib/config/default.js
743
743
  [7]: https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration
744
+
package/api.js CHANGED
@@ -125,7 +125,7 @@ API.prototype.getTransaction = function getTransaction() {
125
125
 
126
126
  transaction.handledExternally = true
127
127
 
128
- return new TransactionHandle(transaction)
128
+ return new TransactionHandle(transaction, this.agent.metrics)
129
129
  }
130
130
 
131
131
  /**
@@ -163,7 +163,7 @@ API.prototype.getLinkingMetadata = function getLinkingMetadata(omitSupportabilit
163
163
  }
164
164
 
165
165
  if (config.distributed_tracing.enabled && segment) {
166
- linkingMetadata['trace.id'] = segment.transaction.getTraceId()
166
+ linkingMetadata['trace.id'] = segment.transaction.traceId
167
167
  const spanId = segment.getSpanId()
168
168
  if (spanId) {
169
169
  linkingMetadata['span.id'] = spanId
@@ -340,6 +340,77 @@ API.prototype.addCustomAttributes = function addCustomAttributes(atts) {
340
340
  }
341
341
  }
342
342
 
343
+ /**
344
+ * Add custom span attributes in an object to the current segment/span.
345
+ *
346
+ * See documentation for newrelic.addCustomSpanAttribute for more information.
347
+ *
348
+ * An example of setting a custom span attribute:
349
+ *
350
+ * newrelic.addCustomSpanAttribute({test: 'value', test2: 'value2'})
351
+ *
352
+ * @param {object} [atts]
353
+ * @param {string} [atts.KEY] The name you want displayed in the RPM UI.API.
354
+ * @param {string} [atts.KEY.VALUE] The value you want displayed. Must be serializable.
355
+ */
356
+ API.prototype.addCustomSpanAttributes = function addCustomSpanAttributes(atts) {
357
+ const metric = this.agent.metrics.getOrCreateMetric(
358
+ NAMES.SUPPORTABILITY.API + '/addCustomSpanAttributes'
359
+ )
360
+ metric.incrementCallCount()
361
+
362
+ for (let key in atts) {
363
+ if (properties.hasOwn(atts, key)) {
364
+ this.addCustomSpanAttribute(key, atts[key])
365
+ }
366
+ }
367
+ }
368
+
369
+ /**
370
+ * Add a custom span attribute to the current transaction. Some attributes
371
+ * are reserved (see CUSTOM_DENYLIST for the current, very short list), and
372
+ * as with most API methods, this must be called in the context of an
373
+ * active segment/span. Most recently set value wins.
374
+ *
375
+ * @param {string} key The key you want displayed in the RPM UI.
376
+ * @param {string} value The value you want displayed. Must be serializable.
377
+ */
378
+ API.prototype.addCustomSpanAttribute = function addCustomSpanAttribute(key, value) {
379
+ const metric = this.agent.metrics.getOrCreateMetric(
380
+ NAMES.SUPPORTABILITY.API + '/addCustomSpanAttribute'
381
+ )
382
+ metric.incrementCallCount()
383
+
384
+ // If high security mode is on, custom attributes are disabled.
385
+ if (this.agent.config.high_security) {
386
+ logger.warnOnce(
387
+ 'Custom span attributes',
388
+ 'Custom span attributes are disabled by high security mode.'
389
+ )
390
+ return false
391
+ } else if (!this.agent.config.api.custom_attributes_enabled) {
392
+ logger.debug(
393
+ 'Config.api.custom_attributes_enabled set to false, not collecting value'
394
+ )
395
+ return false
396
+ }
397
+
398
+ const segment = this.agent.tracer.getSegment()
399
+
400
+ if (!segment) {
401
+ return logger.debug(
402
+ 'Could not add attribute %s. No available span/segment.',
403
+ key
404
+ )
405
+ }
406
+
407
+ if (CUSTOM_DENYLIST.has(key)) {
408
+ return logger.warn('Not overwriting value of NR-only attribute %s.', key)
409
+ }
410
+
411
+ segment.addCustomSpanAttribute(key, value)
412
+ }
413
+
343
414
  API.prototype.setIgnoreTransaction = util.deprecate(
344
415
  setIgnoreTransaction, [
345
416
  'API#setIgnoreTransaction is being deprecated!',
@@ -415,7 +486,6 @@ API.prototype.noticeError = function noticeError(error, customAttributes) {
415
486
  if (typeof error === 'string') {
416
487
  error = new Error(error)
417
488
  }
418
- const transaction = this.agent.tracer.getTransaction()
419
489
 
420
490
  // Filter all object type valued attributes out
421
491
  let filteredAttributes = customAttributes
@@ -423,6 +493,7 @@ API.prototype.noticeError = function noticeError(error, customAttributes) {
423
493
  filteredAttributes = _filterAttributes(customAttributes, 'noticeError')
424
494
  }
425
495
 
496
+ const transaction = this.agent.tracer.getTransaction()
426
497
  this.agent.errors.addUserError(transaction, error, filteredAttributes)
427
498
  }
428
499
 
@@ -1397,7 +1468,7 @@ API.prototype.getTraceMetadata = function getTraceMetadata() {
1397
1468
  } else if (!this.agent.config.distributed_tracing.enabled) {
1398
1469
  logger.debug("Distributed tracing disabled when calling API#getTraceMetadata")
1399
1470
  } else {
1400
- metadata.traceId = segment.transaction.getTraceId()
1471
+ metadata.traceId = segment.transaction.traceId
1401
1472
 
1402
1473
  const spanId = segment.getSpanId()
1403
1474
  if (spanId) {
@@ -5,7 +5,7 @@ PACKAGE_VERSION=$(node -e 'console.log(require("./package").version)')
5
5
  git checkout gh-pages
6
6
  git pull origin gh-pages
7
7
  git merge -
8
- make public-docs
8
+ npm run public-docs
9
9
  git rm -r docs
10
10
  mv out docs
11
11
  git add docs
@@ -33,7 +33,10 @@ if [ -z $NR_NODE_VERSION ]; then
33
33
  exit 1
34
34
  fi
35
35
 
36
- if [ $NR_NODE_VERSION -gt 11 ] && version_gt 2.17 $GLIBC_VERSION_CHECK;then
36
+ version=$NR_NODE_VERSION
37
+ major=${version/.*}
38
+ echo $major
39
+ if [ $major -gt 11 ] && version_gt 2.17 $GLIBC_VERSION_CHECK;then
37
40
  echo "Installing updated glibc\n"
38
41
  # can we get this from an actual repository?
39
42
  curl -LO 'http://launchpadlibrarian.net/130794928/libc6_2.17-0ubuntu4_amd64.deb'
package/index.js CHANGED
@@ -43,10 +43,10 @@ function initialize() {
43
43
  preAgentTime
44
44
  )
45
45
 
46
- // TODO: Update this check when Node v6 is deprecated.
47
- if (psemver.satisfies('<6.0.0')) {
46
+ // TODO: Update this check when Node v8 is deprecated.
47
+ if (psemver.satisfies('<8.0.0')) {
48
48
  message = 'New Relic for Node.js requires a version of Node equal to or\n' +
49
- 'greater than 6.0.0. Not starting!'
49
+ 'greater than 8.0.0. Not starting!'
50
50
 
51
51
  logger.error(message)
52
52
  throw new Error(message)
@@ -88,7 +88,7 @@ class Aggregator extends EventEmitter {
88
88
  }
89
89
 
90
90
  send() {
91
- logger.info(`${this.method} Aggregator data send.`)
91
+ logger.debug(`${this.method} Aggregator data send.`)
92
92
  this.emit(`starting ${this.method} data send.`)
93
93
 
94
94
  const data = this._getMergeData()
package/lib/attributes.js CHANGED
@@ -6,6 +6,8 @@ const isValidType = require('./util/attribute-types')
6
6
  const byteUtils = require('./util/byte-limit')
7
7
  const properties = require('./util/properties')
8
8
 
9
+ const MAXIMUM_CUSTOM_ATTRIBUTES = 64
10
+
9
11
  /**
10
12
  * @class
11
13
  * @private
@@ -23,6 +25,7 @@ class Attributes {
23
25
  this.filter = makeFilter(scope)
24
26
  this.limit = limit
25
27
  this.attributes = Object.create(null)
28
+ this.attributeCount = 0
26
29
  }
27
30
 
28
31
  /**
@@ -57,7 +60,6 @@ class Attributes {
57
60
  */
58
61
  get(dest) {
59
62
  const attrs = Object.create(null)
60
- let attrCount = 0
61
63
  for (let key in this.attributes) { // eslint-disable-line guard-for-in
62
64
  const attr = this.attributes[key]
63
65
  if (!(attr.destinations & dest)) {
@@ -67,10 +69,6 @@ class Attributes {
67
69
  attrs[key] = typeof attr.value === 'string' && !attr.truncateExempt
68
70
  ? byteUtils.truncate(attr.value, 255)
69
71
  : attr.value
70
-
71
- if (++attrCount >= this.limit) {
72
- break
73
- }
74
72
  }
75
73
 
76
74
  return attrs
@@ -103,6 +101,13 @@ class Attributes {
103
101
  * @param {boolean} [truncateExempt=false] - Flag marking value exempt from truncation
104
102
  */
105
103
  addAttribute(destinations, key, value, truncateExempt = false) {
104
+ if (this.attributeCount + 1 > this.limit) {
105
+ return logger.debug(
106
+ `Maximum number of custom attributes have been added.
107
+ Dropping attribute ${key} with ${value} type.`
108
+ )
109
+ }
110
+
106
111
  if (!isValidType(value)) {
107
112
  return logger.debug(
108
113
  'Not adding attribute %s with %s value type. This is expected for undefined' +
@@ -123,6 +128,7 @@ class Attributes {
123
128
  // Only set the attribute if at least one destination passed
124
129
  const validDestinations = this.filter(destinations, key)
125
130
  if (validDestinations) {
131
+ this.attributeCount = this.attributeCount + 1
126
132
  this._set(validDestinations, key, value, truncateExempt)
127
133
  }
128
134
  }
@@ -159,4 +165,7 @@ function makeFilter(scope) {
159
165
  }
160
166
  }
161
167
 
162
- module.exports = Attributes
168
+ module.exports = {
169
+ Attributes: Attributes,
170
+ MAXIMUM_CUSTOM_ATTRIBUTES: MAXIMUM_CUSTOM_ATTRIBUTES
171
+ }
@@ -851,7 +851,17 @@ exports.config = () => ({
851
851
  *
852
852
  * @env NEW_RELIC_DISTRIBUTED_TRACING_ENABLED
853
853
  */
854
- enabled: false
854
+ enabled: false,
855
+
856
+ /**
857
+ * Exludes New Relic format distributed tracing header (`newrelic`) on
858
+ * outbound requests when set to `true`. By default (when false)
859
+ * both W3C TraceContext (`traceparent`, `tracecontext`) and
860
+ * New Relic formats will be sent.
861
+ *
862
+ * @env NEW_RELIC_DISTRIBUTED_TRACING_EXCLUDE_NEWRELIC_HEADER
863
+ */
864
+ exclude_newrelic_header: false
855
865
  },
856
866
 
857
867
  /**
package/lib/config/env.js CHANGED
@@ -134,7 +134,8 @@ const ENV_MAPPING = {
134
134
  }
135
135
  },
136
136
  distributed_tracing: {
137
- enabled: 'NEW_RELIC_DISTRIBUTED_TRACING_ENABLED'
137
+ enabled: 'NEW_RELIC_DISTRIBUTED_TRACING_ENABLED',
138
+ exclude_newrelic_header: 'NEW_RELIC_DISTRIBUTED_TRACING_EXCLUDE_NEWRELIC_HEADER'
138
139
  },
139
140
  message_tracer: {
140
141
  segment_parameters: {
@@ -215,6 +216,7 @@ const BOOLEAN_VARS = new Set([
215
216
  'NEW_RELIC_SPAN_EVENTS_ENABLED',
216
217
  'NEW_RELIC_SPAN_EVENTS_ATTRIBUTES_ENABLED',
217
218
  'NEW_RELIC_DISTRIBUTED_TRACING_ENABLED',
219
+ 'NEW_RELIC_DISTRIBUTED_TRACING_EXCLUDE_NEWRELIC_HEADER',
218
220
  'NEW_RELIC_LOG_ENABLED',
219
221
  'NEW_RELIC_AUDIT_LOG_ENABLED',
220
222
  'NEW_RELIC_DATASTORE_DATABASE_NAME_REPORTING_ENABLED',
package/lib/config/hsm.js CHANGED
@@ -51,7 +51,12 @@ const HIGH_SECURITY_SETTINGS = {
51
51
  const HIGH_SECURITY_KEYS = flatten.keys(HIGH_SECURITY_SETTINGS)
52
52
 
53
53
  // blank out these config values before sending to the collector
54
- const REDACT_BEFORE_SEND = new Set(['proxy_pass', 'proxy_user', 'proxy'])
54
+ const REDACT_BEFORE_SEND = new Set([
55
+ 'proxy_pass',
56
+ 'proxy_user',
57
+ 'proxy',
58
+ 'certificates' // should be public but in case user mistake and also these are huge
59
+ ])
55
60
 
56
61
  // process.domain needs to be stripped befeore sending
57
62
  const REMOVE_BEFORE_SEND = new Set(['domain'])
@@ -1152,15 +1152,15 @@ Config.prototype._loggingManuallySet = function _loggingManuallySet(inputConfig)
1152
1152
  /**
1153
1153
  * Returns true if native-metrics has been manually enabled via configuration
1154
1154
  * file or enveironment variable
1155
- *
1155
+ *
1156
1156
  * @param {*} inputConfig configuration pass to the Config constructor
1157
- *
1157
+ *
1158
1158
  * @returns {boolean}
1159
1159
  */
1160
- Config.prototype._nativeMetricsManuallySet =
1160
+ Config.prototype._nativeMetricsManuallySet =
1161
1161
  function _nativeMetricsManuallySet(inputConfig) {
1162
- const inputEnabled = inputConfig
1163
- && inputConfig.plugins
1162
+ const inputEnabled = inputConfig
1163
+ && inputConfig.plugins
1164
1164
  && inputConfig.plugins.native_metrics
1165
1165
  && inputConfig.plugins.native_metrics.enabled
1166
1166
  const envEnabled = process.env.NEW_RELIC_NATIVE_METRICS_ENABLED
@@ -1211,7 +1211,7 @@ Config.prototype._enforceServerless = function _enforceServerless(inputConfig) {
1211
1211
  )
1212
1212
  }
1213
1213
 
1214
- if (this._nativeMetricsManuallySet(inputConfig) &&
1214
+ if (this._nativeMetricsManuallySet(inputConfig) &&
1215
1215
  this.plugins.native_metrics.enabled) {
1216
1216
  logger.info(
1217
1217
  'Enabling the native-metrics module when in serverless mode may greatly ' +
@@ -1458,8 +1458,12 @@ Config.prototype.applyLasp = function applyLasp(agent, policies) {
1458
1458
  }
1459
1459
  var valueName = splitConfigName[splitConfigName.length - 1]
1460
1460
  var localVal = settingBlock[valueName]
1461
+
1462
+ // Indexes into "allowed values" based on "enabled" setting
1463
+ // to retreive proper mapping.
1461
1464
  var policyValues = localMapping.allowedValues
1462
1465
  var policyValue = policyValues[policy.enabled ? 1 : 0]
1466
+
1463
1467
  // get the most secure setting between local config and the policy
1464
1468
  var finalValue = settingBlock[valueName] = config._getMostSecure(
1465
1469
  name,
@@ -1522,6 +1526,20 @@ Config.prototype.validateFlags = function validateFlags() {
1522
1526
  })
1523
1527
  }
1524
1528
 
1529
+ function redactValue(value) {
1530
+ const REDACT_VALUE = '****'
1531
+
1532
+ let result = null
1533
+ if (Array.isArray(value)) {
1534
+ // Redact each value so we know if was configured and how many values
1535
+ result = value.map(() => REDACT_VALUE)
1536
+ } else {
1537
+ result = REDACT_VALUE
1538
+ }
1539
+
1540
+ return result
1541
+ }
1542
+
1525
1543
  /**
1526
1544
  * Get a JSONifiable object containing all settings we want to report to the
1527
1545
  * collector and store in the environment_values table.
@@ -1532,9 +1550,10 @@ Config.prototype.publicSettings = function publicSettings() {
1532
1550
  var settings = Object.create(null)
1533
1551
 
1534
1552
  for (var key in this) {
1535
- if (this.hasOwnProperty(key)) {
1553
+ if (this.hasOwnProperty(key) && !REMOVE_BEFORE_SEND.has(key)) {
1536
1554
  if (HSM.REDACT_BEFORE_SEND.has(key)) {
1537
- settings[key] = '****'
1555
+ const value = this[key]
1556
+ settings[key] = redactValue(value)
1538
1557
  } else if (!HSM.REMOVE_BEFORE_SEND.has(key)) {
1539
1558
  settings[key] = this[key]
1540
1559
  }
@@ -1695,6 +1714,8 @@ function createInstance(config) {
1695
1714
  return _configInstance
1696
1715
  }
1697
1716
 
1717
+ const REMOVE_BEFORE_SEND = new Set(['attributeFilter'])
1718
+
1698
1719
  /**
1699
1720
  * Preserve the legacy initializer, but also allow consumers to manage their
1700
1721
  * own configuration if they choose.
@@ -1,12 +1,25 @@
1
1
  'use strict'
2
2
 
3
+ // TODO: would likely be easier to understand if the allowedValues mapping
4
+ // just took the raw enabled/disabled and translated. This is not a hot path.
5
+
6
+ /**
7
+ * path: Full nested path for the local configuration item.
8
+ * allowedValues:
9
+ * Array of valid config values to map for incoming enabled/disabled.
10
+ * policy.enabled: false uses index 0, policy.enabled: true uses index 1.
11
+ * filter: Allows for calculating most secure setting to use
12
+ * applyAdditionalSettings: Applies additional settings that are required
13
+ * when the policy is disabled.
14
+ * clearData: Clears the relevant agent collection.
15
+ */
3
16
  const LASP_MAP = {
4
17
  // LASP key
5
18
  record_sql: {
6
19
  // full path to corresponding config key
7
20
  path: 'transaction_tracer.record_sql',
8
21
  // Mapping from policy enabled status to usable config value
9
- // first element is policy is off, second is policy is on
22
+ // policy.enabled: false === off, policy.enabled: true === 'obfuscated'
10
23
  allowedValues: ['off', 'obfuscated'],
11
24
  // Tracks the precedent of settings controlled by LASP.
12
25
  filter: function mostSecureRecordSQL(first, second) {
@@ -45,6 +58,8 @@ const LASP_MAP = {
45
58
  // TODO: rename config key, because the names contradict each other's behavior
46
59
  allow_raw_exception_messages: {
47
60
  path: 'strip_exception_messages.enabled',
61
+ // if raw messages are allowed, then we should not strip them
62
+ // policy.enabled: false === true, policy.enabled: true === false
48
63
  allowedValues: [true, false],
49
64
  filter: function mostSecureStripException(first, second) {
50
65
  return first || second