I want to set some metadatas in routes config, and get them in access logs. where I have known the function is https://github.com/envoyproxy/envoy/pull/4862.
however, I can't figure out how to write the yaml file, I have tried many times, but it not works.
admin: access_log_path: /tmp/admin_access.log address: socket_address: { address: 0.0.0.0, port_value: 9901 } static_resources: listeners: - name: listener_0 address: socket_address: { address: 0.0.0.0, port_value: 10000 } filter_chains: - filters: - name: envoy.http_connection_manager config: tracing: operation_name: ingress use_remote_address: true add_user_agent: true generate_request_id: true stat_prefix: ingress_http codec_type: AUTO route_config: name: local_route virtual_hosts: - name: local_service domains: ["*"] routes: - match: { prefix: "/trace/1" } route: { cluster: some_serviceA } metadata: filter_metadata: envoy.http_connection_manager.access_log: test: "this is metadata" http_filters: - name: envoy.router access_log: - name: envoy.http_grpc_access_log config: common_config: grpc_service: envoy_grpc: cluster_name: accesslog_cluster log_name: accesslog clusters: - name: some_serviceA connect_timeout: 0.25s lb_policy: ROUND_ROBIN type: STATIC hosts: [{ socket_address: { address: 127.0.0.1, port_value: 5001 }}] - name: accesslog_cluster connect_timeout: 2s hosts: - socket_address: address: 127.0.0.1 port_value: 18090 http2_protocol_options: {}
But I get nothing from common metadata.
Is there an example to set the metadata into access log?
11 Answer
Dynamic Metadata can be set by filters using the StreamInfo API (https://github.com/envoyproxy/envoy/blob/2e8ddf3f1821816bfb6ae93352fcc5dcddbb058f/include/envoy/stream_info/stream_info.h): setDynamicMetadata.
You can also use Lua to set it: https://www.envoyproxy.io/docs/envoy/latest/configuration/http_filters/lua_filter#config-http-filters-lua-stream-info-dynamic-metadata-wrapper
1ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobG1oaGuBd4COoaawZaSkeqix02absqaRorakecyeq5qckamubrXNZpicm5WowG64zqCqZq%2BZqbVusc2vprI%3D