@coko/server
Version:
Reusable server for use by Coko's projects
51 lines • 2.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_1 = __importDefault(require("@sentry/node"));
function SentryApolloPlugin() {
return {
async requestDidStart(requestContext) {
const operationName = requestContext.request.operationName || null;
const variables = requestContext.request.variables || null;
return {
async didEncounterErrors(ctx) {
for (const err of ctx.errors) {
const original = err.originalError || err;
node_1.default.withScope(scope => {
if (operationName) {
scope.setExtra('graphql operation', operationName);
}
if (ctx.request.query) {
scope.setExtra('graphql query', ctx.request.query);
}
if (variables) {
scope.setExtra('graphql variables', variables);
}
if (err.path) {
scope.setExtra('graphql path', err.path);
}
if (ctx.request.http && ctx.request.http.headers) {
scope.setExtra('headers', ctx.request.http.headers);
}
// Customize fingerprint to separate by resolver path: eg. group by resolver path + error name
const pathFingerprint = err.path && Array.isArray(err.path)
? err.path.join('.')
: 'no-path';
const errorName = original && original.name ? original.name : 'GraphQLError';
scope.setFingerprint([errorName, pathFingerprint]);
scope.setLevel('error');
const userId = ctx.contextValue?.userId || null;
if (userId)
scope.setUser({ id: userId });
node_1.default.captureException(original);
});
}
},
};
},
};
}
exports.default = SentryApolloPlugin;
//# sourceMappingURL=sentryPlugin.js.map