Introduction
An Access Log is a single log line written atinfo severity to stderr for every request Tyk Gateway handles, giving you a lightweight, real-time record of individual requests. This is a different mechanism from an API Traffic Log, which also records individual requests but is written to Redis and processed asynchronously by Tyk Pump, carrying richer detail as a result.
Access Logs are generated by the same logger as Tyk Gateway’s Application Log, so their severity, format, and third-party output are all controlled by the same shared settings:
- verbosity: which severity levels are written (must be
infoordebugfor Access Logs to be recorded at all) - format: the structure and timestamp style of each entry
- log output: where logs are sent, for example to a third-party aggregator
Availability
Access Logs are not available on Tyk Cloud.
Enabling Access Logs
Access Logs are disabled by default. Setaccess_logs.enabled to true to turn them on:
- Configuration File
- Environment Variables
Configuration using
tyk.conf:Access Log Content
Each Access Log entry contains:- timestamp
- the log severity (always
info) prefix, always set toaccess-log; this identifies the entry as an Access Log, since Application Log entries are written to the same output but use otherprefixvalues.- a configurable list of key-value pairs giving details of the request (for example API ID or HTTP response status code)
prefix field is always included, whether or not a template is configured.
The full list of available fields that can be included in an access log is here.
Field order is predictable, not arbitrary:
time and level always come first, followed by every other field in alphabetical order.Access Log Templates
You can define an access log template to reduce the size of the access log by including only a subset of the available fields. This is a simple list of field names declared in the Tyk Gateway configuration as atemplate array within the access_logs object.
For example:
- Configuration File
- Environment Variables
Configuration using
tyk.confprefix, which is always included regardless of the template.
MCP-Specific Fields
When the log is generated for a request to an MCP Proxy, MCP-specific fields are added to the access log: These fields are omitted when empty, so non-MCP logs are unaffected. ExamplesMCP tools/call request (success)
MCP tools/call request (success)
When an AI client calls a tool via an MCP Proxy:Key fields:
api_type=mcpidentifies this as an MCP Proxy request.mcp_method=tools/callindicates the JSON-RPC method invoked.mcp_primitive_type=toolandmcp_primitive_name=get_current_weatheridentify the specific tool that was called.
MCP tools/call request (error)
MCP tools/call request (error)
When the upstream MCP server returns a JSON-RPC error:Note that JSON-RPC errors are typically returned with HTTP 200 (as per the JSON-RPC spec). The
mcp_error_code field identifies the error, and response_flag will reflect the gateway classification.Access Log Field Reference
ID of the requested API definition. Present whenever the request matched an API.
Obfuscated or hashed API key used in the request.
Name of the requested API definition. Present whenever the request matched an API.
API type classification. One of
mcp, graphql, oas, or classic. Always present.Circuit breaker state (for example,
OPEN), only present on circuit breaker errors.IP address of the client making the request.
Gateway component that generated the error, only present on error requests.
Upstream address being accessed, only present on upstream or proxy errors.
Hostname of the request.
Time spent in Tyk Gateway’s own processing, separate from the upstream round trip.
Total time taken to process the request, including upstream latency and additional gateway processing.
JSON-RPC error code when the MCP request fails (for example,
-32001 for Authentication required, -32002 for Access denied). Only present when an MCP error occurs.JSON-RPC method called on an MCP Proxy (for example,
tools/call, initialize, resources/read). Only present on MCP Proxy requests.Name of the MCP tool, resource, or prompt that was invoked. Only present on MCP Proxy requests.
MCP primitive type invoked:
tool, resource, or prompt. Only present on MCP Proxy requests.HTTP method used in the request (for example, GET or POST).
Organisation ID of the requested API definition. Present whenever the request matched an API.
The client’s request path, captured before Tyk Gateway applies any path-modifying middleware, such as stripping the API’s listen path. Equal to
path unless something changes the path during processing.URL path of the request.
Protocol used in the request (for example, HTTP/1.1).
Remote address of the client.
Detailed error description in snake_case, only present on error requests.
Error classification code, only present on error requests. See Error Classification.
HTTP response status code.
TLS certificate expiration date in RFC 3339 format, only present on TLS certificate errors.
TLS certificate subject (for example,
CN=api.example.com), only present on TLS certificate errors.The OpenTelemetry trace ID for the request (32-character hex W3C trace ID). Only present when OpenTelemetry is enabled and a trace ID is available. Use this to navigate from an access log entry to the corresponding trace in your observability backend.
Full upstream address, including scheme, host, and path.
Round-trip duration between the gateway sending the request to the upstream service and receiving the response.
HTTP status code returned by the upstream, only present when the upstream responds with a 5XX status.
User agent string provided by the client.
Error Classification
Access logs include a small set of additional fields when a request fails, so you can diagnose problems, such as TLS certificate expiry, connection refusal, or authentication errors, directly from the log without cross-referencing application or API Traffic Logs. Whether a given field appears depends on the specific error; each field’s exact conditions are noted in Access Log Field Reference above. Two fields anchor this classification:response_flag and error_source.
Error classification fields are omitted entirely, not set to an empty string or zero, when they don’t apply. This keeps successful requests and errors that don’t trigger a given field unchanged.
Response Flags
A response flag is a short, fixed code, such asUCF or AKI, that classifies the specific error condition Tyk Gateway encountered while processing the request. response_flag values are shared with Tyk Gateway’s error response customization feature, which uses the same flags to match errors you want to override. See the Flag Reference there for the full list, what each one means, and its typical HTTP status.
Error Source
error_source identifies the Gateway component that generated the error, helping you locate where in the request pipeline the failure occurred. It’s present alongside response_flag on every error entry.
Examples
Upstream connection refused (500)
Upstream connection refused (500)
When the upstream server refuses the TCP connection, the access log shows:Key fields:
response_flag=UCFidentifies the error as an Upstream Connection Failure.error_target=api.backend.com:443shows the specific upstream that refused the connection.upstream_statusis absent because no HTTP response was received from the upstream.
TLS certificate expired (500)
TLS certificate expired (500)
When the upstream’s TLS certificate has expired:The
tls_cert_expiry and tls_cert_subject fields help you identify exactly which certificate needs renewal and when it expired.Circuit breaker open (503)
Circuit breaker open (503)
When a circuit breaker trips for an endpoint, the access log shows:
Rate limited (429)
Rate limited (429)
When a client exceeds the configured rate limit, the access log shows:Note that
error_target is absent for gateway-level errors (authentication, rate limiting, validation) because the request did not reach the upstream.Upstream returned 503 (5XX passthrough)
Upstream returned 503 (5XX passthrough)
When the upstream receives the request but responds with an error status, the access log shows:Key distinction:
error_source=Upstream and upstream_status=503 indicate that the upstream returned an error, unlike a connection failure, where no response was received.Performance Considerations
Enabling access logs introduces some performance overhead:- Latency: Increases consistently by approximately 4%-13%, depending on CPU allocation and configuration.
- Memory Usage: Memory consumption increases by approximately 6%-7%.
- Allocations: The number of memory allocations increases by approximately 5%-6%.
While the overhead of enabling access logs is noticeable, the impact is relatively modest. These findings suggest the performance trade-off may be acceptable depending on the criticality of logging to your application.
Troubleshooting
Distinguishing Connection Errors from Upstream Response Errors
Distinguishing Connection Errors from Upstream Response Errors
A common troubleshooting question is whether the upstream received the request or if the connection itself failed. The error classification fields make this distinction clear: