This plugin logs API traffic to Moesif API Analytics, which enables you to:
- Understand customer API usage
- Debug issues quickly
- Monetize your APIs
- Get alerted of API issues
- Guide customers at scale
- Protect and govern your API
This plugin supports automatic analysis of high-volume REST, GraphQL, and other APIs without adding latency.
How it works
When enabled, this plugin captures API traffic and logs it to Moesif API Analytics. This plugin logs to Moesif with an asynchronous design and doesn’t add any latency to your API calls.
Moesif natively supports REST, GraphQL, Web3, SOAP, JSON-RPC, and more.
How to install
If you are using Kong’s Kubernetes Ingress Controller, the installation is slightly different. Review the docs for Kubernetes Ingress.
The .rock
file is a self-contained package that can be installed locally or from a remote server.
If the LuaRocks utility is installed in your system (this is likely the case if you used one of the official installation packages), you can install the ‘rock’ in your LuaRocks tree (a directory in which LuaRocks installs Lua modules).
Install the Moesif plugin
luarocks install --server=http://luarocks.org/manifests/moesif kong-plugin-moesif
Update your loaded plugins list
In your kong.conf
, append moesif
to the plugins
field (or custom_plugins
if old version of Kong). Make sure the field is not commented out.
plugins = bundled,moesif # Comma-separated list of plugins this node
# should load. By default, only plugins
# bundled in official distributions are
# loaded via the `bundled` keyword.
If you don’t have a kong.conf
, create one from the default using the following command:
cp /etc/kong/kong.conf.default /etc/kong/kong.conf
Restart Kong
After LuaRocks is installed, restart Kong before enabling the plugin
kong restart
Enable the Moesif plugin
curl -i -X POST --url http://localhost:8001/plugins/ --data "name=moesif" --data "config.application_id=YOUR_APPLICATION_ID";
Restart Kong again
If you don’t see any logs in Moesif, you may need to restart Kong again.
kong restart
Configuration Reference
This plugin is compatible with DB-less mode.
In DB-less mode, you configure Kong Gateway declaratively. Therefore, the Admin API is mostly read-only. The only tasks it can perform are all related to handling the declarative config, including:
- Setting a target's health status in the load balancer
- Validating configurations against schemas
- Uploading the declarative configuration using the
/config
endpoint
The plugin is compatible with any with DB-less mode including local
, cluster
, and redis
Example plugin configuration
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter | Description |
---|---|
name
required Type: string |
The name of the plugin, in this case moesif . |
service.name or service.id
Type: string |
The name or ID of the service the plugin targets.
Set one of these parameters if adding the plugin to a service through the top-level /plugins endpoint.
Not required if using /services/SERVICE_NAME|SERVICE_ID/plugins . |
route.name or route.id
Type: string |
The name or ID of the route the plugin targets.
Set one of these parameters if adding the plugin to a route through the top-level /plugins endpoint.
Not required if using /routes/ROUTE_NAME|ROUTE_ID/plugins . |
consumer.name or consumer.id
Type: string |
The name or ID of the consumer the plugin targets.
Set one of these parameters if adding the plugin to a consumer through the top-level /plugins endpoint.
Not required if using /consumers/CONSUMER_NAME|CONSUMER_ID/plugins . |
enabled
Type: boolean Default value: true |
Whether this plugin will be applied. |
api_id
Type: string |
The ID of the API the plugin targets.
Note: The API Entity is deprecated in favor of Services since CE 0.13.0 and EE 0.32. |
config.application_id
required |
Your Moesif Application Id from your Moesif dashboard. Go to Top Right Menu -> Installation. |
config.api_endpoint
optional Default value: https://api.moesif.net
|
URL for the Moesif Collection API (Change to your secure proxy hostname if client-side encryption is used). |
config.connect_timeout
optional Default value: 1000
|
Timeout in milliseconds when connecting to Moesif. |
config.send_timeout
optional Default value: 2000
|
Timeout in milliseconds when sending data to Moesif. |
config.timeout
optional Default value: 1000
|
(Deprecated) timeout in milliseconds when connecting/sending to Moesif. |
config.keepalive
optional Default value: 5000
|
Value in milliseconds that defines for how long an idle connection will live before being closed. |
config.api_version
optional Default value: 1.0
|
API Version you want to tag this request with in Moesif. |
config.disable_capture_request_body
optional Default value: false
|
Disable logging of request body. |
config.disable_capture_response_body
optional Default value: false
|
Disable logging of response body. |
config.request_header_masks
optional Default value: {}
|
An array of request header fields to mask. |
config.request_query_masks
optional Default value: {}
|
An array of query string parameter fields to mask. |
config.request_body_masks
optional Default value: {}
|
An array of request body fields to mask. |
config.response_header_masks
optional Default value: {}
|
An array of response header fields to mask. |
config.response_body_masks
optional Default value: {}
|
An array of response body fields to mask. |
config.batch_size
optional Default value: 200
|
Maximum batch size when sending to Moesif. |
config.user_id_header
optional Default value: X-Consumer-Custom-Id
|
Request or response header used to identify the User in Moesif. |
config.company_id_header
optional Default value:
|
Request or response header used to identify the Company (Account) in Moesif. |
config.authorization_header_name
optional Default value: authorization
|
Request header containing a Bearer or basic token to extract user id. See identifying users. Also, supports a comma-separated string. The plugin will check headers in order “X-Api-Key, Authorization”. |
config.authorization_user_id_field
optional Default value: sub
|
Field name in JWT/OpenId token’s payload for identifying users. Only applicable if authorization_header_name is set and is a Bearer token. |
config.event_queue_size
optional Default value: 5000
|
Maximum number of events to hold in the queue before sending to Moesif. In case of network issues where the plugin is unable to connect or send an event to Moesif, skips adding new events to the queue to prevent memory overflow. |
config.disable_gzip_payload_decompression
optional Default value: false
|
If set to |
config.max_callback_time_spent
optional Default value: 2000
|
Limits the amount of time in milliseconds to send events to Moesif per worker cycle. |
config.request_max_body_size_limit
optional Default value: 100000
|
Maximum request body size in bytes to log in Moesif. |
config.response_max_body_size_limit
optional Default value: 100000
|
Maximum response body size in bytes to log in Moesif. |
config.debug
optional Default value: false
|
An option if set to true, prints internal log messages for debugging integration issues. |