Skip to content

Commit

Permalink
request_id in access_log (#280)
Browse files Browse the repository at this point in the history
* request_id in access_log

* custom fields in access log
  • Loading branch information
Ferdudas97 authored Dec 22, 2021
1 parent 56914eb commit cb000c8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Property
**envoy-control.envoy.snapshot.dynamic-listeners.http-filters.access-log.message-format** | Message format for access logs | "%PROTOCOL% %REQ(:METHOD)% %REQ(:authority)% %REQ(:PATH)% %DOWNSTREAM_REMOTE_ADDRESS% -> %UPSTREAM_HOST%"
**envoy-control.envoy.snapshot.dynamic-listeners.http-filters.access-log.level** | Logging level for access logs | "TRACE"
**envoy-control.envoy.snapshot.dynamic-listeners.http-filters.access-log.logger** | Logger name for access logs | "envoy.AccessLog"
**envoy-control.envoy.snapshot.dynamic-listeners.http-filters.access-log.custom-fields** | Custom fields, which should be included in access logs | "empty map()"
**envoy-control.envoy.snapshot.dynamic-listeners.http-filters.ingress-xff-num-trusted-hops** | Number of trusted hops for ingress filter (refer to [envoy docs](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers.html?highlight=xff_num_trusted_hops#x-forwarded-for)) | 1
**envoy-control.envoy.snapshot.dynamic-listeners.local-reply-mapper.enabled** | Enable or disable creating local reply mapper configuration (refer to [envoy docs](https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/local_reply)) | false
**envoy-control.envoy.snapshot.dynamic-listeners.local-reply-mapper.response-format.text-format** | Text message format with placeholders (refer to [envoy docs](https://www.envoyproxy.io/docs/envoy/latest/configuration/observability/access_log/usage#command-operators)) | ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class AccessLogProperties {
"%DOWNSTREAM_REMOTE_ADDRESS% -> %UPSTREAM_HOST%"
var level = "TRACE"
var logger = "envoy.AccessLog"
var customFields = mapOf<String, String>()
}

class OutgoingPermissionsProperties {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import pl.allegro.tech.servicemesh.envoycontrol.snapshot.resource.listeners.util
class AccessLogFilter(
snapshotProperties: SnapshotProperties
) {
private val listenersFactoryProperties = snapshotProperties.dynamicListeners
private val accessLogTimeFormat = stringValue(listenersFactoryProperties.httpFilters.accessLog.timeFormat)
private val accessLogMessageFormat = stringValue(listenersFactoryProperties.httpFilters.accessLog.messageFormat)
private val accessLogLevel = stringValue(listenersFactoryProperties.httpFilters.accessLog.level)
private val accessLogLogger = stringValue(listenersFactoryProperties.httpFilters.accessLog.logger)
private val accessLog = snapshotProperties.dynamicListeners.httpFilters.accessLog
private val accessLogTimeFormat = stringValue(accessLog.timeFormat)
private val accessLogMessageFormat = stringValue(accessLog.messageFormat)
private val accessLogLevel = stringValue(accessLog.level)
private val accessLogLogger = stringValue(accessLog.logger)

fun createFilter(
accessLogPath: String,
Expand Down Expand Up @@ -64,6 +64,7 @@ class AccessLogFilter(
)
.putFields("upstream_host", stringValue("%UPSTREAM_HOST%"))
.putFields("user_agent", stringValue("%REQ(USER-AGENT)%"))
.putAllFields(accessLog.customFields.mapValues { stringValue(it.value) })
.build()
)
.build()
Expand Down

0 comments on commit cb000c8

Please sign in to comment.