The MeshAccessLog policy records traffic handled by selected proxies and sends the records
to a file, a TCP log server, or an OpenTelemetry collector. You can record traffic arriving at
a proxy, traffic it sends, or both, using separate policies.
Use this policy to trace a failing request across services, audit which client called which
service, or feed traffic data into an existing log pipeline.
Proxies that no MeshAccessLog selects produce no access logs. HTTP-aware listeners record
requests and TCP listeners record connections, so application requests inside a TCP connection
aren’t separate log events.
With the default HTTP format, a record looks like this:
targetRef selects which proxies log. kind: Mesh means every proxy in the policy’s own
namespace. If the policy is created in kong-mesh-system, it applies to the whole
zone. To log every zone, create the policy on the global control plane. For more
information, see Policy scope.
rules describes what to do with inbound traffic at those proxies. One entry with no
filter logs everything.
Each backends entry is one destination. A rule can list several, and each record is written
to all of them. Put the following fragments under rules[].default for inbound logging, or
to[].default for outbound logging.
The following fragment streams records over a plain TCP connection to a log server beside
the logging proxy. If the server runs elsewhere, use its reachable address and port:
To send records to an OpenTelemetry collector, point backendRef at a
MeshOpenTelemetryBackend resource, which holds the collector
endpoint. Create that resource first, because an unresolved reference doesn’t fall back to
stdout. The following fragment selects it by the label kuma.io/display-name: otel-collector:
Attribute values and the body accept the same placeholders as a log format, but attribute
keys must be static names: lowercase letters and digits, separated by single . or _
characters, starting with a letter (for example, http.request_id). Keys can’t contain
placeholders or start with the reserved otel. prefix, so the control plane rejects keys
such as request-id, Service.Version, or %KUMA_ZONE%. If several MeshOpenTelemetryBackend resources match the labels,
the oldest one wins.
To override the default record format, set file.format or tcp.format. OpenTelemetry uses
body and attributes instead. Formats use command operators such as %START_TIME%, which the
proxy replaces with a value for each request.
Json writes one JSON object per record, which is easier to query when something downstream
parses the logs. The following fragment builds the object from a list of key-value pairs:
Kuma Resource Identifier (KRI) of the workload the logging proxy belongs to.
%KUMA_SOURCE_SERVICE%
Name of the service that is the source of traffic.
%KUMA_DESTINATION_SERVICE%
Name of the service that is the destination of traffic.
%KUMA_SOURCE_ADDRESS%
Address of the logging proxy’s Dataplane, with port 0.
%KUMA_SOURCE_ADDRESS_WITHOUT_PORT%
Address of the logging proxy’s Dataplane.
%KUMA_TRAFFIC_DIRECTION%
Direction of the traffic: INBOUND, OUTBOUND, or UNSPECIFIED.
On inbound records, %KUMA_SOURCE_SERVICE% is unknown, even when an mTLS caller has an
identity, and %KUMA_SOURCE_ADDRESS% and %KUMA_SOURCE_ADDRESS_WITHOUT_PORT% hold the
receiving proxy’s own address. To record the caller, add %DOWNSTREAM_REMOTE_ADDRESS% or the
peer certificate’s SPIFFE URI, %DOWNSTREAM_PEER_URI_SAN%, to the format. To restrict which callers are logged, use a
spiffeID match.
On TCP traffic, HTTP-only operators such as %REQ(X?Y):Z% become - in a plain record and
null in a JSON record. To render an empty string instead, or to drop the key from JSON, set
format.omitEmptyValues: true.
Kong Mesh uses the following format strings by default:
TCP traffic:
[%START_TIME%] %RESPONSE_FLAGS% %KUMA_MESH% %KUMA_SOURCE_ADDRESS_WITHOUT_PORT%(%KUMA_SOURCE_SERVICE%)->%UPSTREAM_HOST%(%KUMA_DESTINATION_SERVICE%) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes
Logging everything gets expensive and noisy in production. To narrow it, use the following
fields:
targetRef: selects which proxies log, with kind: Mesh or kind: Dataplane and labels.
rules or to: selects which of their traffic is logged, by direction.
rules and to accept the following directions:
Field
Direction
Selects on
rules
Inbound: traffic arriving at the selected proxies
Client identity or SNI, using matches
to
Outbound: traffic the selected proxies send
The destination, using to[].targetRef
rules and to are mutually exclusive within one policy. To log both directions, create
two policies. A request may then appear in the caller’s outbound log and the destination’s
inbound log; these are separate observations of the same traffic.
To log only some inbound traffic, add matches to rules. A match selects on one of the
following:
The client’s SPIFFE ID, with Exact or Prefix. A plaintext caller has no certificate
identity, so it can’t match.
The SNI of the TLS connection, with Exact. SNI is the name requested in the TLS handshake,
not the caller.
By default, Kong Mesh issues SPIFFE IDs in the following formats:
spiffe://{mesh}.{zone}.mesh.local/ns/{namespace}/sa/{service-account} on Kubernetes
spiffe://{mesh}.{zone}.mesh.local/workload/{workload} on Universal
Read the domain from the caller’s certificate, or from its issuer’s generated
MeshTrust.spec.trustDomain, and use it after spiffe:// in
rules[].matches[].spiffeID.value. For a custom path template, check
MeshIdentity.spec.spiffeID.path. For example, a domain of payments.eu.mesh.local and the
default Kubernetes path produce the namespace prefix
spiffe://payments.eu.mesh.local/ns/kong-mesh-demo/sa.
The value must be a valid SPIFFE ID, so it can’t end in /. Prefix is a plain string
comparison, so a prefix ending at /ns/kong-mesh-demo also matches kong-mesh-demo-test.
To match only that namespace, end the prefix at /ns/kong-mesh-demo/sa.
The following example logs only the requests that reach orders from workloads in the
kong-mesh-demo namespace of zone zone-1:
Rules apply independently, so a connection that matches several rules is logged to each
rule’s backends. For example, if a catch-all rule writes to stdout and a namespace rule
writes to a collector, requests from that namespace are logged to both.
To log what the selected proxies send, use to, with each entry naming a destination. The
following example logs everything the orders proxies send to payments:
to[].targetRef accepts Mesh for every destination, or MeshService,
MeshExternalService, MeshMultiZoneService, or MeshHTTPRoute to name one. For more
information, see the configuration reference.
Confirm the policy selects the proxy you’re reading and the traffic direction you tested. Use /dev/stdout for the File path.
TCP traffic has no record yet
Close the test connection. The default connection log is written when it ends.
Logs appear locally but not at the collector
Confirm that the backend reference resolves, and that the collector accepts logs at its endpoint.
An identity-filtered rule produces nothing
Compare the peer’s issued SPIFFE URI with the matcher and confirm the connection uses mTLS.
One request produces several records
Overlapping inbound rules, multiple backends, and whether both client and destination proxies log the request.
HTTP fields are empty
Confirm the listener treats the service as HTTP. TCP logging can’t extract HTTP headers or status codes.
When you add headers or query strings to a format, include only the fields you need for
diagnosis. Tokens and personal data in logs inherit the log system’s access and retention
settings.