Collect Gateway Logs
The Gateway Controller and Gateway Runtime write their logs to stdout and stderr, and Docker stores those logs. You can read them from each container, or start the demonstration logging stack to search them in one place.
The demonstration stack is Fluent Bit, OpenSearch, and OpenSearch Dashboards. It is a starting point, and you can replace it with another logging system.
Set the Log Level and Format
The logging stack parses JSON log lines, so set the format to json. The shipped configs/config.toml already has the three tables below. Do not add them again, because a duplicate table makes the gateway fail to start. Add the format line to each existing table:
[controller.logging]
format = "json" # text or json
[policy_engine.logging]
format = "json"
[router.access_logs]
format = "json"
To change the log level, edit the level value in [controller.logging] and [policy_engine.logging]. The values are debug, info, warn, and error.
The gateway reads config.toml only when it starts. Recreate the containers so that the change takes effect:
docker compose up -d --force-recreate
Start the Logging Stack
Start the gateway with log collection:
docker compose --profile logging up -d
This starts:
- gateway-controller and gateway-runtime, which log to stdout and stderr
- Fluent Bit, which reads the Docker log files, adds the component name, and forwards the logs
- OpenSearch, which stores the logs
- OpenSearch Dashboards, which is the search UI
To run the gateway without that stack:
docker compose up -d
The components still log. Read them with:
docker compose logs gateway-controller
docker compose logs gateway-runtime
The runtime log includes the router access log, with one line for each request.
To stop only the logging stack, leave the gateway running:
docker compose --profile logging stop fluent-bit opensearch-dashboards opensearch
docker compose --profile logging down stops and removes every container in the project, including the gateway. Adding -v also deletes the volumes, which includes the gateway database and the stored logs. Use down -v only when you want to remove the whole gateway and its data.
View Logs in OpenSearch Dashboards
- Open
http://localhost:5601. - Open the menu, then Management → Dashboards Management → Index patterns. If the page offers no Create index pattern button, no logs have arrived yet. Send a request through the gateway and check again.
- Click Create index pattern.
- Enter
gateway-logs-*and click Next step. - Select @timestamp as the time field and click Create index pattern.
- Open the menu, then OpenSearch Dashboards → Discover.
- Select the
gateway-logs-*index pattern. Change the time range if you need more than the last 15 minutes.
Fluent Bit collects the logs of every container on the Docker host and sets the component field to the name of the container, which includes the Compose project name. To show only the gateway, enter a query in the search bar. Use the component.keyword field for wildcards:
| Component | Query |
|---|---|
| Gateway Controller | component.keyword:*gateway-controller* |
| Gateway Runtime (router and policy engine) | component.keyword:*gateway-runtime* |
To filter by level, click Add filter, set Field to level, Operator to is, and Value to error, info, warn, or debug.
Example queries:
error
component.keyword:*gateway-runtime* AND level:error
The log text is in the msg field. To search it, use a query such as:
component.keyword:*gateway-controller* AND msg:*openai*
In Discover, use the gear icon to choose columns, click a column header to sort, and click > on a row to see the JSON. Click Save to keep a search.
Log Requests and Responses
Traffic logging writes one JSON line for each request. It is off by default.
[traffic_logging]
enabled = true
masked_headers = ["authorization", "x-api-key", "x-jwt-assertion"]
The lines go to the container output, so the logging stack picks them up. Headers and bodies appear only if you also enable them under [collector] and [traffic_logging]. Bodies can contain sensitive data, so enable them deliberately.
Use Another Logging System
Point Fluent Bit, or another collector, at the Docker container logs. The gateway components stay the same.
Elastic Stack
Replace OpenSearch with the Elastic Stack:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
environment:
- discovery.type=single-node
- xpack.security.enabled=false
ports:
- "9200:9200"
networks:
- gateway-network
kibana:
image: docker.elastic.co/kibana/kibana:8.11.0
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
ports:
- "5601:5601"
networks:
- gateway-network
depends_on:
- elasticsearch
Update the Fluent Bit output in observability/fluent-bit/fluent-bit.conf:
[OUTPUT]
Name es
Match docker.*
Host elasticsearch
Port 9200
Logstash_Format On
Logstash_Prefix gateway-logs
Grafana Loki
For a lightweight logging solution, add Loki, Promtail, and Grafana. Provide your own Promtail configuration file at observability/promtail/config.yaml.
loki:
image: grafana/loki:latest
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
networks:
- gateway-network
promtail:
image: grafana/promtail:latest
volumes:
- /var/lib/docker/containers:/var/lib/docker/containers:ro
- ./observability/promtail/config.yaml:/etc/promtail/config.yaml:ro
command: -config.file=/etc/promtail/config.yaml
networks:
- gateway-network
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
networks:
- gateway-network
depends_on:
- loki
AWS CloudWatch
Configure Fluent Bit to send logs to CloudWatch:
[OUTPUT]
Name cloudwatch_logs
Match *
region us-east-1
log_group_name /aws/gateway
log_stream_prefix gateway-
auto_create_group true
Provide AWS credentials with environment variables or an IAM role.
Datadog
Use the Datadog Agent:
datadog:
image: datadog/agent:latest
environment:
- DD_API_KEY=${DD_API_KEY}
- DD_LOGS_ENABLED=true
- DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true
- DD_AC_EXCLUDE=name:datadog-agent
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /var/lib/docker/containers:/var/lib/docker/containers:ro
networks:
- gateway-network
Splunk
Configure Fluent Bit to forward to Splunk HEC:
[OUTPUT]
Name splunk
Match *
Host splunk.example.com
Port 8088
Splunk_Token ${SPLUNK_HEC_TOKEN}
TLS On
TLS.Verify Off
Turn TLS verification on for production.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
Fluent Bit exits with Too many open files | The Docker host limits file watchers. Raise fs.inotify.max_user_instances on the Docker host, or run the stack on a host with higher limits. |
The gateway-logs-* index does not exist | Fluent Bit is not running, or no requests reached the gateway. Check docker compose ps and send a request. |
Logs appear in Discover but the level and msg fields are missing | The log format is still text. Set format = "json" in the three tables, as described in Set the Log Level and Format, and recreate the containers. |
| A port is already in use | OpenSearch uses 9200, OpenSearch Dashboards uses 5601, and the Grafana example uses 3000. Change the host side of the port mapping. |
Additional Resources
- Fluent Bit Documentation
- OpenSearch Documentation
- OpenSearch Dashboards User Guide
- Docker Compose Profiles
Was this page helpful?