newrelic 6.4.0 → 6.6.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 (44) hide show
  1. package/.eslintignore +1 -1
  2. package/{.eslintrc → .eslintrc.js} +2 -1
  3. package/.travis.yml +5 -6
  4. package/NEWS.md +105 -1
  5. package/THIRD_PARTY_NOTICES.md +420 -0
  6. package/api.js +72 -1
  7. package/index.js +3 -3
  8. package/lib/agent.js +22 -8
  9. package/lib/aggregators/base-aggregator.js +1 -1
  10. package/lib/attributes.js +15 -6
  11. package/lib/collector/serverless.js +8 -0
  12. package/lib/config/default.js +23 -1
  13. package/lib/config/env.js +7 -1
  14. package/lib/config/hsm.js +6 -1
  15. package/lib/config/index.js +36 -8
  16. package/lib/config/lasp.js +16 -1
  17. package/lib/errors/error-collector.js +51 -90
  18. package/lib/errors/helper.js +13 -13
  19. package/lib/errors/index.js +36 -18
  20. package/lib/grpc/connection/states.js +9 -0
  21. package/lib/grpc/connection.js +344 -0
  22. package/lib/grpc/endpoints/infinite-tracing/v1.proto +29 -0
  23. package/lib/header-processing.js +75 -0
  24. package/lib/instrumentation/core/child_process.js +12 -0
  25. package/lib/instrumentation/core/http-outbound.js +4 -0
  26. package/lib/instrumentation/core/http.js +98 -145
  27. package/lib/instrumentation/hapi/hapi-17.js +10 -3
  28. package/lib/metrics/names.js +12 -1
  29. package/lib/proxy/grpc.js +15 -0
  30. package/lib/serverless/aws-lambda.js +2 -0
  31. package/lib/spans/create-span-event-aggregator.js +112 -0
  32. package/lib/spans/map-to-streaming-type.js +44 -0
  33. package/lib/spans/span-event-aggregator.js +5 -0
  34. package/lib/spans/span-event.js +22 -9
  35. package/lib/spans/span-streamer.js +109 -0
  36. package/lib/spans/streaming-span-attributes.js +59 -0
  37. package/lib/spans/streaming-span-event-aggregator.js +98 -0
  38. package/lib/spans/streaming-span-event.js +261 -0
  39. package/lib/transaction/index.js +36 -20
  40. package/lib/transaction/trace/index.js +13 -10
  41. package/lib/transaction/trace/segment.js +12 -1
  42. package/lib/transaction/tracecontext.js +4 -0
  43. package/package.json +10 -10
  44. package/stub_api.js +5 -0
package/.eslintignore CHANGED
@@ -1 +1 @@
1
- **/node_modules/**
1
+ **/node_modules/**
@@ -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",
package/.travis.yml CHANGED
@@ -14,12 +14,11 @@ env:
14
14
  - NR_NODE_VERSION=10 SUITE=integration
15
15
  - NR_NODE_VERSION=10 SUITE=versioned
16
16
  # NODE 12 --
17
- - NR_NODE_VERSION=12.15 SUITE=smoke
18
- - NR_NODE_VERSION=12.15 SUITE=unit
19
- - NR_NODE_VERSION=12.15 SUITE=integration
20
- - NR_NODE_VERSION=12.15 SUITE=lint
21
- - NR_NODE_VERSION=12.15 SUITE=security
22
- - NR_NODE_VERSION=12.15 SUITE=versioned
17
+ - NR_NODE_VERSION=12 SUITE=smoke
18
+ - NR_NODE_VERSION=12 SUITE=unit
19
+ - NR_NODE_VERSION=12 SUITE=integration
20
+ - NR_NODE_VERSION=12 SUITE=lint
21
+ - NR_NODE_VERSION=12 SUITE=versioned
23
22
  services:
24
23
  - memcached
25
24
  - mysql
package/NEWS.md CHANGED
@@ -1,3 +1,105 @@
1
+ ### 6.6.0 (2020-04-20):
2
+
3
+ * Added support for [Infinite Tracing on New Relic
4
+ Edge](https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/enable-configure/enable-distributed-tracing).
5
+
6
+ Infinite Tracing observes 100% of your distributed traces and provides
7
+ visualizations for the most actionable data so you have the examples of errors
8
+ and long-running traces so you can better diagnose and troubleshoot your systems.
9
+
10
+ You configure your agent to send traces to a trace observer in New Relic Edge.
11
+ You view your distributed traces through the New Relic’s UI. There is no need to
12
+ install a collector on your network.
13
+
14
+ Infinite Tracing is currently available on a sign-up basis. If you would like to
15
+ participate, please contact your sales representative.
16
+
17
+ * Added `function_version` to lambda metadata payload.
18
+
19
+ This is pulled from an invocation's `context.functionVersion` value.
20
+
21
+ ### 6.5.0 (2020-03-18):
22
+
23
+ * Added error attributes to spans.
24
+ * The public api method `noticeError()` now attaches exception details to the currently executing
25
+ span. Spans with error details are now highlighted red in the Distributed Tracing UI. Also, the
26
+ attributes `error.class` and `error.message` are added to the span. If multiple errors are
27
+ recorded for a single span, only the final error's attributes will be added to the span.
28
+
29
+ * Added ID of the span in which an error occurred to the corresponding transaction error event.
30
+
31
+ * Added new public API methods `addCustomSpanAttribute` and `addCustomSpanAttributes` to add
32
+ attributes to the currently executing span.
33
+
34
+ * Added new attributes to http outbound spans: `http.statusCode` and `http.statusText`.
35
+
36
+ * Updated W3C Trace Context "Known Issues and Workaround" notes with latest accurate consideration.
37
+
38
+ * Converted unit tests to run via `tap`. Removes `mocha` dependency.
39
+
40
+ * Fixed route naming when hapi's `pre` route handlers share functions.
41
+
42
+ * Fixed `child_process` instrumentation so that handlers can be effectively removed
43
+ when attached via `.once()` or manually removed via `removeListener()`.
44
+
45
+ ### 6.4.2 (2020-02-27):
46
+
47
+ * Support new http[s] get/request function signature in Node v10+
48
+
49
+ * Added the following Span Event attributes:
50
+ - http.statusCode
51
+ - http.statusText
52
+
53
+ The above attributes will be replacing the following *deprecated* attributes:
54
+ - httpResponseCode
55
+ - response.status
56
+ - response.statusMessage
57
+
58
+ The deprecated attributes will be removed with the next major release of the Agent.
59
+
60
+ * Updates version check to be in alignment with [our stated support
61
+ policy](https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent)
62
+ and the version constraints in package.json
63
+
64
+ * Redacts individual certificates configuration values before sending to server
65
+ settings. When configured, these values will now appear like: `{certificates.0: ****}`.
66
+
67
+ ### 6.4.1 (2020-02-20):
68
+
69
+ * Bumped `@newrelic/aws-sdk` version to `v1.1.2` from `v1.1.1`.
70
+ https://github.com/newrelic/node-newrelic-aws-sdk/blob/master/CHANGELOG.md
71
+
72
+ Notable improvements include:
73
+ * Fixed issue where instrumentation would crash pulling `host` and `port` values
74
+ when `AmazonDaxClient` was used as the service for `DocumentClient`.
75
+
76
+ * Prevented passing CI with `.only()` in mocha tests.
77
+
78
+ * Removed CI restriction for Node `12.15`. Node shipped a fix for the `12.16`
79
+ breakage in `12.16.1`.
80
+
81
+ * Removed calls to `OutgoingMessage.prototype._headers` in favor of using public
82
+ `getHeaders` API (thanks to @adityasabnis for bringing this to our attention).
83
+
84
+ * Removed engine upper-bound to enable easier experimentation of newer Node versions
85
+ with the agent for customers.
86
+
87
+ Please see https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent for officially supported versions.
88
+ Incompatibilities are expected for odd-numbered releases, which are not supported,
89
+ and even-numbered releases before "official" support has been released.
90
+
91
+ * Reduced "... Aggregator data send." log messages to `debug` level to reduce noise
92
+ of default logs.
93
+
94
+ * Fixed issue where disabled agent would return an empty string instead of an empty
95
+ object from API#getLinkingMetadata().
96
+
97
+ This issue would cause the `@newrelic/winston-enricher` module to crash when
98
+ attempting to inject log metatdata.
99
+
100
+ * Reduced logging level of raw `x-queue-start` or `x-request-start` header values
101
+ to avoid logging very large values at default logging levels.
102
+
1
103
  ### 6.4.0 (2020-02-12):
2
104
 
3
105
  * Added support for W3C Trace Context, with easy upgrade from New Relic trace
@@ -34,7 +136,9 @@
34
136
 
35
137
  Known Issues and Workarounds
36
138
 
37
- * If a .NET agent is initiating traces as the root service, do not upgrade your downstream Node New Relic agents to this agent release.
139
+ * If a .NET agent is initiating distributed traces as the root service, you must update
140
+ that .NET agent to version `8.24` or later before upgrading your downstream Node
141
+ New Relic agents to this agent release.
38
142
 
39
143
  * Pins Node 12 version to `v12.15` to avoid breakages with `v12.16.0` until cause(s)
40
144
  resolved.
@@ -237,3 +237,423 @@ THE SOFTWARE.
237
237
  ```
238
238
 
239
239
  Portions copyright [Node.js] contributors. Depending on your existing libraries and package management settings, your systems may call externally maintained libraries in addition to those listed above. See [here](https://nodejs.org/en/docs/meta/topics/dependencies/) and [here](https://github.com/nodejs/node/blob/v4.3.1/LICENSE) for additional details regarding externally maintained libraries and certain related licenses and notices.
240
+
241
+ ## @grpc/grpc-js
242
+
243
+ This product includes source derived from
244
+ [@grpc/grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js), distributed under the
245
+ [Apache-2.0 license](https://github.com/grpc/grpc-node/blob/%40grpc/grpc-js%400.6.12/packages/grpc-js/LICENSE):
246
+
247
+ ```
248
+ Apache License
249
+ Version 2.0, January 2004
250
+ http://www.apache.org/licenses/
251
+
252
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
253
+
254
+ 1. Definitions.
255
+
256
+ "License" shall mean the terms and conditions for use, reproduction,
257
+ and distribution as defined by Sections 1 through 9 of this document.
258
+
259
+ "Licensor" shall mean the copyright owner or entity authorized by
260
+ the copyright owner that is granting the License.
261
+
262
+ "Legal Entity" shall mean the union of the acting entity and all
263
+ other entities that control, are controlled by, or are under common
264
+ control with that entity. For the purposes of this definition,
265
+ "control" means (i) the power, direct or indirect, to cause the
266
+ direction or management of such entity, whether by contract or
267
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
268
+ outstanding shares, or (iii) beneficial ownership of such entity.
269
+
270
+ "You" (or "Your") shall mean an individual or Legal Entity
271
+ exercising permissions granted by this License.
272
+
273
+ "Source" form shall mean the preferred form for making modifications,
274
+ including but not limited to software source code, documentation
275
+ source, and configuration files.
276
+
277
+ "Object" form shall mean any form resulting from mechanical
278
+ transformation or translation of a Source form, including but
279
+ not limited to compiled object code, generated documentation,
280
+ and conversions to other media types.
281
+
282
+ "Work" shall mean the work of authorship, whether in Source or
283
+ Object form, made available under the License, as indicated by a
284
+ copyright notice that is included in or attached to the work
285
+ (an example is provided in the Appendix below).
286
+
287
+ "Derivative Works" shall mean any work, whether in Source or Object
288
+ form, that is based on (or derived from) the Work and for which the
289
+ editorial revisions, annotations, elaborations, or other modifications
290
+ represent, as a whole, an original work of authorship. For the purposes
291
+ of this License, Derivative Works shall not include works that remain
292
+ separable from, or merely link (or bind by name) to the interfaces of,
293
+ the Work and Derivative Works thereof.
294
+
295
+ "Contribution" shall mean any work of authorship, including
296
+ the original version of the Work and any modifications or additions
297
+ to that Work or Derivative Works thereof, that is intentionally
298
+ submitted to Licensor for inclusion in the Work by the copyright owner
299
+ or by an individual or Legal Entity authorized to submit on behalf of
300
+ the copyright owner. For the purposes of this definition, "submitted"
301
+ means any form of electronic, verbal, or written communication sent
302
+ to the Licensor or its representatives, including but not limited to
303
+ communication on electronic mailing lists, source code control systems,
304
+ and issue tracking systems that are managed by, or on behalf of, the
305
+ Licensor for the purpose of discussing and improving the Work, but
306
+ excluding communication that is conspicuously marked or otherwise
307
+ designated in writing by the copyright owner as "Not a Contribution."
308
+
309
+ "Contributor" shall mean Licensor and any individual or Legal Entity
310
+ on behalf of whom a Contribution has been received by Licensor and
311
+ subsequently incorporated within the Work.
312
+
313
+ 2. Grant of Copyright License. Subject to the terms and conditions of
314
+ this License, each Contributor hereby grants to You a perpetual,
315
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
316
+ copyright license to reproduce, prepare Derivative Works of,
317
+ publicly display, publicly perform, sublicense, and distribute the
318
+ Work and such Derivative Works in Source or Object form.
319
+
320
+ 3. Grant of Patent License. Subject to the terms and conditions of
321
+ this License, each Contributor hereby grants to You a perpetual,
322
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
323
+ (except as stated in this section) patent license to make, have made,
324
+ use, offer to sell, sell, import, and otherwise transfer the Work,
325
+ where such license applies only to those patent claims licensable
326
+ by such Contributor that are necessarily infringed by their
327
+ Contribution(s) alone or by combination of their Contribution(s)
328
+ with the Work to which such Contribution(s) was submitted. If You
329
+ institute patent litigation against any entity (including a
330
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
331
+ or a Contribution incorporated within the Work constitutes direct
332
+ or contributory patent infringement, then any patent licenses
333
+ granted to You under this License for that Work shall terminate
334
+ as of the date such litigation is filed.
335
+
336
+ 4. Redistribution. You may reproduce and distribute copies of the
337
+ Work or Derivative Works thereof in any medium, with or without
338
+ modifications, and in Source or Object form, provided that You
339
+ meet the following conditions:
340
+
341
+ (a) You must give any other recipients of the Work or
342
+ Derivative Works a copy of this License; and
343
+
344
+ (b) You must cause any modified files to carry prominent notices
345
+ stating that You changed the files; and
346
+
347
+ (c) You must retain, in the Source form of any Derivative Works
348
+ that You distribute, all copyright, patent, trademark, and
349
+ attribution notices from the Source form of the Work,
350
+ excluding those notices that do not pertain to any part of
351
+ the Derivative Works; and
352
+
353
+ (d) If the Work includes a "NOTICE" text file as part of its
354
+ distribution, then any Derivative Works that You distribute must
355
+ include a readable copy of the attribution notices contained
356
+ within such NOTICE file, excluding those notices that do not
357
+ pertain to any part of the Derivative Works, in at least one
358
+ of the following places: within a NOTICE text file distributed
359
+ as part of the Derivative Works; within the Source form or
360
+ documentation, if provided along with the Derivative Works; or,
361
+ within a display generated by the Derivative Works, if and
362
+ wherever such third-party notices normally appear. The contents
363
+ of the NOTICE file are for informational purposes only and
364
+ do not modify the License. You may add Your own attribution
365
+ notices within Derivative Works that You distribute, alongside
366
+ or as an addendum to the NOTICE text from the Work, provided
367
+ that such additional attribution notices cannot be construed
368
+ as modifying the License.
369
+
370
+ You may add Your own copyright statement to Your modifications and
371
+ may provide additional or different license terms and conditions
372
+ for use, reproduction, or distribution of Your modifications, or
373
+ for any such Derivative Works as a whole, provided Your use,
374
+ reproduction, and distribution of the Work otherwise complies with
375
+ the conditions stated in this License.
376
+
377
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
378
+ any Contribution intentionally submitted for inclusion in the Work
379
+ by You to the Licensor shall be under the terms and conditions of
380
+ this License, without any additional terms or conditions.
381
+ Notwithstanding the above, nothing herein shall supersede or modify
382
+ the terms of any separate license agreement you may have executed
383
+ with Licensor regarding such Contributions.
384
+
385
+ 6. Trademarks. This License does not grant permission to use the trade
386
+ names, trademarks, service marks, or product names of the Licensor,
387
+ except as required for reasonable and customary use in describing the
388
+ origin of the Work and reproducing the content of the NOTICE file.
389
+
390
+ 7. Disclaimer of Warranty. Unless required by applicable law or
391
+ agreed to in writing, Licensor provides the Work (and each
392
+ Contributor provides its Contributions) on an "AS IS" BASIS,
393
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
394
+ implied, including, without limitation, any warranties or conditions
395
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
396
+ PARTICULAR PURPOSE. You are solely responsible for determining the
397
+ appropriateness of using or redistributing the Work and assume any
398
+ risks associated with Your exercise of permissions under this License.
399
+
400
+ 8. Limitation of Liability. In no event and under no legal theory,
401
+ whether in tort (including negligence), contract, or otherwise,
402
+ unless required by applicable law (such as deliberate and grossly
403
+ negligent acts) or agreed to in writing, shall any Contributor be
404
+ liable to You for damages, including any direct, indirect, special,
405
+ incidental, or consequential damages of any character arising as a
406
+ result of this License or out of the use or inability to use the
407
+ Work (including but not limited to damages for loss of goodwill,
408
+ work stoppage, computer failure or malfunction, or any and all
409
+ other commercial damages or losses), even if such Contributor
410
+ has been advised of the possibility of such damages.
411
+
412
+ 9. Accepting Warranty or Additional Liability. While redistributing
413
+ the Work or Derivative Works thereof, You may choose to offer,
414
+ and charge a fee for, acceptance of support, warranty, indemnity,
415
+ or other liability obligations and/or rights consistent with this
416
+ License. However, in accepting such obligations, You may act only
417
+ on Your own behalf and on Your sole responsibility, not on behalf
418
+ of any other Contributor, and only if You agree to indemnify,
419
+ defend, and hold each Contributor harmless for any liability
420
+ incurred by, or claims asserted against, such Contributor by reason
421
+ of your accepting any such warranty or additional liability.
422
+
423
+ END OF TERMS AND CONDITIONS
424
+
425
+ APPENDIX: How to apply the Apache License to your work.
426
+
427
+ To apply the Apache License to your work, attach the following
428
+ boilerplate notice, with the fields enclosed by brackets "{}"
429
+ replaced with your own identifying information. (Don't include
430
+ the brackets!) The text should be enclosed in the appropriate
431
+ comment syntax for the file format. We also recommend that a
432
+ file or class name and description of purpose be included on the
433
+ same "printed page" as the copyright notice for easier
434
+ identification within third-party archives.
435
+
436
+ Copyright {yyyy} {name of copyright owner}
437
+
438
+ Licensed under the Apache License, Version 2.0 (the "License");
439
+ you may not use this file except in compliance with the License.
440
+ You may obtain a copy of the License at
441
+
442
+ http://www.apache.org/licenses/LICENSE-2.0
443
+
444
+ Unless required by applicable law or agreed to in writing, software
445
+ distributed under the License is distributed on an "AS IS" BASIS,
446
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
447
+ See the License for the specific language governing permissions and
448
+ limitations under the License.
449
+ ```
450
+
451
+ ## @grpc/proto-loader
452
+
453
+ This product includes source derived from
454
+ [@grpc/proto-loader](https://github.com/grpc/grpc-node/tree/master/packages/proto-loader), distributed under the
455
+ [Apache-2.0 license](https://github.com/grpc/grpc-node/blob/%40grpc/proto-loader%400.5.2/packages/proto-loader/LICENSE):
456
+
457
+ ```
458
+ Apache License
459
+ Version 2.0, January 2004
460
+ http://www.apache.org/licenses/
461
+
462
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
463
+
464
+ 1. Definitions.
465
+
466
+ "License" shall mean the terms and conditions for use, reproduction,
467
+ and distribution as defined by Sections 1 through 9 of this document.
468
+
469
+ "Licensor" shall mean the copyright owner or entity authorized by
470
+ the copyright owner that is granting the License.
471
+
472
+ "Legal Entity" shall mean the union of the acting entity and all
473
+ other entities that control, are controlled by, or are under common
474
+ control with that entity. For the purposes of this definition,
475
+ "control" means (i) the power, direct or indirect, to cause the
476
+ direction or management of such entity, whether by contract or
477
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
478
+ outstanding shares, or (iii) beneficial ownership of such entity.
479
+
480
+ "You" (or "Your") shall mean an individual or Legal Entity
481
+ exercising permissions granted by this License.
482
+
483
+ "Source" form shall mean the preferred form for making modifications,
484
+ including but not limited to software source code, documentation
485
+ source, and configuration files.
486
+
487
+ "Object" form shall mean any form resulting from mechanical
488
+ transformation or translation of a Source form, including but
489
+ not limited to compiled object code, generated documentation,
490
+ and conversions to other media types.
491
+
492
+ "Work" shall mean the work of authorship, whether in Source or
493
+ Object form, made available under the License, as indicated by a
494
+ copyright notice that is included in or attached to the work
495
+ (an example is provided in the Appendix below).
496
+
497
+ "Derivative Works" shall mean any work, whether in Source or Object
498
+ form, that is based on (or derived from) the Work and for which the
499
+ editorial revisions, annotations, elaborations, or other modifications
500
+ represent, as a whole, an original work of authorship. For the purposes
501
+ of this License, Derivative Works shall not include works that remain
502
+ separable from, or merely link (or bind by name) to the interfaces of,
503
+ the Work and Derivative Works thereof.
504
+
505
+ "Contribution" shall mean any work of authorship, including
506
+ the original version of the Work and any modifications or additions
507
+ to that Work or Derivative Works thereof, that is intentionally
508
+ submitted to Licensor for inclusion in the Work by the copyright owner
509
+ or by an individual or Legal Entity authorized to submit on behalf of
510
+ the copyright owner. For the purposes of this definition, "submitted"
511
+ means any form of electronic, verbal, or written communication sent
512
+ to the Licensor or its representatives, including but not limited to
513
+ communication on electronic mailing lists, source code control systems,
514
+ and issue tracking systems that are managed by, or on behalf of, the
515
+ Licensor for the purpose of discussing and improving the Work, but
516
+ excluding communication that is conspicuously marked or otherwise
517
+ designated in writing by the copyright owner as "Not a Contribution."
518
+
519
+ "Contributor" shall mean Licensor and any individual or Legal Entity
520
+ on behalf of whom a Contribution has been received by Licensor and
521
+ subsequently incorporated within the Work.
522
+
523
+ 2. Grant of Copyright License. Subject to the terms and conditions of
524
+ this License, each Contributor hereby grants to You a perpetual,
525
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
526
+ copyright license to reproduce, prepare Derivative Works of,
527
+ publicly display, publicly perform, sublicense, and distribute the
528
+ Work and such Derivative Works in Source or Object form.
529
+
530
+ 3. Grant of Patent License. Subject to the terms and conditions of
531
+ this License, each Contributor hereby grants to You a perpetual,
532
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
533
+ (except as stated in this section) patent license to make, have made,
534
+ use, offer to sell, sell, import, and otherwise transfer the Work,
535
+ where such license applies only to those patent claims licensable
536
+ by such Contributor that are necessarily infringed by their
537
+ Contribution(s) alone or by combination of their Contribution(s)
538
+ with the Work to which such Contribution(s) was submitted. If You
539
+ institute patent litigation against any entity (including a
540
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
541
+ or a Contribution incorporated within the Work constitutes direct
542
+ or contributory patent infringement, then any patent licenses
543
+ granted to You under this License for that Work shall terminate
544
+ as of the date such litigation is filed.
545
+
546
+ 4. Redistribution. You may reproduce and distribute copies of the
547
+ Work or Derivative Works thereof in any medium, with or without
548
+ modifications, and in Source or Object form, provided that You
549
+ meet the following conditions:
550
+
551
+ (a) You must give any other recipients of the Work or
552
+ Derivative Works a copy of this License; and
553
+
554
+ (b) You must cause any modified files to carry prominent notices
555
+ stating that You changed the files; and
556
+
557
+ (c) You must retain, in the Source form of any Derivative Works
558
+ that You distribute, all copyright, patent, trademark, and
559
+ attribution notices from the Source form of the Work,
560
+ excluding those notices that do not pertain to any part of
561
+ the Derivative Works; and
562
+
563
+ (d) If the Work includes a "NOTICE" text file as part of its
564
+ distribution, then any Derivative Works that You distribute must
565
+ include a readable copy of the attribution notices contained
566
+ within such NOTICE file, excluding those notices that do not
567
+ pertain to any part of the Derivative Works, in at least one
568
+ of the following places: within a NOTICE text file distributed
569
+ as part of the Derivative Works; within the Source form or
570
+ documentation, if provided along with the Derivative Works; or,
571
+ within a display generated by the Derivative Works, if and
572
+ wherever such third-party notices normally appear. The contents
573
+ of the NOTICE file are for informational purposes only and
574
+ do not modify the License. You may add Your own attribution
575
+ notices within Derivative Works that You distribute, alongside
576
+ or as an addendum to the NOTICE text from the Work, provided
577
+ that such additional attribution notices cannot be construed
578
+ as modifying the License.
579
+
580
+ You may add Your own copyright statement to Your modifications and
581
+ may provide additional or different license terms and conditions
582
+ for use, reproduction, or distribution of Your modifications, or
583
+ for any such Derivative Works as a whole, provided Your use,
584
+ reproduction, and distribution of the Work otherwise complies with
585
+ the conditions stated in this License.
586
+
587
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
588
+ any Contribution intentionally submitted for inclusion in the Work
589
+ by You to the Licensor shall be under the terms and conditions of
590
+ this License, without any additional terms or conditions.
591
+ Notwithstanding the above, nothing herein shall supersede or modify
592
+ the terms of any separate license agreement you may have executed
593
+ with Licensor regarding such Contributions.
594
+
595
+ 6. Trademarks. This License does not grant permission to use the trade
596
+ names, trademarks, service marks, or product names of the Licensor,
597
+ except as required for reasonable and customary use in describing the
598
+ origin of the Work and reproducing the content of the NOTICE file.
599
+
600
+ 7. Disclaimer of Warranty. Unless required by applicable law or
601
+ agreed to in writing, Licensor provides the Work (and each
602
+ Contributor provides its Contributions) on an "AS IS" BASIS,
603
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
604
+ implied, including, without limitation, any warranties or conditions
605
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
606
+ PARTICULAR PURPOSE. You are solely responsible for determining the
607
+ appropriateness of using or redistributing the Work and assume any
608
+ risks associated with Your exercise of permissions under this License.
609
+
610
+ 8. Limitation of Liability. In no event and under no legal theory,
611
+ whether in tort (including negligence), contract, or otherwise,
612
+ unless required by applicable law (such as deliberate and grossly
613
+ negligent acts) or agreed to in writing, shall any Contributor be
614
+ liable to You for damages, including any direct, indirect, special,
615
+ incidental, or consequential damages of any character arising as a
616
+ result of this License or out of the use or inability to use the
617
+ Work (including but not limited to damages for loss of goodwill,
618
+ work stoppage, computer failure or malfunction, or any and all
619
+ other commercial damages or losses), even if such Contributor
620
+ has been advised of the possibility of such damages.
621
+
622
+ 9. Accepting Warranty or Additional Liability. While redistributing
623
+ the Work or Derivative Works thereof, You may choose to offer,
624
+ and charge a fee for, acceptance of support, warranty, indemnity,
625
+ or other liability obligations and/or rights consistent with this
626
+ License. However, in accepting such obligations, You may act only
627
+ on Your own behalf and on Your sole responsibility, not on behalf
628
+ of any other Contributor, and only if You agree to indemnify,
629
+ defend, and hold each Contributor harmless for any liability
630
+ incurred by, or claims asserted against, such Contributor by reason
631
+ of your accepting any such warranty or additional liability.
632
+
633
+ END OF TERMS AND CONDITIONS
634
+
635
+ APPENDIX: How to apply the Apache License to your work.
636
+
637
+ To apply the Apache License to your work, attach the following
638
+ boilerplate notice, with the fields enclosed by brackets "{}"
639
+ replaced with your own identifying information. (Don't include
640
+ the brackets!) The text should be enclosed in the appropriate
641
+ comment syntax for the file format. We also recommend that a
642
+ file or class name and description of purpose be included on the
643
+ same "printed page" as the copyright notice for easier
644
+ identification within third-party archives.
645
+
646
+ Copyright {yyyy} {name of copyright owner}
647
+
648
+ Licensed under the Apache License, Version 2.0 (the "License");
649
+ you may not use this file except in compliance with the License.
650
+ You may obtain a copy of the License at
651
+
652
+ http://www.apache.org/licenses/LICENSE-2.0
653
+
654
+ Unless required by applicable law or agreed to in writing, software
655
+ distributed under the License is distributed on an "AS IS" BASIS,
656
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
657
+ See the License for the specific language governing permissions and
658
+ limitations under the License.
659
+ ```
package/api.js CHANGED
@@ -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