newrelic 8.0.0 → 8.1.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.
package/NEWS.md CHANGED
@@ -1,3 +1,18 @@
1
+ ### v8.1.0 (2021-08-05)
2
+
3
+ * Added necessary instrumentation to support v4 of `mongodb`.
4
+ * Explicitly enabled APM for `mongodb` instrumentation(`client.monitorCommands = true`)
5
+
6
+ * Fixed issue where Promise based `pg.Client.query` timings were always in sub-millisecond range.
7
+
8
+ * Fixed bug where `API.shutdown` would not harvest or keep process active effectively after an agent restart.
9
+
10
+ The agent will now correctly update its state to 'started' after a reconnect has completed.
11
+
12
+ * Added an eslint rule to verify every file includes the copyright statement.
13
+
14
+ * Fixed the `homepage` field in package.json to use `https` in the link to the github repo. Thank you @pzrq for the contribution.
15
+
1
16
  ### v8.0.0 (2021-07-26)
2
17
 
3
18
  * Added official parity support for Node 16.
@@ -42,6 +42,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
42
42
  * [bluebird](#bluebird)
43
43
  * [chai](#chai)
44
44
  * [commander](#commander)
45
+ * [eslint-plugin-header](#eslint-plugin-header)
45
46
  * [eslint](#eslint)
46
47
  * [express](#express)
47
48
  * [fastify](#fastify)
@@ -61,7 +62,6 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
61
62
  * [q](#q)
62
63
  * [redis](#redis)
63
64
  * [request](#request)
64
- * [request](#request)
65
65
  * [restify](#restify)
66
66
  * [rimraf](#rimraf)
67
67
  * [rimraf](#rimraf)
@@ -77,7 +77,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
77
77
 
78
78
  ### @grpc/grpc-js
79
79
 
80
- This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.2.11](https://github.com/grpc/grpc-node/tree/%40grpc/grpc-js%401.2.11/packages/grpc-js)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/blob/%40grpc/grpc-js%401.2.11/packages/grpc-js/LICENSE):
80
+ This product includes source derived from [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) ([v1.3.6](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/tree/v1.3.6)), distributed under the [Apache-2.0 License](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js/blob/v1.3.6/LICENSE):
81
81
 
82
82
  ```
83
83
  Apache License
@@ -1762,7 +1762,7 @@ This product includes source derived from [@newrelic/test-utilities](https://git
1762
1762
 
1763
1763
  ### @octokit/rest
1764
1764
 
1765
- This product includes source derived from [@octokit/rest](https://github.com/octokit/rest.js) ([v18.0.15](https://github.com/octokit/rest.js/tree/v18.0.15)), distributed under the [MIT License](https://github.com/octokit/rest.js/blob/v18.0.15/LICENSE):
1765
+ This product includes source derived from [@octokit/rest](https://github.com/octokit/rest.js) ([v18.8.0](https://github.com/octokit/rest.js/tree/v18.8.0)), distributed under the [MIT License](https://github.com/octokit/rest.js/blob/v18.8.0/LICENSE):
1766
1766
 
1767
1767
  ```
1768
1768
  The MIT License
@@ -1871,7 +1871,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1871
1871
 
1872
1872
  ### bluebird
1873
1873
 
1874
- This product includes source derived from [bluebird](https://github.com/petkaantonov/bluebird) ([v3.7.1](https://github.com/petkaantonov/bluebird/tree/v3.7.1)), distributed under the [MIT License](https://github.com/petkaantonov/bluebird/blob/v3.7.1/LICENSE):
1874
+ This product includes source derived from [bluebird](https://github.com/petkaantonov/bluebird) ([v3.7.2](https://github.com/petkaantonov/bluebird/tree/v3.7.2)), distributed under the [MIT License](https://github.com/petkaantonov/bluebird/blob/v3.7.2/LICENSE):
1875
1875
 
1876
1876
  ```
1877
1877
  The MIT License (MIT)
@@ -1900,7 +1900,7 @@ THE SOFTWARE.
1900
1900
 
1901
1901
  ### chai
1902
1902
 
1903
- This product includes source derived from [chai](https://github.com/chaijs/chai) ([v4.2.0](https://github.com/chaijs/chai/tree/v4.2.0)), distributed under the [MIT License](https://github.com/chaijs/chai/blob/v4.2.0/LICENSE):
1903
+ This product includes source derived from [chai](https://github.com/chaijs/chai) ([v4.3.4](https://github.com/chaijs/chai/tree/v4.3.4)), distributed under the [MIT License](https://github.com/chaijs/chai/blob/v4.3.4/LICENSE):
1904
1904
 
1905
1905
  ```
1906
1906
  MIT License
@@ -1954,12 +1954,27 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1954
1954
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1955
1955
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1956
1956
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1957
+ ```
1958
+
1959
+ ### eslint-plugin-header
1960
+
1961
+ This product includes source derived from [eslint-plugin-header](https://github.com/Stuk/eslint-plugin-header) ([v3.1.1](https://github.com/Stuk/eslint-plugin-header/tree/v3.1.1)), distributed under the [MIT License](https://github.com/Stuk/eslint-plugin-header/blob/v3.1.1/README.md):
1957
1962
 
1963
+ ```
1964
+ MIT License
1965
+
1966
+ Copyright (c) <year> <copyright holders>
1967
+
1968
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1969
+
1970
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1971
+
1972
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1958
1973
  ```
1959
1974
 
1960
1975
  ### eslint
1961
1976
 
1962
- This product includes source derived from [eslint](https://github.com/eslint/eslint) ([v6.8.0](https://github.com/eslint/eslint/tree/v6.8.0)), distributed under the [MIT License](https://github.com/eslint/eslint/blob/v6.8.0/LICENSE):
1977
+ This product includes source derived from [eslint](https://github.com/eslint/eslint) ([v7.32.0](https://github.com/eslint/eslint/tree/v7.32.0)), distributed under the [MIT License](https://github.com/eslint/eslint/blob/v7.32.0/LICENSE):
1963
1978
 
1964
1979
  ```
1965
1980
  Copyright JS Foundation and other contributors, https://js.foundation
@@ -2050,7 +2065,7 @@ SOFTWARE.
2050
2065
 
2051
2066
  ### generic-pool
2052
2067
 
2053
- This product includes source derived from [generic-pool](https://github.com/coopernurse/node-pool) ([v3.7.1](https://github.com/coopernurse/node-pool/tree/v3.7.1)), distributed under the [MIT License](https://github.com/coopernurse/node-pool/blob/v3.7.1/README.md):
2068
+ This product includes source derived from [generic-pool](https://github.com/coopernurse/node-pool) ([v3.8.2](https://github.com/coopernurse/node-pool/tree/v3.8.2)), distributed under the [MIT License](https://github.com/coopernurse/node-pool/blob/v3.8.2/README.md):
2054
2069
 
2055
2070
  ```
2056
2071
  MIT License
@@ -2112,7 +2127,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
2112
2127
 
2113
2128
  ### http-errors
2114
2129
 
2115
- This product includes source derived from [http-errors](https://github.com/jshttp/http-errors) ([v1.7.3](https://github.com/jshttp/http-errors/tree/v1.7.3)), distributed under the [MIT License](https://github.com/jshttp/http-errors/blob/v1.7.3/LICENSE):
2130
+ This product includes source derived from [http-errors](https://github.com/jshttp/http-errors) ([v1.8.0](https://github.com/jshttp/http-errors/tree/v1.8.0)), distributed under the [MIT License](https://github.com/jshttp/http-errors/blob/v1.8.0/LICENSE):
2116
2131
 
2117
2132
  ```
2118
2133
 
@@ -2172,7 +2187,7 @@ SOFTWARE.
2172
2187
 
2173
2188
  ### jsdoc
2174
2189
 
2175
- This product includes source derived from [jsdoc](https://github.com/jsdoc/jsdoc) ([v3.6.3](https://github.com/jsdoc/jsdoc/tree/v3.6.3)), distributed under the [Apache-2.0 License](https://github.com/jsdoc/jsdoc/blob/v3.6.3/LICENSE.md):
2190
+ This product includes source derived from [jsdoc](https://github.com/jsdoc/jsdoc) ([v3.6.7](https://github.com/jsdoc/jsdoc/tree/v3.6.7)), distributed under the [Apache-2.0 License](https://github.com/jsdoc/jsdoc/blob/v3.6.7/LICENSE.md):
2176
2191
 
2177
2192
  ```
2178
2193
  # License
@@ -2282,7 +2297,7 @@ https://github.com/jmblog/color-themes-for-google-code-prettify
2282
2297
 
2283
2298
  ### lint-staged
2284
2299
 
2285
- This product includes source derived from [lint-staged](https://github.com/okonet/lint-staged) ([v11.0.0](https://github.com/okonet/lint-staged/tree/v11.0.0)), distributed under the [MIT License](https://github.com/okonet/lint-staged/blob/v11.0.0/LICENSE):
2300
+ This product includes source derived from [lint-staged](https://github.com/okonet/lint-staged) ([v11.1.1](https://github.com/okonet/lint-staged/tree/v11.1.1)), distributed under the [MIT License](https://github.com/okonet/lint-staged/blob/v11.1.1/LICENSE):
2286
2301
 
2287
2302
  ```
2288
2303
  The MIT License (MIT)
@@ -2406,7 +2421,7 @@ https://github.com/jsdoc3/jsdoc
2406
2421
 
2407
2422
  ### mongodb
2408
2423
 
2409
- This product includes source derived from [mongodb](https://github.com/mongodb/node-mongodb-native) ([v3.3.4](https://github.com/mongodb/node-mongodb-native/tree/v3.3.4)), distributed under the [Apache-2.0 License](https://github.com/mongodb/node-mongodb-native/blob/v3.3.4/LICENSE.md):
2424
+ This product includes source derived from [mongodb](https://github.com/mongodb/node-mongodb-native) ([v3.6.10](https://github.com/mongodb/node-mongodb-native/tree/v3.6.10)), distributed under the [Apache-2.0 License](https://github.com/mongodb/node-mongodb-native/blob/v3.6.10/LICENSE.md):
2410
2425
 
2411
2426
  ```
2412
2427
  Apache License
@@ -2614,7 +2629,7 @@ Apache License
2614
2629
 
2615
2630
  ### mysql
2616
2631
 
2617
- This product includes source derived from [mysql](https://github.com/mysqljs/mysql) ([v2.17.1](https://github.com/mysqljs/mysql/tree/v2.17.1)), distributed under the [MIT License](https://github.com/mysqljs/mysql/blob/v2.17.1/License):
2632
+ This product includes source derived from [mysql](https://github.com/mysqljs/mysql) ([v2.18.1](https://github.com/mysqljs/mysql/tree/v2.18.1)), distributed under the [MIT License](https://github.com/mysqljs/mysql/blob/v2.18.1/License):
2618
2633
 
2619
2634
  ```
2620
2635
  Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
@@ -2743,68 +2758,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
2743
2758
 
2744
2759
  ### request
2745
2760
 
2746
- This product includes source derived from [request](https://github.com/request/request) ([v2.88.0](https://github.com/request/request/tree/v2.88.0)), distributed under the [Apache-2.0 License](https://github.com/request/request/blob/v2.88.0/LICENSE):
2747
-
2748
- ```
2749
- Apache License
2750
-
2751
- Version 2.0, January 2004
2752
-
2753
- http://www.apache.org/licenses/
2754
-
2755
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
2756
-
2757
- 1. Definitions.
2758
-
2759
- "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
2760
-
2761
- "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
2762
-
2763
- "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
2764
-
2765
- "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
2766
-
2767
- "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
2768
-
2769
- "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
2770
-
2771
- "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
2772
-
2773
- "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
2774
-
2775
- "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
2776
-
2777
- "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2778
-
2779
- 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
2780
-
2781
- 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
2782
-
2783
- 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
2784
-
2785
- You must give any other recipients of the Work or Derivative Works a copy of this License; and
2786
-
2787
- You must cause any modified files to carry prominent notices stating that You changed the files; and
2788
-
2789
- You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
2790
-
2791
- If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
2792
-
2793
- 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
2794
-
2795
- 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
2796
-
2797
- 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
2798
-
2799
- 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
2800
-
2801
- 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
2802
-
2803
- END OF TERMS AND CONDITIONS
2804
- ```
2805
-
2806
- ### request
2807
-
2808
2761
  This product includes source derived from [request](https://github.com/request/request) ([v2.88.2](https://github.com/request/request/tree/v2.88.2)), distributed under the [Apache-2.0 License](https://github.com/request/request/blob/v2.88.2/LICENSE):
2809
2762
 
2810
2763
  ```
@@ -2867,7 +2820,7 @@ END OF TERMS AND CONDITIONS
2867
2820
 
2868
2821
  ### restify
2869
2822
 
2870
- This product includes source derived from [restify](https://github.com/restify/node-restify) ([v8.4.0](https://github.com/restify/node-restify/tree/v8.4.0)), distributed under the [MIT License](https://github.com/restify/node-restify/blob/v8.4.0/LICENSE):
2823
+ This product includes source derived from [restify](https://github.com/restify/node-restify) ([v8.5.1](https://github.com/restify/node-restify/tree/v8.5.1)), distributed under the [MIT License](https://github.com/restify/node-restify/blob/v8.5.1/LICENSE):
2871
2824
 
2872
2825
  ```
2873
2826
  Copyright (c) 2011 Mark Cavage, All rights reserved.
@@ -1,5 +1,4 @@
1
1
  #! /usr/bin/env node
2
-
3
2
  /*
4
3
  * Copyright 2020 New Relic Corporation. All rights reserved.
5
4
  * SPDX-License-Identifier: Apache-2.0
package/bin/tracetractor CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  /*
4
3
  * Copyright 2020 New Relic Corporation. All rights reserved.
5
4
  * SPDX-License-Identifier: Apache-2.0
package/lib/agent.js CHANGED
@@ -240,32 +240,12 @@ Agent.prototype.start = function start(callback) {
240
240
  }
241
241
 
242
242
  if (agent.collector.isConnected()) {
243
- agent.onConnect()
244
- agent.setState('started')
245
243
  const config = response.payload
246
244
 
247
- if (agent.config.no_immediate_harvest) {
248
- agent.startAggregators()
245
+ const shouldImmediatelyHarvest = !agent.config.no_immediate_harvest
246
+ agent.onConnect(shouldImmediatelyHarvest, () => {
249
247
  callback(null, config)
250
- } else {
251
- // For data collection that streams immediately, dont delay capture/sending until
252
- // the harvest of everything else has completed.
253
- agent.startStreaming()
254
-
255
- // Harvest immediately for quicker data display, but after at least 1
256
- // second or the collector will throw away the data.
257
- //
258
- // NOTE: this setTimeout is deliberately NOT unref'd due to it being
259
- // the last step in the Agent startup process
260
- setTimeout(function afterTimeout() {
261
- logger.info(`Starting initial ${INITIAL_HARVEST_DELAY_MS}ms harvest.`)
262
-
263
- agent.forceHarvestAll(function afterAllAggregatorsSend() {
264
- agent.startAggregators()
265
- callback(null, config)
266
- })
267
- }, INITIAL_HARVEST_DELAY_MS)
268
- }
248
+ })
269
249
  } else {
270
250
  callback(new Error('Collector did not connect and did not error'))
271
251
  }
@@ -450,18 +430,58 @@ Agent.prototype.startAggregators = function startAggregators() {
450
430
  }
451
431
  }
452
432
 
453
- Agent.prototype.onConnect = function onConnect() {
454
- this.metrics.reconfigure(this.config)
455
- this.errors.reconfigure(this.config)
456
- this.traces.reconfigure(this.config)
457
- this.queries.reconfigure(this.config)
458
- this.spanEventAggregator.reconfigure(this.config)
459
- this.transactionEventAggregator.reconfigure(this.config)
460
- this.customEventAggregator.reconfigure(this.config)
433
+ /**
434
+ * Completes any final setup upon full connection to New Relic
435
+ * servers and sets the agent state to 'started'.
436
+ */
437
+ Agent.prototype.onConnect = function onConnect(shouldImmediatelyHarvest, callback) {
438
+ this._reconfigureAggregators(this.config)
461
439
 
462
440
  if (this.config.certificates && this.config.certificates.length > 0) {
463
441
  this.metrics.getOrCreateMetric(NAMES.FEATURES.CERTIFICATES).incrementCallCount()
464
442
  }
443
+
444
+ this._scheduleHarvests(shouldImmediatelyHarvest, callback)
445
+
446
+ this.setState('started')
447
+ }
448
+
449
+ Agent.prototype._reconfigureAggregators = function _reconfigureAggregators(config) {
450
+ this.metrics.reconfigure(config)
451
+ this.errors.reconfigure(config)
452
+ this.traces.reconfigure(config)
453
+ this.queries.reconfigure(config)
454
+ this.spanEventAggregator.reconfigure(config)
455
+ this.transactionEventAggregator.reconfigure(config)
456
+ this.customEventAggregator.reconfigure(config)
457
+ }
458
+
459
+ Agent.prototype._scheduleHarvests = function _scheduleHarvests(shouldImmediatelyHarvest, callback) {
460
+ if (!shouldImmediatelyHarvest) {
461
+ this.startAggregators()
462
+ setImmediate(callback)
463
+ return
464
+ }
465
+
466
+ const agent = this
467
+
468
+ // For data collection that streams immediately, dont delay capture/sending until
469
+ // the harvest of everything else has completed.
470
+ agent.startStreaming()
471
+
472
+ // Harvest immediately for quicker data display, but after at least 1
473
+ // second or the collector will throw away the data.
474
+ //
475
+ // NOTE: this setTimeout is deliberately NOT unref'd due to it being
476
+ // the last step in the Agent startup process
477
+ setTimeout(function afterTimeout() {
478
+ logger.info(`Starting initial ${INITIAL_HARVEST_DELAY_MS}ms harvest.`)
479
+
480
+ agent.forceHarvestAll(function afterAllAggregatorsSend() {
481
+ agent.startAggregators()
482
+ callback()
483
+ })
484
+ }, INITIAL_HARVEST_DELAY_MS)
465
485
  }
466
486
 
467
487
  /**
@@ -515,9 +515,8 @@ CollectorAPI.prototype.restart = function restart(callback) {
515
515
  var api = this
516
516
  this.shutdown(function reconnect() {
517
517
  api.connect(function afterConnect() {
518
- api._agent.onConnect()
519
- api._agent.startAggregators()
520
- return callback.apply(null, arguments)
518
+ const shouldImmediatelyHarvest = false
519
+ api._agent.onConnect(shouldImmediatelyHarvest, callback)
521
520
  })
522
521
  })
523
522
  }
@@ -1,3 +1,8 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
1
6
  'use strict'
2
7
 
3
8
  const getRawRequestFromFastifyRequest = (shim, fn, fnName, args) => {
@@ -1,3 +1,8 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
1
6
  'use strict'
2
7
  const semver = require('semver')
3
8
  const {
@@ -0,0 +1,186 @@
1
+ /*
2
+ * Copyright 2021 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ 'use strict'
7
+ const {
8
+ CURSOR_OPS,
9
+ COLLECTION_OPS,
10
+ DB_OPS
11
+ } = require('./constants')
12
+ const { URL } = require('url')
13
+
14
+ const common = module.exports
15
+
16
+ /**
17
+ * Instruments all methods from constants.CURSOR_OPS on a given
18
+ * cursor class
19
+ *
20
+ * @param {Shim} shim
21
+ * @param {Cursor} Cursor
22
+ */
23
+ common.instrumentCursor = function instrumentCursor(shim, Cursor) {
24
+ if (Cursor && Cursor.prototype) {
25
+ const proto = Cursor.prototype
26
+ for (let i = 0; i < CURSOR_OPS.length; i++) {
27
+ shim.recordQuery(proto, CURSOR_OPS[i], common.makeQueryDescFunc(shim, CURSOR_OPS[i]))
28
+ }
29
+
30
+ shim.recordQuery(proto, 'each', common.makeQueryDescFunc(shim, 'each'))
31
+ shim.recordOperation(proto, 'pipe')
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Instruments all methods from constants.COLLECTION_OPS on
37
+ * the Collection class
38
+ *
39
+ * @param {Shim} shim
40
+ * @param {Collection} Collection
41
+ */
42
+ common.instrumentCollection = function instrumentCollection(shim, Collection) {
43
+ if (Collection && Collection.prototype) {
44
+ const proto = Collection.prototype
45
+ for (let i = 0; i < COLLECTION_OPS.length; i++) {
46
+ shim.recordQuery(
47
+ proto,
48
+ COLLECTION_OPS[i],
49
+ common.makeQueryDescFunc(shim, COLLECTION_OPS[i])
50
+ )
51
+ }
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Instruments all methods from constants.DB_OPS on
57
+ * the Db class.
58
+ *
59
+ * @param {Object} params
60
+ * @param {Shim} params.shim
61
+ * @param {Db} params.Db
62
+ */
63
+ common.instrumentDb = function instrumentDb(shim, Db) {
64
+ if (Db && Db.prototype) {
65
+ const proto = Db.prototype
66
+ shim.recordOperation(proto, DB_OPS, {callback: shim.LAST, opaque: true })
67
+ // link to client.connect(removed in v4.0)
68
+ shim.recordOperation(Db, 'connect', {callback: shim.LAST})
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Sets up the desc for all instrumented query methods
74
+ * @param {Shim} shim
75
+ * @param {string} methodName
76
+ */
77
+ common.makeQueryDescFunc = function makeQueryDescFunc(shim, methodName) {
78
+ if (methodName === 'each') {
79
+ return function eachDescFunc() {
80
+ const parameters = getInstanceAttributeParameters(shim, this)
81
+ return {query: methodName, parameters, rowCallback: shim.LAST, opaque: true }
82
+ }
83
+ }
84
+
85
+ return function queryDescFunc() {
86
+ // segment name does not actually use query string
87
+ // method name is set as query so the query parser has access to the op name
88
+ const parameters = getInstanceAttributeParameters(shim, this)
89
+ return {query: methodName, parameters, promise: true, callback: shim.LAST, opaque: true}
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Sets up a listener for `started` on instrumenter(mongo APM). This applies to
95
+ * mongo <4. The listener adds the following attributes to the active segment:
96
+ * host, port_path_or_id, and database_name
97
+ *
98
+ * @param {Shim} shim
99
+ * @param {Instrumentation} instrumenter instance of mongo APM class
100
+ */
101
+ common.captureAttributesOnStarted = function captureAttributesOnStarted(shim, instrumenter) {
102
+ instrumenter.on('started', function onMongoEventStarted(evnt) {
103
+ // This assumes that this `started` event is fired _after_ our wrapper
104
+ // starts and creates the segment. We perform a check of the segment name
105
+ // out of an excess of caution.
106
+ const connId = evnt.connectionId
107
+ if (connId) {
108
+ // Mongo sticks the path to the domain socket in the "host" slot, but we
109
+ // want it in the "port", so if we have a domain socket we need to change
110
+ // the order of our parameters.
111
+ if (typeof connId === 'string') {
112
+ const parts = connId.split(':')
113
+ if (parts.length && parts[0][0] === '/') {
114
+ shim.captureInstanceAttributes('localhost', parts[0], evnt.databaseName)
115
+ } else {
116
+ shim.captureInstanceAttributes(parts[0], parts[1], evnt.databaseName)
117
+ }
118
+ } else if (connId.domainSocket) {
119
+ shim.captureInstanceAttributes('localhost', connId.host, evnt.databaseName)
120
+ } else {
121
+ shim.captureInstanceAttributes(connId.host, connId.port, evnt.databaseName)
122
+ }
123
+ }
124
+ })
125
+ }
126
+
127
+ /**
128
+ * Get the database_name, host, port_path_or_id
129
+ * for the query segment. v4 refactored where the toplogy is stored.
130
+ * You can now get the details via the client obj that's deeply nested
131
+ * See: https://github.com/mongodb/node-mongodb-native/pull/2594/files#diff-1d214e57ddda9095d296e5700ebce701333bfefcf417e234c584d14091b2f50dR168
132
+ */
133
+ function getInstanceAttributeParameters(shim, obj) {
134
+ if (obj.s && obj.s.db && obj.s.topology) {
135
+ shim.logger.trace(
136
+ 'Adding datastore instance attributes from obj.s.db + obj.s.topology'
137
+ )
138
+ const databaseName = obj.s.db.databaseName || null
139
+ const topology = obj.s.topology
140
+ if (topology.s && topology.s.options) {
141
+ return doCapture(topology.s.options, databaseName)
142
+ }
143
+ } else if (obj.s && obj.s.db && obj.s.db.s && obj.s.db.s.client &&
144
+ obj.s.db.s.client.s && obj.s.db.s.client.s.url) {
145
+ let { hostname: host, port: port_path_or_id } = new URL(obj.s.db.s.client.s.url)
146
+ if (host.endsWith('.sock')) {
147
+ // socket path is uri encoded
148
+ // decode it to properly name attrs
149
+ port_path_or_id = decodeURIComponent(host)
150
+ host = 'localhost'
151
+ }
152
+ return {
153
+ host,
154
+ port_path_or_id,
155
+ database_name: obj.s.db.databaseName
156
+ }
157
+ }
158
+
159
+ shim.logger.trace('Could not find datastore instance attributes.')
160
+ return {
161
+ host: null,
162
+ port_path_or_id: null,
163
+ database_name: null
164
+ }
165
+
166
+ function doCapture(conf, database) {
167
+ let host = conf.host
168
+ let port = conf.port
169
+
170
+ // If using a domain socket, mongo stores the path as the host name, but we
171
+ // pass it through the port value.
172
+ if (
173
+ (conf.socketOptions && conf.socketOptions.domainSocket) ||
174
+ /\.sock$/.test(host)
175
+ ) {
176
+ port = host
177
+ host = 'localhost'
178
+ }
179
+
180
+ return {
181
+ host: host,
182
+ port_path_or_id: port,
183
+ database_name: database
184
+ }
185
+ }
186
+ }