Add Moesif API Analytics and Monitoring to Strapi
Plugin to add Moesif API Analytics and Monitoring to Strapi!
Install the plugin
npm install --save strapi-plugin-moesif
./config/plugins.js
1module.exports = {
2 'strapi-plugin-moesif': {
3 enabled: true,
4 config: {
5 moesif: {
6 //custom config passed to moesif middleware goes here
7 }
8 },
9 },
10}
Add Moesif to your middleware array ./config/middleware.js
1module.exports = [
2 'strapi::errors',
3 'strapi::security',
4 'strapi::cors',
5 'strapi::poweredBy',
6 'strapi::logger',
7 'strapi::query',
8 'strapi::body',
9 'strapi::favicon',
10 'strapi::public',
11 'plugin::strapi-plugin-moesif.moesif'
12];
Add MOESIFAPPLICATION_ID to your environment variables Your Moesif Application Id can be found in the [_Moesif Portal](https://www.moesif.com/). After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.
npm
npm run develop
yarn
yarn develop
Make a few API calls to your resources like so:
curl `http://localhost:1337`
If using Heroku, simply install the Moesif application as an add-on. The MOESIF_APPLICATION_ID environment variable will be automatically created and managed by Heroku.
Because this plugin uses moesif-nodejs
under the hood, all of the configuration options for moesif-nodejs are supported by this plugin also.
To track Strapi users, we set the identifyUser
function by default:
1identifyUser: function (req, res) {
2 if (req.state && req.state.user) {
3 return String(req.state.user.id);
4 }
5 return undefined;
6}
Moesif can be setup to track all traffic in and out of your application, but usually the interest is in API metrics specifically. The default configuration of this plugin skips all non-JSON communication to avoid having tons of file requests in your Moesif dashboard.
To override the skip function, simple include one in your config, or set to to send all communications:
1// return true if the data should be skipped
2skip: function (req, res) {
3 // don't log non JSON types
4 return (
5 res.headers && !res.headers["Content-Type"].includes("application/json")
6 );
7}
8
9//send all data regardless of type
10skip: null
This plugin was originally created by Bobby Glidwell
npm install strapi-plugin-moesif
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.