# Transforming Kong Logs for Ingestion into Your Observability Stack
Damon Sorrentino
As a Solutions Engineer here at Kong, one question that frequently comes across my desk is “how can I transform a Kong logging plugin message into a format that my `insert-observability-stack-here` understands, (e.g., ELK, Loki, Splunk, etc.)?”
If you don’t already have an instance of Kong running in a Kubernetes cluster, connect to your cluster and run the following the commands to get one in seconds.
% kubectl create ns kong
% kubectl apply -f https://bit.ly/kong-ingress-dbless% kubectl get po -n kong -w
NAME READY STATUS RESTARTS AGE
ingress-kong-7c4b795d5d-f2lpt 0/2 ContainerCreating 0 1s
ingress-kong-7c4b795d5d-f2lpt 0/2 Running 0 1s
ingress-kong-7c4b795d5d-f2lpt 1/2 Running 0 10s
ingress-kong-7c4b795d5d-f2lpt 2/2 Running 0 20s
^C
First, create an empty Kubernetes manifest file called, `elastic-common-schema.yaml`.
Next, let’s define our KongPlugin resources. The first plugin we will create is the serverless pre-function. From the Kong plugin docs, a serverless pre-function plugin:
*Runs before other plugins run during each phase. The pre-function plugin can be applied to individual services, routes, or globally.*
The above resource definition creates a `KongPlugin` that executes before the logging phase of each plugin defined in scope. The `kong.ctx.shared.mystuff=kong.log.serialize()` is a single line of Lua code that stores the logging payload into a shared context. From the Kong docs, a shared context is:
*A [Lua] table that has the same lifetime as the current request. This table is shared between all plugins. It can be used to share data between several plugins in a given request.*
The key to doing the transformation is the `custom_fields_by_lua` configuration. From the Kong docs, the `custom_fields_by_lua` is:
*A list of key-value pairs, where the key is the name of a log field and the value is a chunk of Lua code, whose return value sets or replaces the log field value.*
% kubectl create ns myblog
% kubectl apply -f https://bit.ly/k8s-httpbin -n myblog% kubectl get po -n myblog -w
NAME READY STATUS RESTARTS AGE
httpbin-64cdb8c89c-7rxm2 1/1 Running 0 5s
^C
% kubectl logs ingress-kong-7c4b795d5d-pg2c6 -n kong -c proxy -f | grep "@timestamp"
# You should see something similar to the below
{"@timestamp":"1667427319","url":{"original":"/testing/anything"},"http":{"response":{"status_code":200},"request":{"body":{"bytes":93}}},"client_ip":"10.48.0.1"}
{"latencies":{"request":515,"kong":58,"proxy":457},"service":{"host":"httpbin.org","created_at":1614232642,"connect_timeout":60000,"id":"167290ee-c682-4ebf-bdea-e49a3ac5e260","protocol":"http","read_timeout":60000,"port":80,"path":"/anything","updated_at":1614232642,"write_timeout":60000,"retries":5,"ws_id":"54baa5a9-23d6-41e0-9c9a-02434b010b25"},"request":{"querystring":{},"size":138,"uri":"/log","url":"http://localhost:8000/log","headers":{"host":"localhost:8000","accept-encoding":"gzip, deflate","user-agent":"HTTPie/2.4.0","accept":"*/*","connection":"keep-alive"},"method":"GET"},"tries":[{"balancer_latency":0,"port":80,"balancer_start":1614232668399,"ip":"18.211.130.98"}],"client_ip":"192.168.144.1","workspace":"54baa5a9-23d6-41e0-9c9a-02434b010b25","upstream_uri":"/anything","response":{"headers":{"content-type":"application/json","date":"Thu, 25 Feb 2021 05:57:48 GMT","connection":"close","access-control-allow-credentials":"true","content-length":"503","server":"gunicorn/19.9.0","via":"kong/2.2.1.0-enterprise-edition","x-kong-proxy-latency":"57","x-kong-upstream-latency":"457","access-control-allow-origin":"*"},"status":200,"size":827},"route":{"id":"78f79740-c410-4fd9-a998-d0a60a99dc9b","paths":["/log"],"protocols":["http"],"strip_path":true,"created_at":1614232648,"ws_id":"54baa5a9-23d6-41e0-9c9a-02434b010b25","request_buffering":true,"updated_at":1614232648,"preserve_host":false,"regex_priority":0,"response_buffering":true,"https_redirect_status_code":426,"path_handling":"v0","service":{"id":"167290ee-c682-4ebf-bdea-e49a3ac5e260"}},"started_at":1614232668342}
Congratulations, you have transformed a Kong log payload into an Elastic Common Schema format ready for ingestion! This pattern can be used to easily transform Kong logging messages into any format for ingestion with any observability stack.
## Full API Observability Unveiled: Gain Complete Visibility with Konnect
An AI control layer is the governance and observability infrastructure that sits between AI agents and enterprise applications, handling authentication, routing, rate limiting, and auditability to ensure secure, managed access. Unlike traditional in
Together, the following components represent the three layers of the new AI platform: AI Gateway: Kong AI Gateway (including MCP support) controls both GenAI and MCP flow and orchestrates the existing services like Vector Databases, Event Streaming,
Imagine you have a single Service, order-api . You want to apply a strict rate limit to most traffic, but you want to bypass that limit—or apply a different one—if the request contains a specific X-App-Priority: High header. Previously, you had t
How OAuth 2.0 Token Exchange Reshapes Trust Between Services — and Why the API Gateway Is Exactly the Right Place to Enforce It
Modern applications don’t run as a single monolithic. They are composed of services — frontend APIs, backend microservi
Traditional APIs are, in a word, predictable. You know what you're getting: Compute costs that don't surprise you Traffic patterns that behave themselves Clean, well-defined request and response cycles AI APIs, especially anything that runs on LLMs
Running Kong in front of your Solace Broker adds real benefits: Authentication & Access Control – protect your broker from unauthorized publishers. Validation & Transformation – enforce schemas, sanitize data, and map REST calls into event topics.
Architecture Overview
A multicloud DCGW architecture typically contains three main layers.
1\. Konnect Control Plane
The SaaS control plane manages configuration, plugins, and policies. All gateways connect securely to this layer.
2\. Dedicated C
An AI control layer is the governance and observability infrastructure that sits between AI agents and enterprise applications, handling authentication, routing, rate limiting, and auditability to ensure secure, managed access. Unlike traditional in
Together, the following components represent the three layers of the new AI platform: AI Gateway: Kong AI Gateway (including MCP support) controls both GenAI and MCP flow and orchestrates the existing services like Vector Databases, Event Streaming,
Imagine you have a single Service, order-api . You want to apply a strict rate limit to most traffic, but you want to bypass that limit—or apply a different one—if the request contains a specific X-App-Priority: High header. Previously, you had t
How OAuth 2.0 Token Exchange Reshapes Trust Between Services — and Why the API Gateway Is Exactly the Right Place to Enforce It
Modern applications don’t run as a single monolithic. They are composed of services — frontend APIs, backend microservi
Traditional APIs are, in a word, predictable. You know what you're getting: Compute costs that don't surprise you Traffic patterns that behave themselves Clean, well-defined request and response cycles AI APIs, especially anything that runs on LLMs
Running Kong in front of your Solace Broker adds real benefits: Authentication & Access Control – protect your broker from unauthorized publishers. Validation & Transformation – enforce schemas, sanitize data, and map REST calls into event topics.
Architecture Overview
A multicloud DCGW architecture typically contains three main layers.
1\. Konnect Control Plane
The SaaS control plane manages configuration, plugins, and policies. All gateways connect securely to this layer.
2\. Dedicated C
An AI control layer is the governance and observability infrastructure that sits between AI agents and enterprise applications, handling authentication, routing, rate limiting, and auditability to ensure secure, managed access. Unlike traditional in
Together, the following components represent the three layers of the new AI platform: AI Gateway: Kong AI Gateway (including MCP support) controls both GenAI and MCP flow and orchestrates the existing services like Vector Databases, Event Streaming,
Imagine you have a single Service, order-api . You want to apply a strict rate limit to most traffic, but you want to bypass that limit—or apply a different one—if the request contains a specific X-App-Priority: High header. Previously, you had t
How OAuth 2.0 Token Exchange Reshapes Trust Between Services — and Why the API Gateway Is Exactly the Right Place to Enforce It
Modern applications don’t run as a single monolithic. They are composed of services — frontend APIs, backend microservi
Traditional APIs are, in a word, predictable. You know what you're getting: Compute costs that don't surprise you Traffic patterns that behave themselves Clean, well-defined request and response cycles AI APIs, especially anything that runs on LLMs
Running Kong in front of your Solace Broker adds real benefits: Authentication & Access Control – protect your broker from unauthorized publishers. Validation & Transformation – enforce schemas, sanitize data, and map REST calls into event topics.
Architecture Overview
A multicloud DCGW architecture typically contains three main layers.
1\. Konnect Control Plane
The SaaS control plane manages configuration, plugins, and policies. All gateways connect securely to this layer.
2\. Dedicated C