@envelop/newrelic 4.1.0-alpha-c0cc559.0 → 4.1.0-alpha-e9434aa.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.
@@ -1,29 +1,31 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopNamespace(e) {
6
- if (e && e.__esModule) { return e; } else {
7
- var n = {};
8
- if (e) {
9
- Object.keys(e).forEach(function (k) {
10
- var d = Object.getOwnPropertyDescriptor(e, k);
11
- Object.defineProperty(n, k, d.get ? d : {
12
- enumerable: true,
13
- get: function () {
14
- return e[k];
15
- }
16
- });
17
- });
18
- }
19
- n['default'] = e;
20
- return n;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
21
7
  }
22
- }
23
-
24
- const core = require('@envelop/core');
25
- const graphql = require('graphql');
26
-
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useNewRelic = exports.defaultSkipError = void 0;
27
+ const core_1 = require("@envelop/core");
28
+ const graphql_1 = require("graphql");
27
29
  var AttributeName;
28
30
  (function (AttributeName) {
29
31
  AttributeName["COMPONENT_NAME"] = "Envelop_NewRelic_Plugin";
@@ -49,8 +51,9 @@ const DEFAULT_OPTIONS = {
49
51
  skipError: defaultSkipError,
50
52
  };
51
53
  function defaultSkipError(error) {
52
- return error.originalError instanceof core.EnvelopError;
54
+ return error.originalError instanceof core_1.EnvelopError;
53
55
  }
56
+ exports.defaultSkipError = defaultSkipError;
54
57
  const useNewRelic = (rawOptions) => {
55
58
  const options = {
56
59
  ...DEFAULT_OPTIONS,
@@ -58,8 +61,7 @@ const useNewRelic = (rawOptions) => {
58
61
  };
59
62
  options.isExecuteVariablesRegex = options.includeExecuteVariables instanceof RegExp;
60
63
  options.isResolverArgsRegex = options.includeResolverArgs instanceof RegExp;
61
- const instrumentationApi$ = new Promise(function (resolve) { resolve(_interopNamespace(require('newrelic'))); })
62
- .then(m => m.default || m)
64
+ const instrumentationApi$ = Promise.resolve().then(() => __importStar(require('newrelic'))).then(m => m.default || m)
63
65
  .then(({ shim }) => {
64
66
  shim.agent.metrics.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`).incrementCallCount();
65
67
  return shim;
@@ -76,16 +78,16 @@ const useNewRelic = (rawOptions) => {
76
78
  const transactionNameState = instrumentationApi.agent.tracer.getTransaction().nameState;
77
79
  const spanContext = instrumentationApi.agent.tracer.getSpanContext();
78
80
  const delimiter = transactionNameState.delimiter;
79
- const rootOperation = args.document.definitions.find(definitionNode => definitionNode.kind === graphql.Kind.OPERATION_DEFINITION);
81
+ const rootOperation = args.document.definitions.find(definitionNode => definitionNode.kind === graphql_1.Kind.OPERATION_DEFINITION);
80
82
  const operationType = rootOperation.operation;
81
- const document = graphql.print(args.document);
83
+ const document = (0, graphql_1.print)(args.document);
82
84
  const operationName = ((_a = options.extractOperationName) === null || _a === void 0 ? void 0 : _a.call(options, args.contextValue)) ||
83
85
  args.operationName ||
84
86
  ((_b = rootOperation.name) === null || _b === void 0 ? void 0 : _b.value) ||
85
87
  AttributeName.ANONYMOUS_OPERATION;
86
88
  let rootFields = null;
87
89
  if (options.rootFieldsNaming) {
88
- const fieldNodes = rootOperation.selectionSet.selections.filter(selectionNode => selectionNode.kind === graphql.Kind.FIELD);
90
+ const fieldNodes = rootOperation.selectionSet.selections.filter(selectionNode => selectionNode.kind === graphql_1.Kind.FIELD);
89
91
  rootFields = fieldNodes.map(fieldNode => fieldNode.name.value);
90
92
  }
91
93
  transactionNameState.setName(transactionNameState.prefix, transactionNameState.verb, delimiter, operationType + delimiter + operationName + (rootFields ? delimiter + rootFields.join('&') : ''));
@@ -152,7 +154,7 @@ const useNewRelic = (rawOptions) => {
152
154
  }
153
155
  }
154
156
  };
155
- if (core.isAsyncIterable(result)) {
157
+ if ((0, core_1.isAsyncIterable)(result)) {
156
158
  return {
157
159
  onNext: ({ result: singularResult }) => {
158
160
  sendResult(singularResult);
@@ -170,6 +172,7 @@ const useNewRelic = (rawOptions) => {
170
172
  },
171
173
  };
172
174
  };
175
+ exports.useNewRelic = useNewRelic;
173
176
  function flattenPath(fieldPath, delimiter = '/') {
174
177
  const pathArray = [];
175
178
  let thisPath = fieldPath;
@@ -189,6 +192,3 @@ function filterPropertiesByRegex(initialObject, pattern) {
189
192
  }
190
193
  return filteredObject;
191
194
  }
192
-
193
- exports.defaultSkipError = defaultSkipError;
194
- exports.useNewRelic = useNewRelic;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,6 +1,31 @@
1
- import { EnvelopError, isAsyncIterable } from '@envelop/core';
2
- import { Kind, print } from 'graphql';
3
-
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useNewRelic = exports.defaultSkipError = void 0;
27
+ const core_1 = require("@envelop/core");
28
+ const graphql_1 = require("graphql");
4
29
  var AttributeName;
5
30
  (function (AttributeName) {
6
31
  AttributeName["COMPONENT_NAME"] = "Envelop_NewRelic_Plugin";
@@ -26,8 +51,9 @@ const DEFAULT_OPTIONS = {
26
51
  skipError: defaultSkipError,
27
52
  };
28
53
  function defaultSkipError(error) {
29
- return error.originalError instanceof EnvelopError;
54
+ return error.originalError instanceof core_1.EnvelopError;
30
55
  }
56
+ exports.defaultSkipError = defaultSkipError;
31
57
  const useNewRelic = (rawOptions) => {
32
58
  const options = {
33
59
  ...DEFAULT_OPTIONS,
@@ -35,8 +61,7 @@ const useNewRelic = (rawOptions) => {
35
61
  };
36
62
  options.isExecuteVariablesRegex = options.includeExecuteVariables instanceof RegExp;
37
63
  options.isResolverArgsRegex = options.includeResolverArgs instanceof RegExp;
38
- const instrumentationApi$ = import('newrelic')
39
- .then(m => m.default || m)
64
+ const instrumentationApi$ = Promise.resolve().then(() => __importStar(require('newrelic'))).then(m => m.default || m)
40
65
  .then(({ shim }) => {
41
66
  shim.agent.metrics.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`).incrementCallCount();
42
67
  return shim;
@@ -53,16 +78,16 @@ const useNewRelic = (rawOptions) => {
53
78
  const transactionNameState = instrumentationApi.agent.tracer.getTransaction().nameState;
54
79
  const spanContext = instrumentationApi.agent.tracer.getSpanContext();
55
80
  const delimiter = transactionNameState.delimiter;
56
- const rootOperation = args.document.definitions.find(definitionNode => definitionNode.kind === Kind.OPERATION_DEFINITION);
81
+ const rootOperation = args.document.definitions.find(definitionNode => definitionNode.kind === graphql_1.Kind.OPERATION_DEFINITION);
57
82
  const operationType = rootOperation.operation;
58
- const document = print(args.document);
83
+ const document = (0, graphql_1.print)(args.document);
59
84
  const operationName = ((_a = options.extractOperationName) === null || _a === void 0 ? void 0 : _a.call(options, args.contextValue)) ||
60
85
  args.operationName ||
61
86
  ((_b = rootOperation.name) === null || _b === void 0 ? void 0 : _b.value) ||
62
87
  AttributeName.ANONYMOUS_OPERATION;
63
88
  let rootFields = null;
64
89
  if (options.rootFieldsNaming) {
65
- const fieldNodes = rootOperation.selectionSet.selections.filter(selectionNode => selectionNode.kind === Kind.FIELD);
90
+ const fieldNodes = rootOperation.selectionSet.selections.filter(selectionNode => selectionNode.kind === graphql_1.Kind.FIELD);
66
91
  rootFields = fieldNodes.map(fieldNode => fieldNode.name.value);
67
92
  }
68
93
  transactionNameState.setName(transactionNameState.prefix, transactionNameState.verb, delimiter, operationType + delimiter + operationName + (rootFields ? delimiter + rootFields.join('&') : ''));
@@ -129,7 +154,7 @@ const useNewRelic = (rawOptions) => {
129
154
  }
130
155
  }
131
156
  };
132
- if (isAsyncIterable(result)) {
157
+ if ((0, core_1.isAsyncIterable)(result)) {
133
158
  return {
134
159
  onNext: ({ result: singularResult }) => {
135
160
  sendResult(singularResult);
@@ -147,6 +172,7 @@ const useNewRelic = (rawOptions) => {
147
172
  },
148
173
  };
149
174
  };
175
+ exports.useNewRelic = useNewRelic;
150
176
  function flattenPath(fieldPath, delimiter = '/') {
151
177
  const pathArray = [];
152
178
  let thisPath = fieldPath;
@@ -166,5 +192,3 @@ function filterPropertiesByRegex(initialObject, pattern) {
166
192
  }
167
193
  return filteredObject;
168
194
  }
169
-
170
- export { defaultSkipError, useNewRelic };
package/package.json CHANGED
@@ -1,34 +1,56 @@
1
1
  {
2
2
  "name": "@envelop/newrelic",
3
- "version": "4.1.0-alpha-c0cc559.0",
3
+ "version": "4.1.0-alpha-e9434aa.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-c0cc559.0",
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
8
- "newrelic": "^7 || ^8.0.0"
6
+ "@envelop/core": "2.4.0-alpha-e9434aa.0",
7
+ "newrelic": "^7 || ^8.0.0",
8
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },
10
+ "dependencies": {},
10
11
  "repository": {
11
12
  "type": "git",
12
- "url": "https://github.com/dotansimha/envelop.git",
13
+ "url": "https://github.com/n1ru4l/envelop.git",
13
14
  "directory": "packages/plugins/newrelic"
14
15
  },
15
16
  "author": "Santino Puleio <santinopuleio@gmail.com>",
16
17
  "license": "MIT",
17
- "main": "index.js",
18
- "module": "index.mjs",
19
- "typings": "index.d.ts",
18
+ "main": "cjs/index.js",
19
+ "module": "esm/index.js",
20
+ "typings": "typings/index.d.ts",
20
21
  "typescript": {
21
- "definition": "index.d.ts"
22
+ "definition": "typings/index.d.ts"
22
23
  },
24
+ "type": "module",
23
25
  "exports": {
24
26
  ".": {
25
- "require": "./index.js",
26
- "import": "./index.mjs"
27
+ "require": {
28
+ "types": "./typings/index.d.ts",
29
+ "default": "./cjs/index.js"
30
+ },
31
+ "import": {
32
+ "types": "./typings/index.d.ts",
33
+ "default": "./esm/index.js"
34
+ },
35
+ "default": {
36
+ "types": "./typings/index.d.ts",
37
+ "default": "./esm/index.js"
38
+ }
27
39
  },
28
40
  "./*": {
29
- "require": "./*.js",
30
- "import": "./*.mjs"
41
+ "require": {
42
+ "types": "./typings/*.d.ts",
43
+ "default": "./cjs/*.js"
44
+ },
45
+ "import": {
46
+ "types": "./typings/*.d.ts",
47
+ "default": "./esm/*.js"
48
+ },
49
+ "default": {
50
+ "types": "./typings/*.d.ts",
51
+ "default": "./esm/*.js"
52
+ }
31
53
  },
32
54
  "./package.json": "./package.json"
33
55
  }
34
- }
56
+ }
@@ -18,4 +18,4 @@ export declare type UseNewRelicOptions = {
18
18
  skipError?: (error: GraphQLError) => boolean;
19
19
  };
20
20
  export declare function defaultSkipError(error: GraphQLError): boolean;
21
- export declare const useNewRelic: (rawOptions?: UseNewRelicOptions | undefined) => Plugin;
21
+ export declare const useNewRelic: (rawOptions?: UseNewRelicOptions) => Plugin;
package/README.md DELETED
@@ -1,106 +0,0 @@
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.