@envelop/newrelic 4.1.0-alpha-26c4ae2.0 → 4.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.
Files changed (2) hide show
  1. package/README.md +106 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ ## `@envelop/newrelic`
2
+
3
+ Instrument your GraphQL application with New Relic reporting.
4
+ Take advantage of Distributed tracing to monitor performance and errors whilst ultimately getting to the root cause of issues.
5
+
6
+ Below are some screenshots to show how tracking looks like in New Relic, in these examples all plugin options were set to `true`.
7
+
8
+ Error tracking, operation and resolver views:
9
+ ![newrelic_error_operation_screenshot](./error_operation.png)
10
+ ![newrelic_error_resolver_screenshot](./error_resolver.png)
11
+
12
+ Successful operation tracking, operation plus root-field and sub-field resolvers:
13
+ ![newrelic_successful_operation_screenshot](./success_operation.png)
14
+ ![newrelic_successful_root-field_resolver_screenshot](./success_rootfield_resolver.png)
15
+ ![newrelic_successful_sub-field_resolver_screenshot](./success_subfield_resolver.png)
16
+
17
+ ## Getting Started
18
+
19
+ 1. Install dependencies
20
+ 2. Configure the New Relic Agent
21
+ 3. Setup the New Relic Envelop plugin
22
+
23
+ ## Installation
24
+
25
+ This plugin expects the Node.js agent, [newrelic npm package](https://www.npmjs.com/package/newrelic), to be installed in your application.
26
+
27
+ ```
28
+ yarn add newrelic @envelop/newrelic
29
+ ```
30
+
31
+ ## Basic usage Example
32
+
33
+ ```ts
34
+ import { envelop } from '@envelop/core';
35
+ import { useNewRelic } from '@envelop/newrelic';
36
+
37
+ const getEnveloped = envelop({
38
+ plugins: [
39
+ // ... other plugins ...
40
+ useNewRelic({
41
+ includeOperationDocument: true, // default `false`. When set to `true`, includes the GraphQL document defining the operations and fragments
42
+ includeExecuteVariables: false, // default `false`. When set to `true`, includes all the operation variables with their values
43
+ includeRawResult: false, // default: `false`. When set to `true`, includes the execution result
44
+ trackResolvers: true, // default `false`. When set to `true`, track resolvers as segments to monitor their performance
45
+ includeResolverArgs: false, // default `false`. When set to `true`, includes all the arguments passed to resolvers with their values
46
+ rootFieldsNaming: true, // default `false`. When set to `true` append the names of operation root fields to the transaction name
47
+ skipError: error => { ... return true; }, // a function that allows you to skip reporting a given error to NewRelic. By default custom `EnvelopError`s will be skipped
48
+ extractOperationName: (context) => context.request.body.customOperationName, // Allows to set a custom operation name to be used as transaction name and attribute
49
+ }),
50
+ ],
51
+ });
52
+ ```
53
+
54
+ > Note: Transaction and segment/span timings may be affected by other plugins used. In order to get more accurate tracking, it is recommended to add the New Relic plugin last.
55
+
56
+ ## Advanced usage
57
+
58
+ The plugin allows you to keep control over the variables and arguments that are tracked in New Relic.
59
+ In addition to the basic `true/false` boolean value, `includeExecuteVariables` and `includeResolverArgs` also accept a RegEx pattern. This allows you to implement white and black listing of properties to be tracked in New Relic.
60
+
61
+ This is particularly useful if you have properties coming through variables and arguments that are useful for debugging, but you don't want to leak users' data (such as PII).
62
+ Below is a quick example of how you can use RegEx to set up white/black listing functionalities.
63
+
64
+ ```ts
65
+ useNewRelic({
66
+ includeExecuteVariables: /client|application/i, // whitelist, track only variables whose name contains "client" or "application" (e.g. clientName, applicationId, xApplicationId)
67
+ trackResolvers: true, // track resolvers, since we also want to track resolvers' arguments
68
+ includeResolverArgs: /^(?!name|email|password).*/i, // blacklist, track all arguments whose name does not match 'name', 'email' nor 'password'
69
+ }),
70
+ ```
71
+
72
+ Obviously, the ones above are just a couple of examples, but clearly you have endless options to use any RegEx pattern to filter the variables and arguments in the way that best work for you.
73
+
74
+ > Be aware that the only way to filter variables and arguments is to loop through them, so there is an O(_n_) cost when filtering, where _n_ is the number of variables sent to the operation (when tracking execute variables), or the number of arguments passed to resolvers (when tracking resolvers arguments).
75
+
76
+ ## Agent Configuration
77
+
78
+ For full details about New Relic Agent configuration, we recommend reading [New Relic's official Node.js agent configuration documentation](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration/).
79
+
80
+ The main methods to configure the New Relic Agent is through:
81
+
82
+ - The newrelic.js file [or]
83
+ - The environment variables
84
+
85
+ If you choose to use the newrelic.js file, then you need this file located in the root of your application. You can look [here](https://github.com/newrelic/node-newrelic/blob/main/newrelic.js) for a basic example of what this file can look like.
86
+
87
+ If you choose to configure the New Relic Agent through environment variables, then you can follow your preferred strategy to make sure the variables are set and available when your application starts.
88
+ The variables are the same you can set in newrelic.js file, you just need to know that they need to start with `NEW_RELIC_`, obviously, the variables name must be fully uppercase.
89
+
90
+ The two variables that are always required are:
91
+
92
+ | Description | newrelic.js | Environment variable |
93
+ | ---------------- | ---------------------------------------- | ----------------------------------------------- |
94
+ | Application name | `app_name: ['MyAppName']` | `NEW_RELIC_APP_NAME=MyAppName` |
95
+ | License key | `license_key: '40HexadecimalCharacters'` | `NEW_RELIC_LICENSE_KEY=40HexadecimalCharacters` |
96
+
97
+ Other variables that are popularly used are:
98
+
99
+ | Description | newrelic.js | Environment variable |
100
+ | --------------------------- | ---------------------------------------- | -------------------------------------------- |
101
+ | Enable distributed tracing | `distributed_tracing: { enabled: true }` | `NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true` |
102
+ | Logging level | `logging: { level: 'info' }` | `NEW_RELIC_LOG_LEVEL=info` |
103
+ | Capture all request headers | `allow_all_headers: true` | `NEW_RELIC_ALLOW_ALL_HEADERS=true` |
104
+ | Enable error collection | `error_collector: { enabled: true }` | `NEW_RELIC_ERROR_COLLECTOR_ENABLED=true` |
105
+
106
+ Finally, [here](https://github.com/newrelic/node-newrelic/blob/main/lib/config/default.js) is also a reference of all the configuration variables you can include in your newrelic.js file, or translate into the env variables equivalent.
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/newrelic",
3
- "version": "4.1.0-alpha-26c4ae2.0",
3
+ "version": "4.1.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-26c4ae2.0",
6
+ "@envelop/core": "^2.4.0",
7
7
  "newrelic": "^7 || ^8.0.0",
8
8
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },