-
Notifications
You must be signed in to change notification settings - Fork 1.2k
TT-16439 AccessLogs 5XX improvement #7712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
API Changes --- prev.txt 2026-01-30 12:56:53.917821433 +0000
+++ current.txt 2026-01-30 12:56:43.182883227 +0000
@@ -6030,18 +6030,29 @@
//
// Template Options:
//
- // - `api_key` will include they obfuscated or hashed key.
- // - `client_ip` will include the ip of the request.
+ // - `api_key` will include the obfuscated or hashed key.
+ // - `circuit_breaker_state` will include the circuit breaker state when applicable.
+ // - `client_ip` will include the IP of the request.
+ // - `error_source` will include the source of an error (e.g., ReverseProxy).
+ // - `error_target` will include the target that caused an error.
// - `host` will include the host of the request.
+ // - `latency_gateway` will include the gateway processing latency.
+ // - `latency_total` will include the total latency of the request.
// - `method` will include the request method.
+ // - `org_id` will include the organization ID.
// - `path` will include the path of the request.
// - `protocol` will include the protocol of the request.
// - `remote_addr` will include the remote address of the request.
- // - `upstream_addr` will include the upstream address (scheme, host and path)
+ // - `response_code_details` will include detailed error description for 5XX responses.
+ // - `response_flag` will include the error classification flag (e.g., URT, UCF, TLE).
+ // - `status` will include the response status code.
+ // - `tls_cert_expiry` will include the TLS certificate expiry date when applicable.
+ // - `tls_cert_subject` will include the TLS certificate subject when applicable.
+ // - `trace_id` will include the OpenTelemetry trace ID when tracing is enabled.
+ // - `upstream_addr` will include the upstream address (scheme, host and path).
// - `upstream_latency` will include the upstream latency of the request.
- // - `latency_total` will include the total latency of the request.
+ // - `upstream_status` will include the upstream response status code for 5XX responses.
// - `user_agent` will include the user agent of the request.
- // - `status` will include the response status code.
Template []string `json:"template"`
}
AccessLogsConfig defines the type of transactions logs printed to stdout.
@@ -8313,6 +8324,10 @@
GetDefinition will return a deep copy of the API definition valid for the
request.
+func GetErrorClassification(r *http.Request) *errors.ErrorClassification
+ GetErrorClassification retrieves the error classification from the request
+ context. Returns nil if no error classification has been set.
+
func GetOASDefinition(r *http.Request) *oas.OAS
GetOASDefinition will return a deep copy of the OAS API definition valid for
the request.
@@ -8321,6 +8336,10 @@
func SetDefinition(r *http.Request, s *apidef.APIDefinition)
SetDefinition sets an API definition object to the request context.
+func SetErrorClassification(r *http.Request, ec *errors.ErrorClassification)
+ SetErrorClassification sets the error classification for the request
+ context. This is used to store structured error information for access logs.
+
func SetOASDefinition(r *http.Request, s *oas.OAS)
SetOASDefinition sets an OAS API definition object to the request context.
@@ -8367,6 +8386,8 @@
SelfLooping
// RequestStartTime holds the time when the request entered the middleware chain
RequestStartTime
+ // ErrorClassification holds structured error information for access logs
+ ErrorClassification
// MCPRouting indicates the request came via MCP JSON-RPC routing
MCPRouting
) |
|
This pull request introduces a comprehensive error classification system to improve the observability of 5xx and other upstream errors in access logs. It replaces generic error codes with structured, detailed information, enabling operators to quickly diagnose the root cause of failures such as TLS issues, connection timeouts, or circuit breaker events. Files Changed AnalysisThe changes are centered around a new
Architecture & Impact Assessment
Error Classification FlowsequenceDiagram
participant Client
participant Gateway as Tyk Gateway
participant Upstream
Client->>Gateway: Request
Gateway->>Upstream: Forward Request
alt Upstream Connection Fails in reverse_proxy.go
Upstream--xGateway: Error (e.g., syscall.ECONNREFUSED)
Gateway->>Gateway: ClassifyUpstreamError(err)
Gateway->>Gateway: ctx.SetErrorClassification(req, classification)
Gateway-->>Client: 502 Bad Gateway
else Upstream Responds with 5xx in handler_success.go
Upstream-->>Gateway: HTTP 503 Service Unavailable
Gateway->>Gateway: ClassifyUpstreamResponse(503)
Gateway->>Gateway: ctx.SetErrorClassification(req, classification)
Gateway-->>Client: 503 Service Unavailable
end
Note over Gateway: Request finishes, logging middleware runs
Gateway->>Gateway: middleware.go: GetErrorClassification(req)
Gateway->>Gateway: accesslog/record.go: WithErrorClassification(ec)
Gateway->>Gateway: Write structured access log with error-details
Scope Discovery & Context Expansion
This dual approach ensures that both types of upstream failures are correctly captured and logged with the new structured error details. Metadata
Powered by Visor from Probelabs Last updated: 2026-01-30T12:59:14.807Z | Triggered by: pr_updated | Commit: 32fb79e 💡 TIP: You can chat with Visor using |
Security Issues (3)
Architecture Issues (1)
✅ Performance Check PassedNo performance issues found – changes LGTM. Quality Issues (1)
Powered by Visor from Probelabs Last updated: 2026-01-30T12:59:17.778Z | Triggered by: pr_updated | Commit: 32fb79e 💡 TIP: You can chat with Visor using |
/visor ask RecordAccessLog is called from (e *ErrorHandler) HandleError, which uses logreq. |
|



Description
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
Ticket Details
TT-16439
Generated at: 2026-01-30 12:56:08