<commit_before>---
id: page-plugin
title: Plugins - Galileo
header_title: Galileo
header_icon: /assets/images/icons/plugins/galileo.png
redirect_from: /plugins/mashape-analytics/
breadcrumbs:
  Plugins: /plugins
nav:
  - label: Getting Started
    items:
      - label: How it works
      - label: Configuration
---

Logs request and response data to [Galileo][galileo]. Works with any Galileo subscription plan, including the FREE plan with 24h data retention.

----

## How it works

This plugin creates a buffer for each of your APIs on which it is enabled. This buffer accumulates logs of your traffic, serialized as [API Log Format](https://github.com/Mashape/api-log-format) (refered to as *ALFs*) objects for Galileo. Those ALFs are to be send by **batches** to Galileo. When the buffer reaches its configured `batch_size`, or `delay` (see [configuration](#configuration)), the buffer gets emptied and the batch gets queued for sending (in what we refer to as the *sending queue*). This queue will keep sending the batches to Galileo while Kong is running.

It is important to be aware of performance when configuring this plugin. For example, be aware that logging the bodies of your request might slow down your traffic if it is under heavy load. If you are expecting your API's ALFs to be heavy (that would be the case if you chose to log bodies, for example), consider incrementing your sending queue's maximum size (`max_sending_queue_size`), and tweaking your `batch_size` and `delay` configurations.

----

## Configuration

Configuring the plugin is straightforward, you can add it on top of an [API][api-object] (or [Consumer][consumer-object]) by executing the following request on your Kong server:

```bash
$ curl -X POST http://kong:8001/apis/{api}/plugins/ \
    --data "name=mashape-analytics" \
    --data "config.service_token=YOUR_SERVICE_TOKEN"
```

`api`: The `id` or `name` of the API that this plugin configuration will target

parameter                          | description
---                                | ---
`name`                             | The name of the plugin to use, in this case: `mashape-analytics`
`consumer_id`<br>*optional*        | The CONSUMER ID that this plugin configuration will target. This value can only be used if [authentication has been enabled][faq-authentication] so that the system can identify the user making the request.
`config.service_token`             | The service token provided to you by [Galileo][galileo].
`config.batch_size`                | Default: `100`. The size at which the buffer gets emptied and sent to Galileo.
`config.log_body`                  | Default: `false`. Wether or not the request and response bodies should be sent to Galileo.
`config.delay`                     | Default: `2`. The maximum time (in seconds) before the buffer gets sent if no calls are received during that period.
`config.environment`<br>*optional* | A string describing your application environment (for Galileo's dashboards).
`config.max_sending_queue_size`    | Default: `10`. The maximum size (in **MBs**) allowed for the buffer's sending queue. If the sending queue reaches this size, any batch of ALFs will be **discarded** until the queue gets emptied enough.
`config.host`                      | Default: `socket.analytics.mashape.com`. The host where the buffer should send your traffic to. Only change this value if you are running your own installation of Galileo.
`config.port`                      | Default: `80`. The port on which the buffer should connect to. Only change this value if you are running your own installation of Galileo.

**Note**: If you are enabling the `log_body` option, make sure the buffer size never exceeds 1Mb, or the Galileo server will refuse the batch. You can ensure this by setting a lower `batch_size` value.`

[galileo]: https://getgalileo.io/
[api-object]: /docs/latest/admin-api/#api-object
[configuration]: /docs/latest/configuration
[consumer-object]: /docs/latest/admin-api/#consumer-object
[faq-authentication]: /about/faq/#how-can-i-add-an-authentication-layer-on-a-microservice/api?<commit_msg>docs(galileo) document the new Galileo plugin<commit_after>---
id: page-plugin
title: Plugins - Galileo
header_title: Galileo
header_icon: /assets/images/icons/plugins/galileo.png
redirect_from: /plugins/mashape-analytics/
breadcrumbs:
  Plugins: /plugins
nav:
  - label: Getting Started
    items:
      - label: Configuration
  - label: Documentation
    items:
      - label: How it works
      - label: Logging bodies
      - label: FAQ
---

Logs request and response data to [Galileo][galileo], the analytics platform for monitoring, visualizing and inspecting API & microservice traffic.

----

## Configuration

Configuring the plugin is straightforward, you can add it on top of an [API][api-object] (or [Consumer][consumer-object]) by executing the following request on your Kong server:

```bash
$ curl -X POST http://kong:8001/apis/{api}/plugins/ \
    --data "name=galileo" \
    --data "config.service_token=YOUR_SERVICE_TOKEN"
```

`api`: The `id` or `name` of the API that this plugin configuration will target


form parameter      | required     | description
---                 | ---          | ---
`name`              | *required*   | The name of the plugin to use, in this case: `galileo`
`consumer_id`       | *optional*   | The CONSUMER ID that this plugin configuration will target. This value can only be used if [authentication has been enabled][faq-authentication] so that the system can identify the user making the request.
`service_token`     | *required*   | The service token provided to you by [Galileo][galileo].
`environment`       | *optional*   | Slug of your Galileo environment name. None by default.
`log_bodies`        | *optional*   | Capture and send request/response bodies. Defaults to `false`.
`retry_count`       | *optional*   | Number of retries in case of failure to send data to Galileo. Defaults to `10`.
`connection_timeout` | *optional*  | Timeout in seconds before aborting a connection to Galileo. Defaults to `30`.
`flush_timeout`     | *optional*   | Timeout in seconds before flushing the current data to Galileo in case of inactivity. Defaults to `2`.
`queue_size`        | *optional*   | Number of calls to trigger a flush of the buffered data to Galileo. Defaults to `1000`.
`host`              | *optional*   | Host address of the Galileo collector. Defaults to `collector.galileo.mashape.com`
`port`              | *optional*   | Port of the Galileo collector. Defaults to `443`.
`https`             | *optional*   | Use of HTTPs to connect with the Galileo collector. Defaults to `true`.

[galileo]: https://getgalileo.io/
[api-object]: /docs/latest/admin-api/#api-object
[configuration]: /docs/latest/configuration
[consumer-object]: /docs/latest/admin-api/#consumer-object
[faq-authentication]: /about/faq/#how-can-i-add-an-authentication-layer-on-a-microservice/api?

----

## How it works

When enabled, this plugin will create a buffer for each of the APIs it is monitoring. The buffer accumulates the logs of this API's traffic. When the API received no traffic for `flush_timeout` or if the number of calls reaches `queue_size`, the buffer is queued for sending to the Galileo collector.

The Galileo collector then processes your logs before you are able to see your traffic on your Galileo dashboard.

## Logging bodies

This plugin can have a performance impact when the `log_bodies` option is enabled. Buffering the bodies is an expansive operation for Kong and depending on their size, can put pressure on the LuaJIT VM.

The buffer will only allow for bodies up to `20MB`, and for up to `200MB` of data queued for sending at once.

When logging bodies, make sure to configure your `queue_size` so that Kong flushes frequently enough to the Galileo collector.

## FAQ

#### Why can't I see my API logs on my Galileo dashboard?

First of all, check the Kong logs for errors at:

```
{nginx_working_dir}/logs/error.log
```

If you don't see anything useful, you can reload Kong with the `debug` log level by editing your configuration file:

```
error_log logs/error.log debug;
```

Now, you should see logs telling you what the plugin is doing, as well as responses from the Galileo collector. If the collector is able to process your data, it means Galileo is correctly receiving it. You'll want to make sure you have configured your plugin to send your data to the right `environment`.
{'fraction_non_alphanumeric': 0.08818674840839424, 'fraction_numerical': 0.004244282008960151, 'mean_word_length': 3.5387907972177635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1034269', 'n_tokens_mistral': 2408, 'n_tokens_neox': 2285, 'n_words': 1054}