@envelop/newrelic 1.1.0 → 1.3.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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin } from '@envelop/types';
1
+ import { Plugin } from '@envelop/core';
2
2
  export declare type UseNewRelicOptions = {
3
3
  includeOperationDocument?: boolean;
4
4
  includeExecuteVariables?: boolean | RegExp;
@@ -7,5 +7,11 @@ export declare type UseNewRelicOptions = {
7
7
  includeResolverArgs?: boolean | RegExp;
8
8
  rootFieldsNaming?: boolean;
9
9
  operationNameProperty?: string;
10
+ /**
11
+ * Indicates whether or not to skip Sentry exception reporting for a given error.
12
+ * By default, this plugin skips all `EnvelopError` errors and does not report it to Sentry.
13
+ */
14
+ skipError?: (args: Error) => boolean;
10
15
  };
16
+ export declare function defaultSkipError(error: Error): boolean;
11
17
  export declare const useNewRelic: (rawOptions?: UseNewRelicOptions | undefined) => Plugin;
package/index.js CHANGED
@@ -5,20 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
7
  const newRelic = _interopDefault(require('newrelic'));
8
+ const core = require('@envelop/core');
8
9
  const graphql = require('graphql');
9
10
 
10
- /**
11
- * Returns true if the provided object implements the AsyncIterator protocol via
12
- * implementing a `Symbol.asyncIterator` method.
13
- *
14
- * Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
15
- */
16
- function isAsyncIterable(maybeAsyncIterable) {
17
- return (maybeAsyncIterable != null &&
18
- typeof maybeAsyncIterable === 'object' &&
19
- typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
20
- }
21
-
22
11
  const { shim: instrumentationApi } = newRelic;
23
12
  var AttributeName;
24
13
  (function (AttributeName) {
@@ -43,7 +32,11 @@ const DEFAULT_OPTIONS = {
43
32
  includeResolverArgs: false,
44
33
  rootFieldsNaming: false,
45
34
  operationNameProperty: '',
35
+ skipError: defaultSkipError,
46
36
  };
37
+ function defaultSkipError(error) {
38
+ return error instanceof core.EnvelopError;
39
+ }
47
40
  const useNewRelic = (rawOptions) => {
48
41
  const options = {
49
42
  ...DEFAULT_OPTIONS,
@@ -112,10 +105,11 @@ const useNewRelic = (rawOptions) => {
112
105
  resolverSegment.addAttribute(AttributeName.RESOLVER_ARGS, JSON.stringify(resolverArgsToTrack));
113
106
  }
114
107
  return ({ result }) => {
108
+ var _a;
115
109
  if (options.includeRawResult) {
116
110
  resolverSegment.addAttribute(AttributeName.RESOLVER_RESULT, JSON.stringify(result));
117
111
  }
118
- if (result instanceof Error) {
112
+ if (result instanceof Error && !((_a = options.skipError) === null || _a === void 0 ? void 0 : _a.call(options, result))) {
119
113
  const transaction = instrumentationApi.tracer.getTransaction();
120
114
  instrumentationApi.agent.errors.add(transaction, JSON.stringify(result));
121
115
  }
@@ -126,7 +120,7 @@ const useNewRelic = (rawOptions) => {
126
120
  return {
127
121
  onResolverCalled,
128
122
  onExecuteDone({ result }) {
129
- if (isAsyncIterable(result)) {
123
+ if (core.isAsyncIterable(result)) {
130
124
  operationSegment.end();
131
125
  // eslint-disable-next-line no-console
132
126
  console.warn(`Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
@@ -168,4 +162,5 @@ function filterPropertiesByRegex(initialObject, pattern) {
168
162
  return filteredObject;
169
163
  }
170
164
 
165
+ exports.defaultSkipError = defaultSkipError;
171
166
  exports.useNewRelic = useNewRelic;
package/index.mjs CHANGED
@@ -1,18 +1,7 @@
1
1
  import newRelic from 'newrelic';
2
+ import { EnvelopError, isAsyncIterable } from '@envelop/core';
2
3
  import { Kind, print } from 'graphql';
3
4
 
4
- /**
5
- * Returns true if the provided object implements the AsyncIterator protocol via
6
- * implementing a `Symbol.asyncIterator` method.
7
- *
8
- * Source: https://github.com/graphql/graphql-js/blob/main/src/jsutils/isAsyncIterable.ts
9
- */
10
- function isAsyncIterable(maybeAsyncIterable) {
11
- return (maybeAsyncIterable != null &&
12
- typeof maybeAsyncIterable === 'object' &&
13
- typeof maybeAsyncIterable[Symbol.asyncIterator] === 'function');
14
- }
15
-
16
5
  const { shim: instrumentationApi } = newRelic;
17
6
  var AttributeName;
18
7
  (function (AttributeName) {
@@ -37,7 +26,11 @@ const DEFAULT_OPTIONS = {
37
26
  includeResolverArgs: false,
38
27
  rootFieldsNaming: false,
39
28
  operationNameProperty: '',
29
+ skipError: defaultSkipError,
40
30
  };
31
+ function defaultSkipError(error) {
32
+ return error instanceof EnvelopError;
33
+ }
41
34
  const useNewRelic = (rawOptions) => {
42
35
  const options = {
43
36
  ...DEFAULT_OPTIONS,
@@ -106,10 +99,11 @@ const useNewRelic = (rawOptions) => {
106
99
  resolverSegment.addAttribute(AttributeName.RESOLVER_ARGS, JSON.stringify(resolverArgsToTrack));
107
100
  }
108
101
  return ({ result }) => {
102
+ var _a;
109
103
  if (options.includeRawResult) {
110
104
  resolverSegment.addAttribute(AttributeName.RESOLVER_RESULT, JSON.stringify(result));
111
105
  }
112
- if (result instanceof Error) {
106
+ if (result instanceof Error && !((_a = options.skipError) === null || _a === void 0 ? void 0 : _a.call(options, result))) {
113
107
  const transaction = instrumentationApi.tracer.getTransaction();
114
108
  instrumentationApi.agent.errors.add(transaction, JSON.stringify(result));
115
109
  }
@@ -162,4 +156,4 @@ function filterPropertiesByRegex(initialObject, pattern) {
162
156
  return filteredObject;
163
157
  }
164
158
 
165
- export { useNewRelic };
159
+ export { defaultSkipError, useNewRelic };
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/newrelic",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
+ "@envelop/core": "^1.6.1",
6
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
7
8
  "newrelic": "^7 || ^8.0.0"
8
9
  },