Moesif Tyk API Gateway Plugin

The Tyk plugin for Moesif captures API traffic from Tyk API Gateway and sends to Moesif. This is done via the Tyk Analytics Pump which is an open source component that handles sending API logs to Moesif in an asynchronous way.

For an overview on how the plugin works and use cases, see Tyk + Moesif: the perfect pairing on Tyk’s blog.

Setup

Moesif recommends Tyk Pump v1.1.0 or later for enhanced user tracking and sampling features. The Moesif Tyk integration automatically maps a Tyk Token Alias to a user in Moesif.

  1. Follow Tyk’s setup instructions to get a Tyk Gateway instance running. You will also need to set up a Tyk Pump instance, if you haven’t already. Here is the guide for Ubuntu

  2. Create or update your pump.env to configure the Tyk Analytics Pump and add Moesif as a backend:

TYK_PMP_PUMPS_MOESIF_TYPE=moesif
TYK_PMP_PUMPS_MOESIF_META_APPLICATIONID=your_moesif_application_id

You can find your Application Id from Moesif Dashboard -> Bottom Left Menu -> Installation -> Tyk API Gateway

  1. Ensure analytics is enabled You should ensure detailed analytics recording is enabled in your tyk.env file.
TYK_GW_ENABLEANALYTICS=true
TYK_GW_ANALYTICSCONFIG_ENABLEDETAILEDRECORDING=true

Once your config changes are done, you may need to reload your Tyk Pump and Tyk Gateway instances.

Configuration options

The Tyk Pump for Moesif has a few configuration options:

Parameter Required? Description Environment Variable Name
application_id required Moesif Application Id. Multiple Tyk api_id’s will be logged under the same app id. TYK_PMP_PUMPS_MOESIF_META_APPLICATIONID
request_header_masks optional Mask a specific request header field. Type: String Array [] string TYK_PMP_PUMPS_MOESIF_META_REQUESTHEADERMASKS
request_body_masks optional Mask a specific - request body field. Type: String Array [] string TYK_PMP_PUMPS_MOESIF_META_REQUESTBODYMASKS
response_header_masks optional Mask a specific response header field. Type: String Array [] string TYK_PMP_PUMPS_MOESIF_META_RESPONSEHEADERMASKS
response_body_masks optional Mask a specific response body field. Type: String Array [] string TYK_PMP_PUMPS_MOESIF_META_RESPONSEBODYMASKS
disable_capture_request_body optional Disable logging of request body. Type: Boolean. Default value is false. TYK_PMP_PUMPS_MOESIF_META_DISABLECAPTUREREQUESTBODY
disable_capture_response_body optional Disable logging of response body. Type: Boolean. Default value is false. TYK_PMP_PUMPS_MOESIF_META_DISABLECAPTURERESPONSEBODY
user_id_header optional Field name to identify User from a request or response header. Type: String. TYK_PMP_PUMPS_MOESIF_META_USERIDHEADER
company_id_header optional Field name to identify Company (Account) from a request or response header. Type: String. TYK_PMP_PUMPS_MOESIF_META_COMPANYIDHEADER
bulk_config optional JSON map containing the batch writing trigger configuration.  
bulk_config.api_endpoint optional API Endpoint for when setting up client-side encryption via Moesif Secure Proxy. TYK_PMP_PUMPS_MOESIF_META_BULKCONFIG_APIENDPOINT
bulk_config.event_queue_size optional Specifies the maximum number of events to hold in queue before sending to Moesif. In case of network issues when not able to connect/send event to Moesif, skips adding new events to the queue to prevent memory overflow. Type: int. Default value is 10000. TYK_PMP_PUMPS_MOESIF_META_BULKCONFIG_EVENTQUEUESIZE
bulk_config.batch_size optional Specifies the maximum batch size when sending to Moesif. Type: int. Default value is 200. TYK_PMP_PUMPS_MOESIF_META_BULKCONFIG_BATCHSIZE
bulk_config.timer_wake_up_seconds optional Specifies a time (every n seconds) how often background thread runs to send events to Moesif. TYK_PMP_PUMPS_MOESIF_META_BULKCONFIG_TIMERWAKEUPSECONDSs

Updated: