@envelop/sentry 3.5.0-alpha-aca44e1.0 → 4.0.0-alpha-d0d0776.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 (4) hide show
  1. package/README.md +2 -0
  2. package/index.js +36 -21
  3. package/index.mjs +20 -25
  4. package/package.json +20 -8
package/README.md CHANGED
@@ -32,6 +32,8 @@ yarn add @sentry/node @sentry/tracing @envelop/sentry
32
32
  ```ts
33
33
  import { envelop } from '@envelop/core';
34
34
  import { useSentry } from '@envelop/sentry';
35
+ // do this only once in you entry file.
36
+ import "@sentry/tracing";
35
37
 
36
38
  const getEnveloped = envelop({
37
39
  plugins: [
package/index.js CHANGED
@@ -6,14 +6,33 @@ const core = require('@envelop/core');
6
6
  const Sentry = require('@sentry/node');
7
7
  const graphql = require('graphql');
8
8
 
9
+ function _interopNamespace(e) {
10
+ if (e && e.__esModule) return e;
11
+ const n = Object.create(null);
12
+ if (e) {
13
+ for (const k in e) {
14
+ if (k !== 'default') {
15
+ const d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ }
22
+ }
23
+ n["default"] = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ const Sentry__namespace = /*#__PURE__*/_interopNamespace(Sentry);
28
+
9
29
  function defaultSkipError(error) {
10
30
  return error instanceof core.EnvelopError;
11
31
  }
12
32
  const sentryTracingSymbol = Symbol('sentryTracing');
13
33
  const useSentry = (options = {}) => {
14
34
  function pick(key, defaultValue) {
15
- var _a;
16
- return (_a = options[key]) !== null && _a !== void 0 ? _a : defaultValue;
35
+ return options[key] ?? defaultValue;
17
36
  }
18
37
  const startTransaction = pick('startTransaction', true);
19
38
  const trackResolvers = pick('trackResolvers', true);
@@ -24,11 +43,10 @@ const useSentry = (options = {}) => {
24
43
  const skipOperation = pick('skip', () => false);
25
44
  const skipError = pick('skipError', defaultSkipError);
26
45
  function addEventId(err, eventId) {
27
- var _a;
28
46
  if (options.eventIdKey === null) {
29
47
  return err;
30
48
  }
31
- const eventIdKey = (_a = options.eventIdKey) !== null && _a !== void 0 ? _a : 'sentryEventId';
49
+ const eventIdKey = options.eventIdKey ?? 'sentryEventId';
32
50
  return new graphql.GraphQLError(err.message, err.nodes, err.source, err.positions, err.path, undefined, {
33
51
  ...err.extensions,
34
52
  [eventIdKey]: eventId,
@@ -61,7 +79,7 @@ const useSentry = (options = {}) => {
61
79
  const errorPath = graphql.responsePathAsArray(info.path)
62
80
  .map(v => (typeof v === 'number' ? '$index' : v))
63
81
  .join(' > ');
64
- Sentry.captureException(result, {
82
+ Sentry__namespace.captureException(result, {
65
83
  fingerprint: ['graphql', errorPath, opName, operationType],
66
84
  });
67
85
  }
@@ -74,14 +92,13 @@ const useSentry = (options = {}) => {
74
92
  return {
75
93
  onResolverCalled,
76
94
  onExecute({ args, extendContext }) {
77
- var _a;
78
95
  if (skipOperation(args)) {
79
96
  return;
80
97
  }
81
98
  const rootOperation = args.document.definitions.find(o => o.kind === graphql.Kind.OPERATION_DEFINITION);
82
99
  const operationType = rootOperation.operation;
83
100
  const document = graphql.print(args.document);
84
- const opName = args.operationName || ((_a = rootOperation.name) === null || _a === void 0 ? void 0 : _a.value) || 'Anonymous Operation';
101
+ const opName = args.operationName || rootOperation.name?.value || 'Anonymous Operation';
85
102
  const addedTags = (options.appendTags && options.appendTags(args)) || {};
86
103
  const transactionName = options.transactionName ? options.transactionName(args) : opName;
87
104
  const op = options.operationName ? options.operationName(args) : 'execute';
@@ -92,16 +109,16 @@ const useSentry = (options = {}) => {
92
109
  };
93
110
  let rootSpan;
94
111
  if (startTransaction) {
95
- rootSpan = Sentry.startTransaction({
112
+ rootSpan = Sentry__namespace.startTransaction({
96
113
  name: transactionName,
97
114
  op,
98
115
  tags,
99
116
  });
100
117
  }
101
118
  else {
102
- const scope = Sentry.getCurrentHub().getScope();
103
- const parentSpan = scope === null || scope === void 0 ? void 0 : scope.getSpan();
104
- const span = parentSpan === null || parentSpan === void 0 ? void 0 : parentSpan.startChild({
119
+ const scope = Sentry__namespace.getCurrentHub().getScope();
120
+ const parentSpan = scope?.getSpan();
121
+ const span = parentSpan?.startChild({
105
122
  description: transactionName,
106
123
  op,
107
124
  tags,
@@ -121,7 +138,7 @@ const useSentry = (options = {}) => {
121
138
  }
122
139
  rootSpan.setData('document', document);
123
140
  if (options.configureScope) {
124
- Sentry.configureScope(scope => options.configureScope(args, scope));
141
+ Sentry__namespace.configureScope(scope => options.configureScope(args, scope));
125
142
  }
126
143
  if (onResolverCalled) {
127
144
  const sentryContext = {
@@ -138,8 +155,7 @@ const useSentry = (options = {}) => {
138
155
  rootSpan.setData('result', result);
139
156
  }
140
157
  if (result.errors && result.errors.length > 0) {
141
- Sentry.withScope(scope => {
142
- var _a;
158
+ Sentry__namespace.withScope(scope => {
143
159
  scope.setTransactionName(opName);
144
160
  scope.setTag('operation', operationType);
145
161
  scope.setTag('operationName', opName);
@@ -151,24 +167,23 @@ const useSentry = (options = {}) => {
151
167
  if (includeExecuteVariables) {
152
168
  scope.setExtra('variables', args.variableValues);
153
169
  }
154
- const errors = (_a = result.errors) === null || _a === void 0 ? void 0 : _a.map(err => {
155
- var _a, _b;
156
- const errorPath = ((_a = err.path) !== null && _a !== void 0 ? _a : []).join(' > ');
170
+ const errors = result.errors?.map(err => {
171
+ const errorPath = (err.path ?? []).join(' > ');
157
172
  if (errorPath) {
158
173
  scope.addBreadcrumb({
159
174
  category: 'execution-path',
160
175
  message: errorPath,
161
- level: Sentry.Severity.Debug,
176
+ level: 'debug',
162
177
  });
163
178
  }
164
179
  // Map index values in list to $index for better grouping of events.
165
- const errorPathWithIndex = ((_b = err.path) !== null && _b !== void 0 ? _b : []).map(v => (typeof v === 'number' ? '$index' : v)).join(' > ');
166
- const eventId = Sentry.captureException(err, {
180
+ const errorPathWithIndex = (err.path ?? []).map(v => (typeof v === 'number' ? '$index' : v)).join(' > ');
181
+ const eventId = Sentry__namespace.captureException(err, {
167
182
  fingerprint: ['graphql', errorPathWithIndex, opName, operationType],
168
183
  contexts: {
169
184
  GraphQL: {
170
185
  operationName: opName,
171
- operationType: operationType,
186
+ operationType,
172
187
  variables: args.variableValues,
173
188
  },
174
189
  },
package/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EnvelopError, handleStreamOrSingleExecutionResult } from '@envelop/core';
2
- import { startTransaction, getCurrentHub, configureScope, captureException, withScope, Severity } from '@sentry/node';
3
- import { Kind, print, responsePathAsArray, GraphQLError } from 'graphql';
2
+ import * as Sentry from '@sentry/node';
3
+ import { responsePathAsArray, Kind, print, GraphQLError } from 'graphql';
4
4
 
5
5
  function defaultSkipError(error) {
6
6
  return error instanceof EnvelopError;
@@ -8,10 +8,9 @@ function defaultSkipError(error) {
8
8
  const sentryTracingSymbol = Symbol('sentryTracing');
9
9
  const useSentry = (options = {}) => {
10
10
  function pick(key, defaultValue) {
11
- var _a;
12
- return (_a = options[key]) !== null && _a !== void 0 ? _a : defaultValue;
11
+ return options[key] ?? defaultValue;
13
12
  }
14
- const startTransaction$1 = pick('startTransaction', true);
13
+ const startTransaction = pick('startTransaction', true);
15
14
  const trackResolvers = pick('trackResolvers', true);
16
15
  const includeResolverArgs = pick('includeResolverArgs', false);
17
16
  const includeRawResult = pick('includeRawResult', false);
@@ -20,11 +19,10 @@ const useSentry = (options = {}) => {
20
19
  const skipOperation = pick('skip', () => false);
21
20
  const skipError = pick('skipError', defaultSkipError);
22
21
  function addEventId(err, eventId) {
23
- var _a;
24
22
  if (options.eventIdKey === null) {
25
23
  return err;
26
24
  }
27
- const eventIdKey = (_a = options.eventIdKey) !== null && _a !== void 0 ? _a : 'sentryEventId';
25
+ const eventIdKey = options.eventIdKey ?? 'sentryEventId';
28
26
  return new GraphQLError(err.message, err.nodes, err.source, err.positions, err.path, undefined, {
29
27
  ...err.extensions,
30
28
  [eventIdKey]: eventId,
@@ -57,7 +55,7 @@ const useSentry = (options = {}) => {
57
55
  const errorPath = responsePathAsArray(info.path)
58
56
  .map(v => (typeof v === 'number' ? '$index' : v))
59
57
  .join(' > ');
60
- captureException(result, {
58
+ Sentry.captureException(result, {
61
59
  fingerprint: ['graphql', errorPath, opName, operationType],
62
60
  });
63
61
  }
@@ -70,14 +68,13 @@ const useSentry = (options = {}) => {
70
68
  return {
71
69
  onResolverCalled,
72
70
  onExecute({ args, extendContext }) {
73
- var _a;
74
71
  if (skipOperation(args)) {
75
72
  return;
76
73
  }
77
74
  const rootOperation = args.document.definitions.find(o => o.kind === Kind.OPERATION_DEFINITION);
78
75
  const operationType = rootOperation.operation;
79
76
  const document = print(args.document);
80
- const opName = args.operationName || ((_a = rootOperation.name) === null || _a === void 0 ? void 0 : _a.value) || 'Anonymous Operation';
77
+ const opName = args.operationName || rootOperation.name?.value || 'Anonymous Operation';
81
78
  const addedTags = (options.appendTags && options.appendTags(args)) || {};
82
79
  const transactionName = options.transactionName ? options.transactionName(args) : opName;
83
80
  const op = options.operationName ? options.operationName(args) : 'execute';
@@ -87,17 +84,17 @@ const useSentry = (options = {}) => {
87
84
  ...(addedTags || {}),
88
85
  };
89
86
  let rootSpan;
90
- if (startTransaction$1) {
91
- rootSpan = startTransaction({
87
+ if (startTransaction) {
88
+ rootSpan = Sentry.startTransaction({
92
89
  name: transactionName,
93
90
  op,
94
91
  tags,
95
92
  });
96
93
  }
97
94
  else {
98
- const scope = getCurrentHub().getScope();
99
- const parentSpan = scope === null || scope === void 0 ? void 0 : scope.getSpan();
100
- const span = parentSpan === null || parentSpan === void 0 ? void 0 : parentSpan.startChild({
95
+ const scope = Sentry.getCurrentHub().getScope();
96
+ const parentSpan = scope?.getSpan();
97
+ const span = parentSpan?.startChild({
101
98
  description: transactionName,
102
99
  op,
103
100
  tags,
@@ -117,7 +114,7 @@ const useSentry = (options = {}) => {
117
114
  }
118
115
  rootSpan.setData('document', document);
119
116
  if (options.configureScope) {
120
- configureScope(scope => options.configureScope(args, scope));
117
+ Sentry.configureScope(scope => options.configureScope(args, scope));
121
118
  }
122
119
  if (onResolverCalled) {
123
120
  const sentryContext = {
@@ -134,8 +131,7 @@ const useSentry = (options = {}) => {
134
131
  rootSpan.setData('result', result);
135
132
  }
136
133
  if (result.errors && result.errors.length > 0) {
137
- withScope(scope => {
138
- var _a;
134
+ Sentry.withScope(scope => {
139
135
  scope.setTransactionName(opName);
140
136
  scope.setTag('operation', operationType);
141
137
  scope.setTag('operationName', opName);
@@ -147,24 +143,23 @@ const useSentry = (options = {}) => {
147
143
  if (includeExecuteVariables) {
148
144
  scope.setExtra('variables', args.variableValues);
149
145
  }
150
- const errors = (_a = result.errors) === null || _a === void 0 ? void 0 : _a.map(err => {
151
- var _a, _b;
152
- const errorPath = ((_a = err.path) !== null && _a !== void 0 ? _a : []).join(' > ');
146
+ const errors = result.errors?.map(err => {
147
+ const errorPath = (err.path ?? []).join(' > ');
153
148
  if (errorPath) {
154
149
  scope.addBreadcrumb({
155
150
  category: 'execution-path',
156
151
  message: errorPath,
157
- level: Severity.Debug,
152
+ level: 'debug',
158
153
  });
159
154
  }
160
155
  // Map index values in list to $index for better grouping of events.
161
- const errorPathWithIndex = ((_b = err.path) !== null && _b !== void 0 ? _b : []).map(v => (typeof v === 'number' ? '$index' : v)).join(' > ');
162
- const eventId = captureException(err, {
156
+ const errorPathWithIndex = (err.path ?? []).map(v => (typeof v === 'number' ? '$index' : v)).join(' > ');
157
+ const eventId = Sentry.captureException(err, {
163
158
  fingerprint: ['graphql', errorPathWithIndex, opName, operationType],
164
159
  contexts: {
165
160
  GraphQL: {
166
161
  operationName: opName,
167
- operationType: operationType,
162
+ operationType,
168
163
  variables: args.variableValues,
169
164
  },
170
165
  },
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@envelop/sentry",
3
- "version": "3.5.0-alpha-aca44e1.0",
3
+ "version": "4.0.0-alpha-d0d0776.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-aca44e1.0",
7
- "@sentry/node": "^6",
6
+ "@envelop/core": "3.0.0-alpha-d0d0776.0",
7
+ "@sentry/node": "^6 || ^7",
8
8
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/dotansimha/envelop.git",
12
+ "url": "https://github.com/n1ru4l/envelop.git",
13
13
  "directory": "packages/plugins/sentry"
14
14
  },
15
15
  "author": "Dotan Simha <dotansimha@gmail.com>",
@@ -22,12 +22,24 @@
22
22
  },
23
23
  "exports": {
24
24
  ".": {
25
- "require": "./index.js",
26
- "import": "./index.mjs"
25
+ "require": {
26
+ "default": "./index.js",
27
+ "types": "./index.d.ts"
28
+ },
29
+ "import": {
30
+ "default": "./index.mjs",
31
+ "types": "./index.d.ts"
32
+ }
27
33
  },
28
34
  "./*": {
29
- "require": "./*.js",
30
- "import": "./*.mjs"
35
+ "require": {
36
+ "default": "./*.js",
37
+ "types": "./*.d.ts"
38
+ },
39
+ "import": {
40
+ "default": "./*.mjs",
41
+ "types": "./*.d.ts"
42
+ }
31
43
  },
32
44
  "./package.json": "./package.json"
33
45
  }