Treblle is a federated API intelligence platform that helps organizations understand their entire API landscape in less than 60 seconds.
The Kong API Gateway plugin for Treblle captures API requests in real time and sends that data to Treblle for monitoring and analysis.
- Understand who your API consumers are, how they're using the API, and when
- Stay secure and compliant at design and run-time
- Automate API governance checks across security, performance, and design
- Debug APIs in real-time with access to request/response payloads
- Generate and update your API documentation in OpenAPI Spec format
- Build your API developer portal with an AI-powered integration assistant
- Test your APIs in a fast and easy way
- And much more
plugin: a plugin executing actions inside Kong before or after a request has been proxied to the upstream API.Service: the Kong entity representing an external upstream API or microservice.Route: The Kong entity represents a way to map downstream requests to upstream services.Consumer: the Kong entity representing a developer or machine using the API. When using Kong, a Consumer only communicates with Kong, which proxies every call to the upstream API.Credential: a unique string associated with a Consumer, also called an API key.Upstream service: refers to your own API/service sitting behind Kong, to which client requests are forwarded.API: a legacy entity representing your upstream services. Deprecated in favor of Services since CE 0.13.0 and EE 0.32.
This plugin can be installed on various environments. Below you'll find installation instructions for:
Choose the option that fits your environment.
- Docker Desktop installed on your Mac
- Git installed
- A Treblle account with an API key and Project ID
git clone https://github.com/Treblle/treblle-kong.git
cd treblle-kongWe'll use the Dockerfile in the plugin folder to build a custom image of Kong with the Treblle plugin enabled:
docker build -t k:v1 .This creates a custom Kong image tagged as "k" with the installed Treblle plugin.
Run Docker Compose to start the Kong container with the plugin:
docker-compose up -dAfter this step, your Kong Gateway should be up and running with the Treblle plugin enabled.
Read the Plugin Reference and the Plugin Precedence sections for more information.
curl -i -X GET http://localhost:8001/plugins/enabledConfigure this plugin on a Service by making the following request on your Kong server:
curl -i -X POST http://localhost:8001/services \
--data "name=httpbin-service" \
--data "url=https://httpbin.org"Configure this plugin on a Route with:
curl -i -X POST http://localhost:8001/services/httpbin-service/routes \
--data "name=httpbin-route-post" \
--data "paths[]=/httpbin" \
--data "methods[]=POST"First, you need to create an API on the Treblle platform to get your API key and Project ID, which will be used to configure the plugin in the next step.
- Visit the Treblle Dashboard to create a new API
- Note your
TREBLLE_API_KEYandTREBLLE_PROJECT_ID
The mask_keywords are the sensitive data fields that will be masked before being sent to Treblle. This important security feature protects sensitive information in your API traffic.
curl -i -X POST http://localhost:8001/services/httpbin-service/plugins \
--data "name=treblle" \
--data "config.api_key=YOUR_TREBLLE_API_KEY" \
--data "config.project_id=YOUR_TREBLLE_PROJECT_ID" \
--data "config.mask_keywords[]=Authorization" \
--data "config.mask_keywords[]=User-Agent" \
--data "config.mask_keywords[]=Cookie"curl -i -X POST http://localhost:8000/httpbin/post \
-H "Content-Type: application/json" \
-d '{"test": "v1final3d", "foo": "bar"}'At this point, you should be able to go to your Treblle dashboard and see the API request that was just made, complete with all the details captured by the plugin.
kong-treblle-sandbox/
│
├── docker-compose.yml
├── kong.conf
├── Dockerfile
└── kong.yml
- Docker installed on your Linux system
- Git installed
- A Treblle account with an API key and Project ID
Create a Dockerfile with the following content. This file builds a custom Kong image with the Treblle plugin installed:
FROM kong:3.4.0
USER root
# Install dependencies
RUN apk add --no-cache \
git \
unzip \
curl \
luarocks
# Install the Treblle plugin
RUN luarocks install --server=http://luarocks.org/manifests/treblle kong-plugin-treblle
# Copy Kong configuration
COPY kong.conf /etc/kong/kong.conf
USER kongCreate a kong.conf file with the following content. This configuration file sets up the database connection and enables the Treblle plugin:
database = on
pg_host = postgres
pg_port = 5432
pg_user = kong
pg_password = kong
pg_database = kong
plugins = bundled,treblleCreate a docker-compose.yml file with the following content. This file orchestrates the containers needed for Kong and its database:
services:
postgres:
image: postgres:13
environment:
POSTGRES_DB: kong
POSTGRES_PASSWORD: kong
POSTGRES_USER: kong
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "kong"]
interval: 30s
timeout: 30s
retries: 3
kong-migration:
image: kong:3.4.0
command: kong migrations bootstrap
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: postgres
KONG_PG_PASSWORD: kong
KONG_PG_USER: kong
depends_on:
postgres:
condition: service_healthy
kong:
build:
context: .
dockerfile: Dockerfile
container_name: kong-treblle
environment:
KONG_DATABASE: postgres
KONG_PG_HOST: postgres
KONG_PG_PASSWORD: kong
KONG_PG_USER: kong
KONG_PLUGINS: bundled,treblle
KONG_PROXY_ACCESS_LOG: /dev/stdout
KONG_ADMIN_ACCESS_LOG: /dev/stdout
KONG_PROXY_ERROR_LOG: /dev/stderr
KONG_ADMIN_ERROR_LOG: /dev/stderr
KONG_ADMIN_LISTEN: 0.0.0.0:8001, 0.0.0.0:8444 ssl
ports:
- "9000:8000" # Proxy port
- "9001:8001" # Admin API port
- "9443:8443"
- "9444:8444"
depends_on:
postgres:
condition: service_healthy
kong-migration:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "kong", "health"]
interval: 10s
timeout: 10s
retries: 10
volumes:
postgres_data:Optionally, create a kong.yml file for declarative configuration. This file provides a way to define services and routes in a declarative manner:
_format_version: "3.0"
services:
- name: test-service
url: https://httpbin.org
routes:
- name: test-route
paths:
- /testmkdir kong-treblle-sandbox
cd kong-treblle-sandboxdocker-compose up -dcurl -i -X POST http://localhost:9001/services \
--data name=httpbin-service \
--data url=https://httpbin.orgcurl -i -X POST http://localhost:9001/services/httpbin-service/routes \
--data "name=httpbin-route" \
--data "paths[]=/test" \
--data "methods[]=POST"curl -i -X POST http://localhost:9001/services/httpbin-service/plugins \
--data "name=treblle" \
--data "config.api_key=YOUR_TREBLLE_API_KEY" \
--data "config.project_id=YOUR_TREBLLE_PROJECT_ID" \
--data "config.mask_keywords[]=Authorization" \
--data "config.mask_keywords[]=API_Key" \
--data "config.mask_keywords[]=Secure-Token"# Test route
curl -X POST http://localhost:9000/test/postIf you want to print Treblle debug logs, set config.debug=true when enabling the plugin:
curl -i -X POST http://localhost:8001/services/httpbin-service/plugins \
--data "name=treblle" \
--data "config.api_key=YOUR_TREBLLE_API_KEY" \
--data "config.project_id=YOUR_TREBLLE_PROJECT_ID" \
--data "config.debug=true"# Check Docker containers
docker-compose ps
# View Kong logs
docker-compose logs kong
# Test route
curl -X POST http://localhost:9000/test/post# Stop and remove containers
docker-compose down
# Remove volumes (optional)
docker-compose down -v| Parameter | Default | Description |
|---|---|---|
| name | The name of the plugin, in this case treblle |
|
| config.api_key | The Treblle SDK token provided by Treblle | |
| config.project_id | The Treblle API ID provided by Treblle | |
| config.connect_timeout | 1000 | Timeout in milliseconds when connecting to Treblle |
| config.send_timeout | 5000 | Timeout in milliseconds when sending data to Treblle |
| config.keepalive | 5000 | Value in milliseconds that defines how long an idle connection will live before being closed |
| config.max_callback_time_spent | 750 | Limiter on how much time to send events to Treblle per worker cycle |
| config.request_max_body_size_limit | 100000 | Maximum request body size in bytes to log |
| config.response_max_body_size_limit | 100000 | Maximum response body size in bytes to log |
| config.event_queue_size | 100000 | Maximum number of events to hold in the queue before sending to Treblle |
| config.debug | false | If set to true, prints internal log messages for debugging integration issues |
| config.enable_compression | false | If set to true, requests are compressed before sending to Treblle |
| config.max_retry_count | 1 | Retry count to send the payload to the Treblle API |
| config.retry_interval | 5 | Retry interval between retries in seconds |
| config.mask_keywords | Masking keywords to be used for the entire payload |
Note: If you already have Treblle installed, you must update the configuration of the existing instance rather than installing Treblle twice.
First and foremost, Star and watch this repository to stay up-to-date.
Also, follow our Blog, and on Twitter.
You can chat with the team and other members on Discord and follow our tutorials and other video material at YouTube.

