@envelop/newrelic 5.0.0-alpha-d0d0776.0 → 5.0.0-alpha-ccec0fc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,8 +31,8 @@ yarn add newrelic @envelop/newrelic
31
31
  ## Basic usage Example
32
32
 
33
33
  ```ts
34
- import { envelop } from '@envelop/core';
35
- import { useNewRelic } from '@envelop/newrelic';
34
+ import { envelop } from '@envelop/core'
35
+ import { useNewRelic } from '@envelop/newrelic'
36
36
 
37
37
  const getEnveloped = envelop({
38
38
  plugins: [
@@ -44,11 +44,13 @@ const getEnveloped = envelop({
44
44
  trackResolvers: true, // default `false`. When set to `true`, track resolvers as segments to monitor their performance
45
45
  includeResolverArgs: false, // default `false`. When set to `true`, includes all the arguments passed to resolvers with their values
46
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
- });
47
+ skipError: error => {
48
+ return true // a function that allows you to skip reporting a given error to NewRelic. By default custom `EnvelopError`s will be skipped
49
+ },
50
+ extractOperationName: context => context.request.body.customOperationName // Allows to set a custom operation name to be used as transaction name and attribute
51
+ })
52
+ ]
53
+ })
52
54
  ```
53
55
 
54
56
  > 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.
@@ -1,28 +1,31 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const core = require('@envelop/core');
6
- const graphql = require('graphql');
7
-
8
- function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- const n = Object.create(null);
11
- if (e) {
12
- for (const k in e) {
13
- if (k !== 'default') {
14
- const d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () { return e[k]; }
18
- });
19
- }
20
- }
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
- n["default"] = e;
23
- return Object.freeze(n);
24
- }
25
-
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-tools/graphql");
26
29
  var AttributeName;
27
30
  (function (AttributeName) {
28
31
  AttributeName["COMPONENT_NAME"] = "Envelop_NewRelic_Plugin";
@@ -48,19 +51,21 @@ const DEFAULT_OPTIONS = {
48
51
  skipError: defaultSkipError,
49
52
  };
50
53
  function defaultSkipError(error) {
51
- return error.originalError instanceof core.EnvelopError;
54
+ return error.originalError instanceof core_1.EnvelopError;
52
55
  }
56
+ exports.defaultSkipError = defaultSkipError;
53
57
  const useNewRelic = (rawOptions) => {
54
58
  const options = {
55
59
  ...DEFAULT_OPTIONS,
56
- ...(rawOptions || {}),
60
+ ...rawOptions,
57
61
  };
58
62
  options.isExecuteVariablesRegex = options.includeExecuteVariables instanceof RegExp;
59
63
  options.isResolverArgsRegex = options.includeResolverArgs instanceof RegExp;
60
- const instrumentationApi$ = Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('newrelic')); })
61
- .then(m => m.default || m)
64
+ const instrumentationApi$ = Promise.resolve().then(() => __importStar(require('newrelic'))).then(m => m.default || m)
62
65
  .then(({ shim }) => {
63
- shim.agent.metrics.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`).incrementCallCount();
66
+ shim.agent.metrics
67
+ .getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`)
68
+ .incrementCallCount();
64
69
  return shim;
65
70
  });
66
71
  const logger$ = instrumentationApi$.then(({ logger }) => {
@@ -70,26 +75,28 @@ const useNewRelic = (rawOptions) => {
70
75
  });
71
76
  return {
72
77
  async onExecute({ args }) {
78
+ var _a, _b;
73
79
  const instrumentationApi = await instrumentationApi$;
74
80
  const transactionNameState = instrumentationApi.agent.tracer.getTransaction().nameState;
75
81
  const spanContext = instrumentationApi.agent.tracer.getSpanContext();
76
82
  const delimiter = transactionNameState.delimiter;
77
- const rootOperation = args.document.definitions.find(definitionNode => definitionNode.kind === graphql.Kind.OPERATION_DEFINITION);
83
+ const rootOperation = args.document.definitions.find(definitionNode => definitionNode.kind === graphql_1.Kind.OPERATION_DEFINITION);
78
84
  const operationType = rootOperation.operation;
79
- const document = graphql.print(args.document);
80
- const operationName = options.extractOperationName?.(args.contextValue) ||
85
+ const document = (0, graphql_1.print)(args.document);
86
+ const operationName = ((_a = options.extractOperationName) === null || _a === void 0 ? void 0 : _a.call(options, args.contextValue)) ||
81
87
  args.operationName ||
82
- rootOperation.name?.value ||
88
+ ((_b = rootOperation.name) === null || _b === void 0 ? void 0 : _b.value) ||
83
89
  AttributeName.ANONYMOUS_OPERATION;
84
90
  let rootFields = null;
85
91
  if (options.rootFieldsNaming) {
86
- const fieldNodes = rootOperation.selectionSet.selections.filter(selectionNode => selectionNode.kind === graphql.Kind.FIELD);
92
+ const fieldNodes = rootOperation.selectionSet.selections.filter(selectionNode => selectionNode.kind === graphql_1.Kind.FIELD);
87
93
  rootFields = fieldNodes.map(fieldNode => fieldNode.name.value);
88
94
  }
89
95
  transactionNameState.setName(transactionNameState.prefix, transactionNameState.verb, delimiter, operationType + delimiter + operationName + (rootFields ? delimiter + rootFields.join('&') : ''));
90
96
  spanContext.addCustomAttribute(AttributeName.EXECUTION_OPERATION_NAME, operationName);
91
97
  spanContext.addCustomAttribute(AttributeName.EXECUTION_OPERATION_TYPE, operationType);
92
- options.includeOperationDocument && spanContext.addCustomAttribute(AttributeName.EXECUTION_OPERATION_DOCUMENT, document);
98
+ options.includeOperationDocument &&
99
+ spanContext.addCustomAttribute(AttributeName.EXECUTION_OPERATION_DOCUMENT, document);
93
100
  if (options.includeExecuteVariables) {
94
101
  const rawVariables = args.variableValues || {};
95
102
  const executeVariablesToTrack = options.isExecuteVariablesRegex
@@ -136,6 +143,7 @@ const useNewRelic = (rawOptions) => {
136
143
  onResolverCalled,
137
144
  onExecuteDone({ result }) {
138
145
  const sendResult = (singularResult) => {
146
+ var _a;
139
147
  if (singularResult.data && options.includeRawResult) {
140
148
  spanContext.addCustomAttribute(AttributeName.EXECUTION_RESULT, JSON.stringify(singularResult));
141
149
  }
@@ -143,13 +151,13 @@ const useNewRelic = (rawOptions) => {
143
151
  const agent = instrumentationApi.agent;
144
152
  const transaction = instrumentationApi.tracer.getTransaction();
145
153
  for (const error of singularResult.errors) {
146
- if (options.skipError?.(error))
154
+ if ((_a = options.skipError) === null || _a === void 0 ? void 0 : _a.call(options, error))
147
155
  continue;
148
156
  agent.errors.add(transaction, JSON.stringify(error));
149
157
  }
150
158
  }
151
159
  };
152
- if (core.isAsyncIterable(result)) {
160
+ if ((0, core_1.isAsyncIterable)(result)) {
153
161
  return {
154
162
  onNext: ({ result: singularResult }) => {
155
163
  sendResult(singularResult);
@@ -167,6 +175,7 @@ const useNewRelic = (rawOptions) => {
167
175
  },
168
176
  };
169
177
  };
178
+ exports.useNewRelic = useNewRelic;
170
179
  function flattenPath(fieldPath, delimiter = '/') {
171
180
  const pathArray = [];
172
181
  let thisPath = fieldPath;
@@ -186,6 +195,3 @@ function filterPropertiesByRegex(initialObject, pattern) {
186
195
  }
187
196
  return filteredObject;
188
197
  }
189
-
190
- exports.defaultSkipError = defaultSkipError;
191
- exports.useNewRelic = useNewRelic;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,6 +1,5 @@
1
- import { EnvelopError, isAsyncIterable } from '@envelop/core';
2
- import { Kind, print } from 'graphql';
3
-
1
+ import { isAsyncIterable, EnvelopError } from '@envelop/core';
2
+ import { print, Kind } from '@graphql-tools/graphql';
4
3
  var AttributeName;
5
4
  (function (AttributeName) {
6
5
  AttributeName["COMPONENT_NAME"] = "Envelop_NewRelic_Plugin";
@@ -25,20 +24,22 @@ const DEFAULT_OPTIONS = {
25
24
  rootFieldsNaming: false,
26
25
  skipError: defaultSkipError,
27
26
  };
28
- function defaultSkipError(error) {
27
+ export function defaultSkipError(error) {
29
28
  return error.originalError instanceof EnvelopError;
30
29
  }
31
- const useNewRelic = (rawOptions) => {
30
+ export const useNewRelic = (rawOptions) => {
32
31
  const options = {
33
32
  ...DEFAULT_OPTIONS,
34
- ...(rawOptions || {}),
33
+ ...rawOptions,
35
34
  };
36
35
  options.isExecuteVariablesRegex = options.includeExecuteVariables instanceof RegExp;
37
36
  options.isResolverArgsRegex = options.includeResolverArgs instanceof RegExp;
38
37
  const instrumentationApi$ = import('newrelic')
39
38
  .then(m => m.default || m)
40
39
  .then(({ shim }) => {
41
- shim.agent.metrics.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`).incrementCallCount();
40
+ shim.agent.metrics
41
+ .getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`)
42
+ .incrementCallCount();
42
43
  return shim;
43
44
  });
44
45
  const logger$ = instrumentationApi$.then(({ logger }) => {
@@ -48,6 +49,7 @@ const useNewRelic = (rawOptions) => {
48
49
  });
49
50
  return {
50
51
  async onExecute({ args }) {
52
+ var _a, _b;
51
53
  const instrumentationApi = await instrumentationApi$;
52
54
  const transactionNameState = instrumentationApi.agent.tracer.getTransaction().nameState;
53
55
  const spanContext = instrumentationApi.agent.tracer.getSpanContext();
@@ -55,9 +57,9 @@ const useNewRelic = (rawOptions) => {
55
57
  const rootOperation = args.document.definitions.find(definitionNode => definitionNode.kind === Kind.OPERATION_DEFINITION);
56
58
  const operationType = rootOperation.operation;
57
59
  const document = print(args.document);
58
- const operationName = options.extractOperationName?.(args.contextValue) ||
60
+ const operationName = ((_a = options.extractOperationName) === null || _a === void 0 ? void 0 : _a.call(options, args.contextValue)) ||
59
61
  args.operationName ||
60
- rootOperation.name?.value ||
62
+ ((_b = rootOperation.name) === null || _b === void 0 ? void 0 : _b.value) ||
61
63
  AttributeName.ANONYMOUS_OPERATION;
62
64
  let rootFields = null;
63
65
  if (options.rootFieldsNaming) {
@@ -67,7 +69,8 @@ const useNewRelic = (rawOptions) => {
67
69
  transactionNameState.setName(transactionNameState.prefix, transactionNameState.verb, delimiter, operationType + delimiter + operationName + (rootFields ? delimiter + rootFields.join('&') : ''));
68
70
  spanContext.addCustomAttribute(AttributeName.EXECUTION_OPERATION_NAME, operationName);
69
71
  spanContext.addCustomAttribute(AttributeName.EXECUTION_OPERATION_TYPE, operationType);
70
- options.includeOperationDocument && spanContext.addCustomAttribute(AttributeName.EXECUTION_OPERATION_DOCUMENT, document);
72
+ options.includeOperationDocument &&
73
+ spanContext.addCustomAttribute(AttributeName.EXECUTION_OPERATION_DOCUMENT, document);
71
74
  if (options.includeExecuteVariables) {
72
75
  const rawVariables = args.variableValues || {};
73
76
  const executeVariablesToTrack = options.isExecuteVariablesRegex
@@ -114,6 +117,7 @@ const useNewRelic = (rawOptions) => {
114
117
  onResolverCalled,
115
118
  onExecuteDone({ result }) {
116
119
  const sendResult = (singularResult) => {
120
+ var _a;
117
121
  if (singularResult.data && options.includeRawResult) {
118
122
  spanContext.addCustomAttribute(AttributeName.EXECUTION_RESULT, JSON.stringify(singularResult));
119
123
  }
@@ -121,7 +125,7 @@ const useNewRelic = (rawOptions) => {
121
125
  const agent = instrumentationApi.agent;
122
126
  const transaction = instrumentationApi.tracer.getTransaction();
123
127
  for (const error of singularResult.errors) {
124
- if (options.skipError?.(error))
128
+ if ((_a = options.skipError) === null || _a === void 0 ? void 0 : _a.call(options, error))
125
129
  continue;
126
130
  agent.errors.add(transaction, JSON.stringify(error));
127
131
  }
@@ -164,5 +168,3 @@ function filterPropertiesByRegex(initialObject, pattern) {
164
168
  }
165
169
  return filteredObject;
166
170
  }
167
-
168
- export { defaultSkipError, useNewRelic };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@envelop/newrelic",
3
- "version": "5.0.0-alpha-d0d0776.0",
3
+ "version": "5.0.0-alpha-ccec0fc.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "3.0.0-alpha-d0d0776.0",
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
8
- "newrelic": "^7 || ^8.0.0"
6
+ "@envelop/core": "3.0.0-alpha-ccec0fc.0",
7
+ "newrelic": "^7 || ^8.0.0",
8
+ "@graphql-tools/graphql": "0.1.0-alpha-e7752ba5.0"
9
9
  },
10
+ "dependencies": {},
10
11
  "repository": {
11
12
  "type": "git",
12
13
  "url": "https://github.com/n1ru4l/envelop.git",
@@ -14,33 +15,42 @@
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
27
  "require": {
26
- "default": "./index.js",
27
- "types": "./index.d.ts"
28
+ "types": "./typings/index.d.ts",
29
+ "default": "./cjs/index.js"
28
30
  },
29
31
  "import": {
30
- "default": "./index.mjs",
31
- "types": "./index.d.ts"
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"
32
38
  }
33
39
  },
34
40
  "./*": {
35
41
  "require": {
36
- "default": "./*.js",
37
- "types": "./*.d.ts"
42
+ "types": "./typings/*.d.ts",
43
+ "default": "./cjs/*.js"
38
44
  },
39
45
  "import": {
40
- "default": "./*.mjs",
41
- "types": "./*.d.ts"
46
+ "types": "./typings/*.d.ts",
47
+ "default": "./esm/*.js"
48
+ },
49
+ "default": {
50
+ "types": "./typings/*.d.ts",
51
+ "default": "./esm/*.js"
42
52
  }
43
53
  },
44
54
  "./package.json": "./package.json"
45
55
  }
46
- }
56
+ }
@@ -1,5 +1,5 @@
1
1
  import { Plugin, DefaultContext } from '@envelop/core';
2
- import { GraphQLError } from 'graphql';
2
+ import { GraphQLError } from '@graphql-tools/graphql';
3
3
  export declare type UseNewRelicOptions = {
4
4
  includeOperationDocument?: boolean;
5
5
  includeExecuteVariables?: boolean | RegExp;
@@ -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;