newrelic 11.10.4 → 11.11.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 (73) hide show
  1. package/NEWS.md +63 -20
  2. package/THIRD_PARTY_NOTICES.md +32 -32
  3. package/api.js +22 -49
  4. package/lib/config/default.js +10 -0
  5. package/lib/instrumentation/@elastic/elasticsearch.js +4 -2
  6. package/lib/instrumentation/@hapi/hapi.js +32 -22
  7. package/lib/instrumentation/@hapi/vision.js +2 -1
  8. package/lib/instrumentation/@node-redis/client.js +9 -4
  9. package/lib/instrumentation/@prisma/client.js +3 -2
  10. package/lib/instrumentation/amqplib/amqplib.js +71 -41
  11. package/lib/instrumentation/cassandra-driver.js +30 -13
  12. package/lib/instrumentation/connect.js +20 -11
  13. package/lib/instrumentation/core/child_process.js +3 -1
  14. package/lib/instrumentation/core/crypto.js +4 -2
  15. package/lib/instrumentation/core/dns.js +3 -1
  16. package/lib/instrumentation/core/fs.js +2 -1
  17. package/lib/instrumentation/core/timers.js +2 -1
  18. package/lib/instrumentation/core/zlib.js +2 -1
  19. package/lib/instrumentation/director.js +37 -25
  20. package/lib/instrumentation/express.js +65 -49
  21. package/lib/instrumentation/fastify.js +3 -2
  22. package/lib/instrumentation/ioredis.js +9 -6
  23. package/lib/instrumentation/langchain/callback-manager.js +25 -0
  24. package/lib/instrumentation/langchain/common.js +65 -0
  25. package/lib/instrumentation/langchain/nr-hooks.js +27 -0
  26. package/lib/instrumentation/langchain/runnable.js +124 -0
  27. package/lib/instrumentation/langchain/tools.js +69 -0
  28. package/lib/instrumentation/memcached.js +8 -4
  29. package/lib/instrumentation/mongodb/common.js +24 -17
  30. package/lib/instrumentation/mongodb/v2-mongo.js +4 -3
  31. package/lib/instrumentation/mongodb/v3-mongo.js +2 -1
  32. package/lib/instrumentation/mongodb/v4-mongo.js +2 -1
  33. package/lib/instrumentation/mysql/mysql.js +12 -9
  34. package/lib/instrumentation/openai.js +20 -31
  35. package/lib/instrumentation/pg.js +7 -6
  36. package/lib/instrumentation/redis.js +10 -6
  37. package/lib/instrumentation/restify.js +50 -43
  38. package/lib/instrumentations.js +2 -1
  39. package/lib/llm-events/{openai/error-message.js → error-message.js} +5 -1
  40. package/lib/llm-events/event.js +7 -3
  41. package/lib/llm-events/{openai/feedback-message.js → feedback-message.js} +2 -4
  42. package/lib/llm-events/langchain/chat-completion-message.js +8 -7
  43. package/lib/llm-events/langchain/chat-completion-summary.js +0 -15
  44. package/lib/llm-events/langchain/event.js +10 -4
  45. package/lib/llm-events/langchain/index.js +2 -1
  46. package/lib/llm-events/langchain/tool.js +24 -0
  47. package/lib/llm-events/openai/chat-completion-message.js +0 -1
  48. package/lib/llm-events/openai/chat-completion-summary.js +0 -1
  49. package/lib/llm-events/openai/event.js +1 -1
  50. package/lib/llm-events/openai/index.js +2 -4
  51. package/lib/metrics/names.js +13 -2
  52. package/lib/shim/datastore-shim.js +73 -76
  53. package/lib/shim/shim.js +3 -2
  54. package/lib/shim/specs/class.js +10 -4
  55. package/lib/shim/specs/index.js +17 -24
  56. package/lib/shim/specs/message-subscribe.js +1 -1
  57. package/lib/shim/specs/message.js +3 -3
  58. package/lib/shim/specs/middleware-mounter.js +9 -3
  59. package/lib/shim/specs/middleware.js +2 -1
  60. package/lib/shim/specs/operation.js +8 -17
  61. package/lib/shim/specs/params/datastore.js +40 -0
  62. package/lib/shim/specs/params/queue-message.js +31 -0
  63. package/lib/shim/specs/query.js +8 -2
  64. package/lib/shim/specs/recorder.js +5 -1
  65. package/lib/shim/specs/render.js +4 -3
  66. package/lib/shim/specs/transaction.js +9 -3
  67. package/lib/shim/specs/wrap.js +9 -3
  68. package/lib/shim/webframework-shim/middleware-mounter.js +2 -5
  69. package/lib/shimmer.js +1 -1
  70. package/lib/symbols.js +1 -0
  71. package/lib/transaction/index.js +0 -5
  72. package/package.json +3 -3
  73. package/lib/llm-events/tracked-ids.js +0 -27
package/NEWS.md CHANGED
@@ -1,23 +1,66 @@
1
- ### v11.10.4 (2024-02-13)
2
-
3
- #### Bug fixes
4
-
5
- * Resolved application logs getting blocked when an excessive payload is encountered ([#2013](https://github.com/newrelic/node-newrelic/pull/2013)) ([365ded4](https://github.com/newrelic/node-newrelic/commit/365ded432b7781ee9c896bf0e067dac8cc2c45cc))
6
- * Updated Shim to properly calculate the `_moduleRoot` on windows environments ([#2014](https://github.com/newrelic/node-newrelic/pull/2014)) ([ab0bd7f](https://github.com/newrelic/node-newrelic/commit/ab0bd7f87a5ed6ea38f51f068a2fc066af8f8d74))
7
-
8
- #### Code refactoring
9
-
10
- * Abstracted registering of new aggregators into a Harvester class that is responsible for starting, stopping, updating all registered aggregators. ([#1994](https://github.com/newrelic/node-newrelic/pull/1994)) ([1fb85a6](https://github.com/newrelic/node-newrelic/commit/1fb85a6f97c522ce2951911c670fcbddaa218049))
11
- * Refactored specs into classes for easier code navigation ([#2004](https://github.com/newrelic/node-newrelic/pull/2004)) ([4daedc0](https://github.com/newrelic/node-newrelic/commit/4daedc08c707bec22056466ef15a45b50f20026f))
12
-
13
- #### Miscellaneous chores
14
-
15
- * **deps:** Updated @newrelic/security agent to v1.0.1 ([#2002](https://github.com/newrelic/node-newrelic/pull/2002)) ([b460c7b](https://github.com/newrelic/node-newrelic/commit/b460c7be589dd6fa801285b756bf66f62e0f10aa))
16
-
17
- #### Tests
18
-
19
- * Updated smoke tests to send data to the appropriate collector method ([#2005](https://github.com/newrelic/node-newrelic/pull/2005)) ([6130486](https://github.com/newrelic/node-newrelic/commit/6130486514268b02f68dccceb9b1e29d1e99c78e))
20
-
1
+ ### v11.11.0 (2024-02-27)
2
+
3
+ #### Features
4
+
5
+ * Added instrumentation for RunnableSequence ([#1996](https://github.com/newrelic/node-newrelic/pull/1996)) ([71ffa37](https://github.com/newrelic/node-newrelic/commit/71ffa373e01d27be4d3ad40464facc8a33f4aeb2))
6
+
7
+ * Added LangChain error events capture ([#2040](https://github.com/newrelic/node-newrelic/pull/2040)) ([4d0d839](https://github.com/newrelic/node-newrelic/commit/4d0d8396ac3c19dee9d14477d8b408efaae3c24f))
8
+
9
+ * Added `ai_monitoring.streaming.enabled`. When set to `false` this will not instrument chat completion streams, thus it will not create relevant Llm events. ([#2021](https://github.com/newrelic/node-newrelic/pull/2021)) ([ff78b51](https://github.com/newrelic/node-newrelic/commit/ff78b514d0afe8127a094ce810f164b08768bcac))
10
+ * Added ability to recordLlmFeedbackEvent by traceId ([#2043](https://github.com/newrelic/node-newrelic/pull/2043)) ([b0a4ed1](https://github.com/newrelic/node-newrelic/commit/b0a4ed10ad7d6e021727d6d5e4746292e7a34ea1))
11
+ * Added instrumentation for langchain tools. ([#2009](https://github.com/newrelic/node-newrelic/pull/2009)) ([695d10e](https://github.com/newrelic/node-newrelic/commit/695d10e28ee6cbeba252299d7d94c9660137d293))
12
+
13
+ #### Code refactoring
14
+
15
+ * Updated AIM instrumentation ([#2015](https://github.com/newrelic/node-newrelic/pull/2015)) ([d37d2a8](https://github.com/newrelic/node-newrelic/commit/d37d2a88a4754c23ee039955c5839d8b7d35f875))
16
+ * removed capturing last 4 of api key
17
+ * included all custom attributes prefixed with `llm.` as attributes on all Llm events
18
+ * changed tracking metric to start with Supportability
19
+
20
+ * Updated capturing conversation_id on Llm Events as `llm.conversation_id` ([#2020](https://github.com/newrelic/node-newrelic/pull/2020)) ([5f93f65](https://github.com/newrelic/node-newrelic/commit/5f93f6571eeb38740d8f3cb59f7706d9cb07c67a))
21
+ * Updated instrumentation to construct specs at source instead of within the shim methods ([#2035](https://github.com/newrelic/node-newrelic/pull/2035)) ([ead8c25](https://github.com/newrelic/node-newrelic/commit/ead8c25e851d49b199cf808529e6483b2a3f024d))
22
+ * Simplified the logic in `shim.recordQuery` and `shim.recordOperation` to reduce merging of spec properties and rely on the constructed spec
23
+
24
+
25
+ #### Documentation
26
+
27
+ * Added note about using sudo for firewall script ([#2032](https://github.com/newrelic/node-newrelic/pull/2032)) ([bf106d2](https://github.com/newrelic/node-newrelic/commit/bf106d2a8a84d86443765a27d031233993cbd788))
28
+
29
+ * Fixed spec objects parameter definitions ([#2024](https://github.com/newrelic/node-newrelic/pull/2024)) ([4378173](https://github.com/newrelic/node-newrelic/commit/4378173b19cd1a7c92c38d6d9d7c6ad22d823fe5))
30
+
31
+
32
+ #### Miscellaneous chores
33
+
34
+ * Added missing is_response to LangChain completion messages ([#2044](https://github.com/newrelic/node-newrelic/pull/2044)) ([20c7d47](https://github.com/newrelic/node-newrelic/commit/20c7d473e318d50854ab8fefcc92d0b7a3b95b64))
35
+
36
+ * Attached specs to the `Shim.prototype` for use in custom instrumentation and instrumentation outside of the agent ([#2038](https://github.com/newrelic/node-newrelic/pull/2038)) ([2c97488](https://github.com/newrelic/node-newrelic/commit/2c974887068b7cc522eb29dd781481bb1583bde7))
37
+ * **deps:** Updated to use @newrelic/ritm from require-in-the-middle ([#2034](https://github.com/newrelic/node-newrelic/pull/2034)) ([ffb729f](https://github.com/newrelic/node-newrelic/commit/ffb729f1e9389e7a3d495b09df913eb3b5b43c3f))
38
+ * Updated DatastoreParameters to include collection ([#2039](https://github.com/newrelic/node-newrelic/pull/2039)) ([b9c73ca](https://github.com/newrelic/node-newrelic/commit/b9c73ca482d13d26f2bf54c22cd3ab4f77f413ca))
39
+
40
+ #### Tests
41
+
42
+ * Cleaned up pending mocks in the log dropping test to avoid a console warning around pending mocks in after each ([#2017](https://github.com/newrelic/node-newrelic/pull/2017)) ([d2f40c2](https://github.com/newrelic/node-newrelic/commit/d2f40c2e67c5bff826d0234412eacdfff70a2fd7))
43
+
44
+ ### v11.10.4 (2024-02-13)
45
+
46
+ #### Bug fixes
47
+
48
+ * Resolved application logs getting blocked when an excessive payload is encountered ([#2013](https://github.com/newrelic/node-newrelic/pull/2013)) ([365ded4](https://github.com/newrelic/node-newrelic/commit/365ded432b7781ee9c896bf0e067dac8cc2c45cc))
49
+ * Updated Shim to properly calculate the `_moduleRoot` on windows environments ([#2014](https://github.com/newrelic/node-newrelic/pull/2014)) ([ab0bd7f](https://github.com/newrelic/node-newrelic/commit/ab0bd7f87a5ed6ea38f51f068a2fc066af8f8d74))
50
+
51
+ #### Code refactoring
52
+
53
+ * Abstracted registering of new aggregators into a Harvester class that is responsible for starting, stopping, updating all registered aggregators. ([#1994](https://github.com/newrelic/node-newrelic/pull/1994)) ([1fb85a6](https://github.com/newrelic/node-newrelic/commit/1fb85a6f97c522ce2951911c670fcbddaa218049))
54
+ * Refactored specs into classes for easier code navigation ([#2004](https://github.com/newrelic/node-newrelic/pull/2004)) ([4daedc0](https://github.com/newrelic/node-newrelic/commit/4daedc08c707bec22056466ef15a45b50f20026f))
55
+
56
+ #### Miscellaneous chores
57
+
58
+ * **deps:** Updated @newrelic/security agent to v1.0.1 ([#2002](https://github.com/newrelic/node-newrelic/pull/2002)) ([b460c7b](https://github.com/newrelic/node-newrelic/commit/b460c7be589dd6fa801285b756bf66f62e0f10aa))
59
+
60
+ #### Tests
61
+
62
+ * Updated smoke tests to send data to the appropriate collector method ([#2005](https://github.com/newrelic/node-newrelic/pull/2005)) ([6130486](https://github.com/newrelic/node-newrelic/commit/6130486514268b02f68dccceb9b1e29d1e99c78e))
63
+
21
64
  ### v11.10.3 (2024-02-07)
22
65
 
23
66
  #### Features
@@ -18,6 +18,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
18
18
  * [@grpc/proto-loader](#grpcproto-loader)
19
19
  * [@newrelic/aws-sdk](#newrelicaws-sdk)
20
20
  * [@newrelic/koa](#newrelickoa)
21
+ * [@newrelic/ritm](#newrelicritm)
21
22
  * [@newrelic/security-agent](#newrelicsecurity-agent)
22
23
  * [@newrelic/superagent](#newrelicsuperagent)
23
24
  * [@tyriar/fibonacci-heap](#tyriarfibonacci-heap)
@@ -28,7 +29,6 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic
28
29
  * [json-stringify-safe](#json-stringify-safe)
29
30
  * [module-details-from-path](#module-details-from-path)
30
31
  * [readable-stream](#readable-stream)
31
- * [require-in-the-middle](#require-in-the-middle)
32
32
  * [semver](#semver)
33
33
  * [winston-transport](#winston-transport)
34
34
 
@@ -919,6 +919,36 @@ Apache License
919
919
 
920
920
  ```
921
921
 
922
+ ### @newrelic/ritm
923
+
924
+ This product includes source derived from [@newrelic/ritm](https://github.com/newrelic-forks/require-in-the-middle) ([v7.2.0](https://github.com/newrelic-forks/require-in-the-middle/tree/v7.2.0)), distributed under the [MIT License](https://github.com/newrelic-forks/require-in-the-middle/blob/v7.2.0/LICENSE):
925
+
926
+ ```
927
+ The MIT License (MIT)
928
+
929
+ Copyright (c) 2016-2019, Thomas Watson Steen
930
+ Copyright (c) 2019-2023, Elasticsearch B.V.
931
+
932
+ Permission is hereby granted, free of charge, to any person obtaining a copy
933
+ of this software and associated documentation files (the "Software"), to deal
934
+ in the Software without restriction, including without limitation the rights
935
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
936
+ copies of the Software, and to permit persons to whom the Software is
937
+ furnished to do so, subject to the following conditions:
938
+
939
+ The above copyright notice and this permission notice shall be included in all
940
+ copies or substantial portions of the Software.
941
+
942
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
943
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
944
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
945
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
946
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
947
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
948
+ SOFTWARE.
949
+
950
+ ```
951
+
922
952
  ### @newrelic/security-agent
923
953
 
924
954
  This product includes source derived from [@newrelic/security-agent](https://github.com/newrelic/csec-node-agent) ([v1.0.1](https://github.com/newrelic/csec-node-agent/tree/v1.0.1)), distributed under the [UNKNOWN License](https://github.com/newrelic/csec-node-agent/blob/v1.0.1/LICENSE):
@@ -1406,36 +1436,6 @@ IN THE SOFTWARE.
1406
1436
 
1407
1437
  ```
1408
1438
 
1409
- ### require-in-the-middle
1410
-
1411
- This product includes source derived from [require-in-the-middle](https://github.com/elastic/require-in-the-middle) ([v7.2.0](https://github.com/elastic/require-in-the-middle/tree/v7.2.0)), distributed under the [MIT License](https://github.com/elastic/require-in-the-middle/blob/v7.2.0/LICENSE):
1412
-
1413
- ```
1414
- The MIT License (MIT)
1415
-
1416
- Copyright (c) 2016-2019, Thomas Watson Steen
1417
- Copyright (c) 2019-2023, Elasticsearch B.V.
1418
-
1419
- Permission is hereby granted, free of charge, to any person obtaining a copy
1420
- of this software and associated documentation files (the "Software"), to deal
1421
- in the Software without restriction, including without limitation the rights
1422
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1423
- copies of the Software, and to permit persons to whom the Software is
1424
- furnished to do so, subject to the following conditions:
1425
-
1426
- The above copyright notice and this permission notice shall be included in all
1427
- copies or substantial portions of the Software.
1428
-
1429
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1430
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1431
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1432
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1433
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1434
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1435
- SOFTWARE.
1436
-
1437
- ```
1438
-
1439
1439
  ### semver
1440
1440
 
1441
1441
  This product includes source derived from [semver](https://github.com/npm/node-semver) ([v7.6.0](https://github.com/npm/node-semver/tree/v7.6.0)), distributed under the [ISC License](https://github.com/npm/node-semver/blob/v7.6.0/LICENSE):
@@ -2426,7 +2426,7 @@ THE SOFTWARE.
2426
2426
 
2427
2427
  ### eslint-plugin-jsdoc
2428
2428
 
2429
- This product includes source derived from [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) ([v48.0.5](https://github.com/gajus/eslint-plugin-jsdoc/tree/v48.0.5)), distributed under the [BSD-3-Clause License](https://github.com/gajus/eslint-plugin-jsdoc/blob/v48.0.5/LICENSE):
2429
+ This product includes source derived from [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) ([v48.0.6](https://github.com/gajus/eslint-plugin-jsdoc/tree/v48.0.6)), distributed under the [BSD-3-Clause License](https://github.com/gajus/eslint-plugin-jsdoc/blob/v48.0.6/LICENSE):
2430
2430
 
2431
2431
  ```
2432
2432
  Copyright (c) 2018, Gajus Kuizinas (http://gajus.com/)
package/api.js CHANGED
@@ -23,7 +23,7 @@ const {
23
23
  assignCLMSymbol,
24
24
  addCLMAttributes: maybeAddCLMAttributes
25
25
  } = require('./lib/util/code-level-metrics')
26
- const { LlmFeedbackMessage } = require('./lib/llm-events/openai')
26
+ const LlmFeedbackMessage = require('./lib/llm-events/feedback-message')
27
27
 
28
28
  const ATTR_DEST = require('./lib/config/attribute-filter').DESTINATIONS
29
29
  const MODULE_TYPE = require('./lib/shim/constants').MODULE_TYPE
@@ -617,7 +617,7 @@ API.prototype.addIgnoringRule = function addIgnoringRule(pattern) {
617
617
  * @private
618
618
  * @see RUM_ISSUES
619
619
  * @param {number} errorCode Error code from `RUM_ISSUES`.
620
- * @param {boolean} [quiet=false] Be quiet about this failure.
620
+ * @param {boolean} [quiet] Be quiet about this failure.
621
621
  * @returns {string} HTML comment for debugging purposes with specific error code
622
622
  */
623
623
  function _gracefail(errorCode, quiet) {
@@ -1541,52 +1541,20 @@ API.prototype.getTraceMetadata = function getTraceMetadata() {
1541
1541
  return metadata
1542
1542
  }
1543
1543
 
1544
- /**
1545
- * Get a set of tracked identifiers
1546
- *
1547
- * @param {object} params Input parameters.
1548
- * @param {string} params.responseId The LLM generated identifier for the
1549
- * response.
1550
- * @returns {LlmTrackedIds|undefined} The tracked identifiers.
1551
- */
1552
- API.prototype.getLlmMessageIds = function getLlmMessageIds({ responseId } = {}) {
1553
- this.agent.metrics
1554
- .getOrCreateMetric(`${NAMES.SUPPORTABILITY.API}/getLlmMessageIds`)
1555
- .incrementCallCount()
1556
-
1557
- if (this.agent.config?.ai_monitoring?.enabled !== true) {
1558
- logger.warn('getLlmMessageIds invoked but ai_monitoring is disabled.')
1559
- return
1560
- }
1561
-
1562
- const tx = this.agent.tracer.getTransaction()
1563
- if (!tx) {
1564
- logger.warn('getLlmMessageIds must be called within the scope of a transaction.')
1565
- return
1566
- }
1567
- return tx.llm.responses.get(responseId)
1568
- }
1569
-
1570
1544
  /**
1571
1545
  * Record a LLM feedback event which can be viewed in New Relic API Monitoring.
1572
1546
  *
1573
1547
  * @param {object} params Input parameters.
1574
- * @param {string} [params.conversationId=""] If available, the unique
1575
- * identifier for the LLM conversation that triggered the event.
1576
- * @param {string} [params.requestId=""] If available, the request identifier
1577
- * from the remote service.
1578
- * @param {string} params.messageId Identifier for the message being rated.
1579
- * Obtained from {@link getLlmMessageIds}.
1548
+ * @param {string} params.traceId Identifier for the feedback event.
1549
+ * Obtained from {@link getTraceMetadata}.
1580
1550
  * @param {string} params.category A tag for the event.
1581
1551
  * @param {string} params.rating A indicator of how useful the message was.
1582
- * @param {string} [params.message=""] The message that triggered the event.
1583
- * @param {object} [params.metadata={}] Additional key-value pairs to associate
1552
+ * @param {string} [params.message] The message that triggered the event.
1553
+ * @param {object} [params.metadata] Additional key-value pairs to associate
1584
1554
  * with the recorded event.
1585
1555
  */
1586
1556
  API.prototype.recordLlmFeedbackEvent = function recordLlmFeedbackEvent({
1587
- conversationId = '',
1588
- requestId = '',
1589
- messageId,
1557
+ traceId,
1590
1558
  category,
1591
1559
  rating,
1592
1560
  message = '',
@@ -1596,6 +1564,13 @@ API.prototype.recordLlmFeedbackEvent = function recordLlmFeedbackEvent({
1596
1564
  .getOrCreateMetric(`${NAMES.SUPPORTABILITY.API}/recordLlmFeedbackEvent`)
1597
1565
  .incrementCallCount()
1598
1566
 
1567
+ if (!traceId) {
1568
+ logger.warn(
1569
+ 'A feedback event will not be recorded. recordLlmFeedbackEvent must be called with a traceId.'
1570
+ )
1571
+ return
1572
+ }
1573
+
1599
1574
  if (this.agent.config?.ai_monitoring?.enabled !== true) {
1600
1575
  logger.warn('recordLlmFeedbackEvent invoked but ai_monitoring is disabled.')
1601
1576
  return
@@ -1604,15 +1579,13 @@ API.prototype.recordLlmFeedbackEvent = function recordLlmFeedbackEvent({
1604
1579
  const tx = this.agent.tracer.getTransaction()
1605
1580
  if (!tx) {
1606
1581
  logger.warn(
1607
- 'No message feedback events will be recorded. recordLlmFeedbackEvent must be called within the scope of a transaction.'
1582
+ 'A feedback events will not be recorded. recordLlmFeedbackEvent must be called within the scope of a transaction.'
1608
1583
  )
1609
1584
  return
1610
1585
  }
1611
1586
 
1612
1587
  const feedback = new LlmFeedbackMessage({
1613
- conversationId,
1614
- requestId,
1615
- messageId,
1588
+ traceId,
1616
1589
  category,
1617
1590
  rating,
1618
1591
  message
@@ -1625,12 +1598,12 @@ API.prototype.recordLlmFeedbackEvent = function recordLlmFeedbackEvent({
1625
1598
  *
1626
1599
  * @param {object} [options]
1627
1600
  * Object with shut down options.
1628
- * @param {boolean} [options.collectPendingData=false]
1601
+ * @param {boolean} [options.collectPendingData]
1629
1602
  * If true, the agent will send any pending data to the collector before
1630
1603
  * shutting down.
1631
- * @param {number} [options.timeout=0]
1604
+ * @param {number} [options.timeout]
1632
1605
  * Time in milliseconds to wait before shutting down.
1633
- * @param {boolean} [options.waitForIdle=false]
1606
+ * @param {boolean} [options.waitForIdle]
1634
1607
  * If true, the agent will not shut down until there are no active transactions.
1635
1608
  * @param {Function} [cb]
1636
1609
  * Callback function that runs when agent stops.
@@ -1675,12 +1648,12 @@ function _logErrorCallback(error, phase) {
1675
1648
  * @private
1676
1649
  * @param {object} api instantiation of this file
1677
1650
  * @param {object} options shutdown options object
1678
- * @param {boolean} [options.collectPendingData=false]
1651
+ * @param {boolean} [options.collectPendingData]
1679
1652
  * If true, the agent will send any pending data to the collector before
1680
1653
  * shutting down.
1681
- * @param {number} [options.timeout=0]
1654
+ * @param {number} [options.timeout]
1682
1655
  * Time in milliseconds to wait before shutting down.
1683
- * @param {boolean} [options.waitForIdle=false]
1656
+ * @param {boolean} [options.waitForIdle]
1684
1657
  * If true, the agent will not shut down until there are no active transactions.
1685
1658
  * @param {Function} callback callback function to execute after shutdown process is complete (successful or not)
1686
1659
  */
@@ -1358,6 +1358,16 @@ defaultConfig.definition = () => ({
1358
1358
  enabled: {
1359
1359
  formatter: boolean,
1360
1360
  default: false
1361
+ },
1362
+ /**
1363
+ * Toggles the capturing of Llm events when using streaming
1364
+ * based methods in AIM supported libraries(i.e.- openai, AWS bedrock, langchain)
1365
+ */
1366
+ streaming: {
1367
+ enabled: {
1368
+ formatter: boolean,
1369
+ default: true
1370
+ }
1361
1371
  }
1362
1372
  }
1363
1373
  })
@@ -4,6 +4,8 @@
4
4
  */
5
5
 
6
6
  'use strict'
7
+
8
+ const { QuerySpec } = require('../../shim/specs')
7
9
  const semver = require('semver')
8
10
  const logger = require('../../logger').child({ component: 'ElasticSearch' })
9
11
  const { isNotEmpty } = require('../../util/objects')
@@ -33,14 +35,14 @@ module.exports = function initialize(_agent, elastic, _moduleName, shim) {
33
35
 
34
36
  shim.recordQuery(elastic.Transport.prototype, 'request', function wrapQuery(shim, _, __, args) {
35
37
  const ctx = this
36
- return {
38
+ return new QuerySpec({
37
39
  query: JSON.stringify(args?.[0]),
38
40
  promise: true,
39
41
  opaque: true,
40
42
  inContext: function inContext() {
41
43
  getConnection.call(ctx, shim)
42
44
  }
43
- }
45
+ })
44
46
  })
45
47
  }
46
48
 
@@ -5,6 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
+ const { MiddlewareSpec, SegmentSpec } = require('../../shim/specs')
8
9
  const record = require('../../metrics/recorders/generic')
9
10
  // This object defines all the events that we want to wrap extensions
10
11
  // for, as they are the only ones associated with requests.
@@ -208,23 +209,29 @@ function wrapPreHandlers(shim, container, path) {
208
209
 
209
210
  function wrapPreHandler(shim, container, path) {
210
211
  return shim.record(container, (shim) => {
211
- return { name: [shim.HAPI, ' pre handler: ', '(', path, ')'].join(''), recorder: record }
212
+ return new SegmentSpec({
213
+ name: [shim.HAPI, ' pre handler: ', '(', path, ')'].join(''),
214
+ recorder: record
215
+ })
212
216
  })
213
217
  }
214
218
 
215
219
  function wrapRouteHandler(shim, handler, path) {
216
- return shim.recordMiddleware(handler, {
217
- route: path,
218
- req: function getReq(shim, fn, fnName, args) {
219
- const [request] = args
220
- return request?.raw?.req
221
- },
222
- promise: true,
223
- params: function getParams(shim, fn, fnName, args) {
224
- const [req] = args
225
- return req?.params
226
- }
227
- })
220
+ return shim.recordMiddleware(
221
+ handler,
222
+ new MiddlewareSpec({
223
+ route: path,
224
+ req: function getReq(shim, fn, fnName, args) {
225
+ const [request] = args
226
+ return request?.raw?.req
227
+ },
228
+ promise: true,
229
+ params: function getParams(shim, fn, fnName, args) {
230
+ const [req] = args
231
+ return req?.params
232
+ }
233
+ })
234
+ )
228
235
  }
229
236
 
230
237
  function wrapMiddleware(shim, middleware, event) {
@@ -232,13 +239,16 @@ function wrapMiddleware(shim, middleware, event) {
232
239
  return middleware
233
240
  }
234
241
 
235
- return shim.recordMiddleware(middleware, {
236
- route: event,
237
- type: event === 'onPreResponse' ? shim.ERRORWARE : shim.MIDDLEWARE,
238
- promise: true,
239
- req: function getReq(_shim, _fn, _fnName, args) {
240
- const [req] = args
241
- return req?.raw?.req
242
- }
243
- })
242
+ return shim.recordMiddleware(
243
+ middleware,
244
+ new MiddlewareSpec({
245
+ route: event,
246
+ type: event === 'onPreResponse' ? shim.ERRORWARE : shim.MIDDLEWARE,
247
+ promise: true,
248
+ req: function getReq(_shim, _fn, _fnName, args) {
249
+ const [req] = args
250
+ return req?.raw?.req
251
+ }
252
+ })
253
+ )
244
254
  }
@@ -6,6 +6,7 @@
6
6
  'use strict'
7
7
 
8
8
  const semver = require('semver')
9
+ const { RenderSpec } = require('../../shim/specs')
9
10
 
10
11
  module.exports = function initialize(agent, vision, moduleName, shim) {
11
12
  const plugin = vision.plugin
@@ -36,7 +37,7 @@ function wrapDecorate(shim, decorate) {
36
37
  }
37
38
 
38
39
  const args = shim.argsToArray.apply(shim, arguments)
39
- args[2] = shim.recordRender(handler, { promise: true })
40
+ args[2] = shim.recordRender(handler, new RenderSpec({ promise: true }))
40
41
 
41
42
  return decorate.apply(this, args)
42
43
  }
@@ -4,6 +4,11 @@
4
4
  */
5
5
 
6
6
  'use strict'
7
+
8
+ const {
9
+ OperationSpec,
10
+ params: { DatastoreParameters }
11
+ } = require('../../shim/specs')
7
12
  const CLIENT_COMMANDS = ['select', 'quit', 'SELECT', 'QUIT']
8
13
  const opts = Symbol('clientOptions')
9
14
 
@@ -49,11 +54,11 @@ function instrumentClientCommand(shim, client, cmd) {
49
54
  }
50
55
  }
51
56
 
52
- return {
57
+ return new OperationSpec({
53
58
  name: (cmd && cmd.toLowerCase()) || 'other',
54
59
  parameters,
55
60
  promise: true
56
- }
61
+ })
57
62
  })
58
63
  }
59
64
 
@@ -64,11 +69,11 @@ function instrumentClientCommand(shim, client, cmd) {
64
69
  * @returns {object} params
65
70
  */
66
71
  function getRedisParams(clientOpts) {
67
- return {
72
+ return new DatastoreParameters({
68
73
  host: clientOpts?.socket?.host || 'localhost',
69
74
  port_path_or_id: clientOpts?.socket?.path || clientOpts?.socket?.port || '6379',
70
75
  database_name: clientOpts?.database || 0
71
- }
76
+ })
72
77
  }
73
78
 
74
79
  module.exports.getRedisParams = getRedisParams
@@ -5,6 +5,7 @@
5
5
 
6
6
  'use strict'
7
7
 
8
+ const { QuerySpec } = require('../../shim/specs')
8
9
  const { prismaConnection, prismaModelCall } = require('../../symbols')
9
10
  const { URL } = require('url')
10
11
  const logger = require('../../logger').child({ component: 'prisma' })
@@ -172,7 +173,7 @@ module.exports = async function initialize(_agent, prisma, _moduleName, shim) {
172
173
  function wrapExecuteRequest(shim, _executeRequest, _fnName, args) {
173
174
  const client = this
174
175
 
175
- return {
176
+ return new QuerySpec({
176
177
  promise: true,
177
178
  query: retrieveQuery(args, pkgVersion),
178
179
  /**
@@ -201,7 +202,7 @@ module.exports = async function initialize(_agent, prisma, _moduleName, shim) {
201
202
  )
202
203
  }
203
204
  }
204
- }
205
+ })
205
206
  }
206
207
  )
207
208
  }