Log API metrics to the local Datadog agent.


Configuration

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

$ curl -X POST http://kong:8001/apis/{api}/plugins \
    --data "name=datadog" \
    --data "config.host=127.0.0.1" \
    --data "config.port=8125"

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

You can also apply it for every API using the http://kong:8001/plugins/ endpoint. Read the Plugin Reference for more information.

parameter default description
name The name of the plugin to use, in this case: datadog.
consumer_id
optional
The CONSUMER ID that this plugin configuration will target. This value can only be used if authentication has been enabled so that the system can identify the user making the request.
config.host
optional
127.0.0.1 The IP address or host name to send data to.
config.port
optional
8125 The port to send data to on the upstream server.
config.metrics
optional
All metrics
are logged
List of Metrics to be logged. Available values are described at Metrics.
config.prefix
optional
kong String to be attached as prefix to metric's name.

Metrics

Plugin currently logs following metrics to the Datadog server.

Metric description namespace
request_count tracks api request kong.<api_name>.request.count
request_size tracks api request's body size in bytes kong.<api_name>.request.size
response_size tracks api response's body size in bytes kong.<api_name>.response.size
latency tracks the time interval between the request started and response received from the upstream server kong.<api_name>.latency
status_count tracks each status code returned as response kong.<api_name>.status.<status>.count and kong.<api_name>.status.<status>.total
unique_users tracks unique users made a request to the api kong.<api_name>.user.uniques
request_per_user tracks request/user kong.<api_name>.user.<consumer_id>.count
upstream_latency tracks the time it took for the final service to process the request kong.<api_name>.upstream_latency
kong_latency tracks the internal Kong latency that it took to run all the plugins kong.<api_name>.kong_latency
status_count_per_user tracks request/status/user kong.<api_name>.user.<customer_id>.status.<status> and kong.<api_name>.user.<customer_id>.status.total

Metric fields

Plugin can be configured with any combination of Metrics, with each entry containing the following fields.

Field description allowed values
name Datadog metric's name Metrics
stat_type determines what sort of event the metric represents gauge, timer, counter, histogram, meter and set
sample_rate
conditional
sampling rate number
customer_identifier
conditional
authenticated user detail consumer_id, custom_id, username
tags
optional
List of tags key[:value]

Metric requirements

  1. by default all metrics get logged.
  2. metric with stat_type as counter or gouge must have sample_rate defined as well.
  3. unique_users metric only works with stat_type as set.
  4. status_count, status_count_per_user and request_per_user work only with stat_type as counter.
  5. status_count_per_user, request_per_user and unique_users must have customer_identifier defined.

Kong Process Errors

This logging plugin will only log HTTP request and response data. If you are looking for the Kong process error file (which is the nginx error file), then you can find it at the following path: {prefix}/logs/error.log

Keep up with the latest features