@envelop/sentry 3.8.0 → 3.8.1-alpha-20220901205925-b1fd44a9
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 +5 -0
- package/cjs/index.js +13 -16
- package/esm/index.js +14 -17
- package/package.json +2 -2
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -30,12 +30,17 @@ yarn add @sentry/node @sentry/tracing @envelop/sentry
|
|
|
30
30
|
## Usage Example
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
|
+
import { parse, validate, execute, subscribe } from 'graphql'
|
|
33
34
|
import { envelop } from '@envelop/core'
|
|
34
35
|
import { useSentry } from '@envelop/sentry'
|
|
35
36
|
// do this only once in you entry file.
|
|
36
37
|
import '@sentry/tracing'
|
|
37
38
|
|
|
38
39
|
const getEnveloped = envelop({
|
|
40
|
+
parse,
|
|
41
|
+
validate,
|
|
42
|
+
execute,
|
|
43
|
+
subscribe,
|
|
39
44
|
plugins: [
|
|
40
45
|
// ... other plugins ...
|
|
41
46
|
useSentry({
|
package/cjs/index.js
CHANGED
|
@@ -6,14 +6,13 @@ const core_1 = require("@envelop/core");
|
|
|
6
6
|
const Sentry = tslib_1.__importStar(require("@sentry/node"));
|
|
7
7
|
const graphql_1 = require("graphql");
|
|
8
8
|
function defaultSkipError(error) {
|
|
9
|
-
return error instanceof
|
|
9
|
+
return error instanceof Error;
|
|
10
10
|
}
|
|
11
11
|
exports.defaultSkipError = defaultSkipError;
|
|
12
12
|
const sentryTracingSymbol = Symbol('sentryTracing');
|
|
13
13
|
const useSentry = (options = {}) => {
|
|
14
14
|
function pick(key, defaultValue) {
|
|
15
|
-
|
|
16
|
-
return (_a = options[key]) !== null && _a !== void 0 ? _a : defaultValue;
|
|
15
|
+
return options[key] ?? defaultValue;
|
|
17
16
|
}
|
|
18
17
|
const startTransaction = pick('startTransaction', true);
|
|
19
18
|
const trackResolvers = pick('trackResolvers', true);
|
|
@@ -24,11 +23,10 @@ const useSentry = (options = {}) => {
|
|
|
24
23
|
const skipOperation = pick('skip', () => false);
|
|
25
24
|
const skipError = pick('skipError', defaultSkipError);
|
|
26
25
|
function addEventId(err, eventId) {
|
|
27
|
-
var _a;
|
|
28
26
|
if (options.eventIdKey === null) {
|
|
29
27
|
return err;
|
|
30
28
|
}
|
|
31
|
-
const eventIdKey =
|
|
29
|
+
const eventIdKey = options.eventIdKey ?? 'sentryEventId';
|
|
32
30
|
return new graphql_1.GraphQLError(err.message, err.nodes, err.source, err.positions, err.path, undefined, {
|
|
33
31
|
...err.extensions,
|
|
34
32
|
[eventIdKey]: eventId,
|
|
@@ -74,14 +72,15 @@ const useSentry = (options = {}) => {
|
|
|
74
72
|
return {
|
|
75
73
|
onResolverCalled,
|
|
76
74
|
onExecute({ args, extendContext }) {
|
|
77
|
-
var _a;
|
|
78
75
|
if (skipOperation(args)) {
|
|
79
76
|
return;
|
|
80
77
|
}
|
|
81
|
-
const rootOperation = args.document.definitions.find(
|
|
78
|
+
const rootOperation = args.document.definitions.find(
|
|
79
|
+
// @ts-expect-error TODO: not sure how we will make it dev friendly
|
|
80
|
+
o => o.kind === graphql_1.Kind.OPERATION_DEFINITION);
|
|
82
81
|
const operationType = rootOperation.operation;
|
|
83
82
|
const document = (0, graphql_1.print)(args.document);
|
|
84
|
-
const opName = args.operationName ||
|
|
83
|
+
const opName = args.operationName || rootOperation.name?.value || 'Anonymous Operation';
|
|
85
84
|
const addedTags = (options.appendTags && options.appendTags(args)) || {};
|
|
86
85
|
const traceparentData = (options.traceparentData && options.traceparentData(args)) || {};
|
|
87
86
|
const transactionName = options.transactionName ? options.transactionName(args) : opName;
|
|
@@ -109,8 +108,8 @@ const useSentry = (options = {}) => {
|
|
|
109
108
|
}
|
|
110
109
|
else {
|
|
111
110
|
const scope = Sentry.getCurrentHub().getScope();
|
|
112
|
-
const parentSpan = scope
|
|
113
|
-
const span = parentSpan
|
|
111
|
+
const parentSpan = scope?.getSpan();
|
|
112
|
+
const span = parentSpan?.startChild({
|
|
114
113
|
description: transactionName,
|
|
115
114
|
op,
|
|
116
115
|
tags,
|
|
@@ -149,7 +148,6 @@ const useSentry = (options = {}) => {
|
|
|
149
148
|
}
|
|
150
149
|
if (result.errors && result.errors.length > 0) {
|
|
151
150
|
Sentry.withScope(scope => {
|
|
152
|
-
var _a;
|
|
153
151
|
scope.setTransactionName(opName);
|
|
154
152
|
scope.setTag('operation', operationType);
|
|
155
153
|
scope.setTag('operationName', opName);
|
|
@@ -161,9 +159,8 @@ const useSentry = (options = {}) => {
|
|
|
161
159
|
if (includeExecuteVariables) {
|
|
162
160
|
scope.setExtra('variables', args.variableValues);
|
|
163
161
|
}
|
|
164
|
-
const errors =
|
|
165
|
-
|
|
166
|
-
const errorPath = ((_a = err.path) !== null && _a !== void 0 ? _a : []).join(' > ');
|
|
162
|
+
const errors = result.errors?.map(err => {
|
|
163
|
+
const errorPath = (err.path ?? []).join(' > ');
|
|
167
164
|
if (errorPath) {
|
|
168
165
|
scope.addBreadcrumb({
|
|
169
166
|
category: 'execution-path',
|
|
@@ -172,8 +169,8 @@ const useSentry = (options = {}) => {
|
|
|
172
169
|
});
|
|
173
170
|
}
|
|
174
171
|
// Map index values in list to $index for better grouping of events.
|
|
175
|
-
const errorPathWithIndex = (
|
|
176
|
-
.map(v => (typeof v === 'number' ? '$index' : v))
|
|
172
|
+
const errorPathWithIndex = (err.path ?? [])
|
|
173
|
+
.map((v) => (typeof v === 'number' ? '$index' : v))
|
|
177
174
|
.join(' > ');
|
|
178
175
|
const eventId = Sentry.captureException(err, {
|
|
179
176
|
fingerprint: ['graphql', errorPathWithIndex, opName, operationType],
|
package/esm/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { handleStreamOrSingleExecutionResult, } from '@envelop/core';
|
|
2
2
|
import * as Sentry from '@sentry/node';
|
|
3
3
|
import { GraphQLError, Kind, print, responsePathAsArray } from 'graphql';
|
|
4
4
|
export function defaultSkipError(error) {
|
|
5
|
-
return error instanceof
|
|
5
|
+
return error instanceof Error;
|
|
6
6
|
}
|
|
7
7
|
const sentryTracingSymbol = Symbol('sentryTracing');
|
|
8
8
|
export const useSentry = (options = {}) => {
|
|
9
9
|
function pick(key, defaultValue) {
|
|
10
|
-
|
|
11
|
-
return (_a = options[key]) !== null && _a !== void 0 ? _a : defaultValue;
|
|
10
|
+
return options[key] ?? defaultValue;
|
|
12
11
|
}
|
|
13
12
|
const startTransaction = pick('startTransaction', true);
|
|
14
13
|
const trackResolvers = pick('trackResolvers', true);
|
|
@@ -19,11 +18,10 @@ export const useSentry = (options = {}) => {
|
|
|
19
18
|
const skipOperation = pick('skip', () => false);
|
|
20
19
|
const skipError = pick('skipError', defaultSkipError);
|
|
21
20
|
function addEventId(err, eventId) {
|
|
22
|
-
var _a;
|
|
23
21
|
if (options.eventIdKey === null) {
|
|
24
22
|
return err;
|
|
25
23
|
}
|
|
26
|
-
const eventIdKey =
|
|
24
|
+
const eventIdKey = options.eventIdKey ?? 'sentryEventId';
|
|
27
25
|
return new GraphQLError(err.message, err.nodes, err.source, err.positions, err.path, undefined, {
|
|
28
26
|
...err.extensions,
|
|
29
27
|
[eventIdKey]: eventId,
|
|
@@ -69,14 +67,15 @@ export const useSentry = (options = {}) => {
|
|
|
69
67
|
return {
|
|
70
68
|
onResolverCalled,
|
|
71
69
|
onExecute({ args, extendContext }) {
|
|
72
|
-
var _a;
|
|
73
70
|
if (skipOperation(args)) {
|
|
74
71
|
return;
|
|
75
72
|
}
|
|
76
|
-
const rootOperation = args.document.definitions.find(
|
|
73
|
+
const rootOperation = args.document.definitions.find(
|
|
74
|
+
// @ts-expect-error TODO: not sure how we will make it dev friendly
|
|
75
|
+
o => o.kind === Kind.OPERATION_DEFINITION);
|
|
77
76
|
const operationType = rootOperation.operation;
|
|
78
77
|
const document = print(args.document);
|
|
79
|
-
const opName = args.operationName ||
|
|
78
|
+
const opName = args.operationName || rootOperation.name?.value || 'Anonymous Operation';
|
|
80
79
|
const addedTags = (options.appendTags && options.appendTags(args)) || {};
|
|
81
80
|
const traceparentData = (options.traceparentData && options.traceparentData(args)) || {};
|
|
82
81
|
const transactionName = options.transactionName ? options.transactionName(args) : opName;
|
|
@@ -104,8 +103,8 @@ export const useSentry = (options = {}) => {
|
|
|
104
103
|
}
|
|
105
104
|
else {
|
|
106
105
|
const scope = Sentry.getCurrentHub().getScope();
|
|
107
|
-
const parentSpan = scope
|
|
108
|
-
const span = parentSpan
|
|
106
|
+
const parentSpan = scope?.getSpan();
|
|
107
|
+
const span = parentSpan?.startChild({
|
|
109
108
|
description: transactionName,
|
|
110
109
|
op,
|
|
111
110
|
tags,
|
|
@@ -144,7 +143,6 @@ export const useSentry = (options = {}) => {
|
|
|
144
143
|
}
|
|
145
144
|
if (result.errors && result.errors.length > 0) {
|
|
146
145
|
Sentry.withScope(scope => {
|
|
147
|
-
var _a;
|
|
148
146
|
scope.setTransactionName(opName);
|
|
149
147
|
scope.setTag('operation', operationType);
|
|
150
148
|
scope.setTag('operationName', opName);
|
|
@@ -156,9 +154,8 @@ export const useSentry = (options = {}) => {
|
|
|
156
154
|
if (includeExecuteVariables) {
|
|
157
155
|
scope.setExtra('variables', args.variableValues);
|
|
158
156
|
}
|
|
159
|
-
const errors =
|
|
160
|
-
|
|
161
|
-
const errorPath = ((_a = err.path) !== null && _a !== void 0 ? _a : []).join(' > ');
|
|
157
|
+
const errors = result.errors?.map(err => {
|
|
158
|
+
const errorPath = (err.path ?? []).join(' > ');
|
|
162
159
|
if (errorPath) {
|
|
163
160
|
scope.addBreadcrumb({
|
|
164
161
|
category: 'execution-path',
|
|
@@ -167,8 +164,8 @@ export const useSentry = (options = {}) => {
|
|
|
167
164
|
});
|
|
168
165
|
}
|
|
169
166
|
// Map index values in list to $index for better grouping of events.
|
|
170
|
-
const errorPathWithIndex = (
|
|
171
|
-
.map(v => (typeof v === 'number' ? '$index' : v))
|
|
167
|
+
const errorPathWithIndex = (err.path ?? [])
|
|
168
|
+
.map((v) => (typeof v === 'number' ? '$index' : v))
|
|
172
169
|
.join(' > ');
|
|
173
170
|
const eventId = Sentry.captureException(err, {
|
|
174
171
|
fingerprint: ['graphql', errorPathWithIndex, opName, operationType],
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/sentry",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.1-alpha-20220901205925-b1fd44a9",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
6
|
+
"@envelop/core": "2.6.1-alpha-20220901205925-b1fd44a9",
|
|
7
7
|
"@sentry/node": "^6 || ^7",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|
package/typings/index.d.cts
CHANGED
|
@@ -73,7 +73,7 @@ export declare type SentryPluginOptions = {
|
|
|
73
73
|
skip?: (args: ExecutionArgs) => boolean;
|
|
74
74
|
/**
|
|
75
75
|
* Indicates whether or not to skip Sentry exception reporting for a given error.
|
|
76
|
-
* By default, this plugin skips all `
|
|
76
|
+
* By default, this plugin skips all `Error` errors and does not report it to Sentry.
|
|
77
77
|
*/
|
|
78
78
|
skipError?: (args: Error) => boolean;
|
|
79
79
|
};
|
package/typings/index.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export declare type SentryPluginOptions = {
|
|
|
73
73
|
skip?: (args: ExecutionArgs) => boolean;
|
|
74
74
|
/**
|
|
75
75
|
* Indicates whether or not to skip Sentry exception reporting for a given error.
|
|
76
|
-
* By default, this plugin skips all `
|
|
76
|
+
* By default, this plugin skips all `Error` errors and does not report it to Sentry.
|
|
77
77
|
*/
|
|
78
78
|
skipError?: (args: Error) => boolean;
|
|
79
79
|
};
|