@strapi/plugin-sentry 4.0.0-next.7 → 4.0.1
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/admin/src/index.js +0 -8
- package/admin/src/translations/ko.json +4 -1
- package/jest.config.js +10 -0
- package/package.json +21 -13
- package/server/bootstrap.js +4 -5
- package/server/config.js +1 -1
- package/server/index.js +11 -0
- package/server/middlewares/sentry.js +40 -0
- package/server/services/__tests__/sentry.test.js +4 -3
- package/strapi-admin.js +3 -0
- package/strapi-server.js +1 -11
- package/admin/src/assets/images/logo.svg +0 -1
- package/server/middlewares/index.js +0 -7
- package/server/middlewares/sentry/index.js +0 -36
package/admin/src/index.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
import { prefixPluginTranslations } from '@strapi/helper-plugin';
|
|
2
2
|
import pluginPkg from '../../package.json';
|
|
3
3
|
import pluginId from './pluginId';
|
|
4
|
-
import pluginLogo from './assets/images/logo.svg';
|
|
5
4
|
|
|
6
|
-
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
|
7
|
-
const icon = pluginPkg.strapi.icon;
|
|
8
5
|
const name = pluginPkg.strapi.name;
|
|
9
6
|
|
|
10
7
|
export default {
|
|
11
8
|
register(app) {
|
|
12
9
|
app.registerPlugin({
|
|
13
|
-
description: pluginDescription,
|
|
14
|
-
icon,
|
|
15
10
|
id: pluginId,
|
|
16
|
-
isReady: true,
|
|
17
|
-
isRequired: pluginPkg.strapi.required || false,
|
|
18
11
|
name,
|
|
19
|
-
pluginLogo,
|
|
20
12
|
});
|
|
21
13
|
},
|
|
22
14
|
bootstrap() {},
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/plugin-sentry",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Send Strapi error events to Sentry",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"kind": "plugin"
|
|
10
|
-
},
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"@sentry/node": "6.7.1"
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/strapi/strapi.git",
|
|
8
|
+
"directory": "packages/plugins/sentry"
|
|
13
9
|
},
|
|
10
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
14
11
|
"author": {
|
|
15
|
-
"name": "Strapi
|
|
12
|
+
"name": "Strapi Solutions SAS",
|
|
16
13
|
"email": "hi@strapi.io",
|
|
17
14
|
"url": "https://strapi.io"
|
|
18
15
|
},
|
|
19
16
|
"maintainers": [
|
|
20
17
|
{
|
|
21
|
-
"name": "Strapi
|
|
18
|
+
"name": "Strapi Solutions SAS",
|
|
22
19
|
"email": "hi@strapi.io",
|
|
23
20
|
"url": "https://strapi.io"
|
|
24
21
|
}
|
|
25
22
|
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test:unit": "jest --verbose"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@sentry/node": "6.7.1"
|
|
28
|
+
},
|
|
26
29
|
"engines": {
|
|
27
30
|
"node": ">=12.x.x <=16.x.x",
|
|
28
31
|
"npm": ">=6.0.0"
|
|
29
32
|
},
|
|
30
|
-
"
|
|
31
|
-
|
|
33
|
+
"strapi": {
|
|
34
|
+
"name": "sentry",
|
|
35
|
+
"displayName": "Sentry",
|
|
36
|
+
"description": "Send Strapi error events to Sentry.",
|
|
37
|
+
"kind": "plugin"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "e2cd01e8c6cbfeba15ad7787e38b6eebcbb92221"
|
|
32
40
|
}
|
package/server/bootstrap.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const initSentryMiddleware = require('./middlewares/sentry');
|
|
4
|
+
|
|
5
|
+
module.exports = async ({ strapi }) => {
|
|
4
6
|
// Initialize the Sentry service exposed by this plugin
|
|
5
|
-
strapi
|
|
6
|
-
.plugin('sentry')
|
|
7
|
-
.service('sentry')
|
|
8
|
-
.init();
|
|
7
|
+
initSentryMiddleware({ strapi });
|
|
9
8
|
};
|
package/server/config.js
CHANGED
package/server/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Programmatic sentry middleware. We do not want to expose it in the plugin
|
|
5
|
+
* @param {{ strapi: import('@strapi/strapi').Strapi }}
|
|
6
|
+
*/
|
|
7
|
+
module.exports = ({ strapi }) => {
|
|
8
|
+
const sentryService = strapi.plugin('sentry').service('sentry');
|
|
9
|
+
sentryService.init();
|
|
10
|
+
const sentry = sentryService.getInstance();
|
|
11
|
+
|
|
12
|
+
if (!sentry) {
|
|
13
|
+
// initialization failed
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
strapi.server.use(async (ctx, next) => {
|
|
18
|
+
try {
|
|
19
|
+
await next();
|
|
20
|
+
} catch (error) {
|
|
21
|
+
sentry.sendError(error, (scope, sentryInstance) => {
|
|
22
|
+
scope.addEventProcessor(event => {
|
|
23
|
+
// Parse Koa context to add error metadata
|
|
24
|
+
return sentryInstance.Handlers.parseRequest(event, ctx.request, {
|
|
25
|
+
// Don't parse the transaction name, we'll do it manually
|
|
26
|
+
transaction: false,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Manually add transaction name
|
|
31
|
+
scope.setTag('transaction', `${ctx.method} ${ctx.request.url}`);
|
|
32
|
+
// Manually add Strapi version
|
|
33
|
+
scope.setTag('strapi_version', strapi.config.info.strapi);
|
|
34
|
+
scope.setTag('method', ctx.method);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const INVALID_DSN = 'an_invalid_dsn';
|
|
4
4
|
const VALID_DSN = 'a_valid_dsn';
|
|
5
|
-
const
|
|
5
|
+
const mockCaptureException = jest.fn();
|
|
6
|
+
|
|
6
7
|
// FIXME
|
|
7
8
|
/* eslint-disable import/extensions */
|
|
8
9
|
jest.mock('@sentry/node', () => {
|
|
@@ -12,7 +13,7 @@ jest.mock('@sentry/node', () => {
|
|
|
12
13
|
throw Error();
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
|
-
captureException,
|
|
16
|
+
captureException: mockCaptureException,
|
|
16
17
|
withScope(configureScope) {
|
|
17
18
|
configureScope();
|
|
18
19
|
},
|
|
@@ -83,7 +84,7 @@ describe('Sentry service', () => {
|
|
|
83
84
|
const configureScope = jest.fn();
|
|
84
85
|
sentryService.sendError(error, configureScope);
|
|
85
86
|
expect(configureScope).toHaveBeenCalled();
|
|
86
|
-
expect(
|
|
87
|
+
expect(mockCaptureException).toHaveBeenCalled();
|
|
87
88
|
});
|
|
88
89
|
|
|
89
90
|
it('does not not send metadata when the option is disabled', () => {
|
package/strapi-admin.js
ADDED
package/strapi-server.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const services = require('./server/services');
|
|
5
|
-
const middlewares = require('./server/middlewares');
|
|
6
|
-
const config = require('./server/config');
|
|
7
|
-
|
|
8
|
-
module.exports = () => ({
|
|
9
|
-
bootstrap,
|
|
10
|
-
config,
|
|
11
|
-
middlewares,
|
|
12
|
-
services,
|
|
13
|
-
});
|
|
3
|
+
module.exports = require('./server');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg class="css-15xgryy e10nushx5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 66" width="400" height="367"><path d="M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z" fill="#362d59" transform="translate(11, 11)"></path></svg>
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
defaults: { sentry: { enabled: true } },
|
|
5
|
-
load: {
|
|
6
|
-
beforeInitialize() {
|
|
7
|
-
strapi.config.middleware.load.after.unshift('sentry');
|
|
8
|
-
},
|
|
9
|
-
initialize() {
|
|
10
|
-
const sentry = strapi.plugin('sentry').service('sentry');
|
|
11
|
-
sentry.init();
|
|
12
|
-
|
|
13
|
-
strapi.app.use(async (ctx, next) => {
|
|
14
|
-
try {
|
|
15
|
-
await next();
|
|
16
|
-
} catch (error) {
|
|
17
|
-
sentry.sendError(error, (scope, sentryInstance) => {
|
|
18
|
-
scope.addEventProcessor(event => {
|
|
19
|
-
// Parse Koa context to add error metadata
|
|
20
|
-
return sentryInstance.Handlers.parseRequest(event, ctx.request, {
|
|
21
|
-
// Don't parse the transaction name, we'll do it manually
|
|
22
|
-
transaction: false,
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
// Manually add transaction name
|
|
26
|
-
scope.setTag('transaction', `${ctx.method} ${ctx.request.url}`);
|
|
27
|
-
// Manually add Strapi version
|
|
28
|
-
scope.setTag('strapi_version', strapi.config.info.strapi);
|
|
29
|
-
scope.setTag('method', ctx.method);
|
|
30
|
-
});
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
};
|