envoyproxy / envoyproxy/envoy

[Feature Request] Support environment variables in log formatting

Open
#12,767 5 comments 15 reactions 1 assignee Claimed by @Shikugawa View on GitHub
area/access_log enhancement help wanted
Dominant language
C++
Stars
28.9k
Forks
5.6k
Avg merge
1d 22h
Merged PRs (30d)
430

Description

Adding a request to support environment variables in our log formatting, perhaps using the `ENV` key (similar to `REQ`, `RESP`, etc). `HOSTNAME` is an already supported keyword pulled from the environment--this feature would expand on that.

Some values are known ahead of time and can be baked into the log format. However, the use case would be for logging runtime values (host IP, AZ, etc) that are only known when the container is deployed. Our current solution is to parse the config file, injecting selected envvars, etc before booting the service.

```yaml
access_log:
- name: envoy.access_loggers.file
config:
path: /dev/stdout
json_format:
hostname: "%HOSTNAME%"
method: "%REQ(:METHOD)%"
app_version: "%ENV(APP_VERSION)%"
private_ip: "%ENV(PRIVATE_IP)%"
region: "%ENV(REGION)%"
```

```
export APP_VERSION=0.1.0
export PRIVATE_IP=192.168.1.5
export REGION=us-east-1
envoy -c envoy.yaml

#=> {
"hostname":"macbook-pro",
"method":"GET",
"app_version": "0.1.0",
"private_ip": "192.168.1.5",
"region": "us-east-1"
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.