Loading…
Loading…
Describes the internal repository for storing API runtime transaction logs and associated debug trace payloads. Details the data model and methods for
The Runtime Log Repository is a server-side component responsible for persisting API transaction logs and detailed debug traces to a database. It provides a durable storage mechanism for runtime observability data generated by the API gateway.
This component is called by the API runtime after processing a request. It takes structured data describing the transaction—including identifiers, metrics, status codes, and error details—and writes it to the s2r_runtime_log table. For transactions where full payload debugging is enabled, it can also store request/response headers and bodies in a separate s2r_debug_trace table.
The data stored by this repository is the canonical source for features such as the Log Search UI, analytics, and monitoring.
The repository provides two primary methods for data persistence: insertRuntimeLog for summary transaction data and insertDebugTrace for detailed payload traces.
When an API transaction is completed, the runtime calls insertRuntimeLog with various metrics and metadata. The repository generates a unique log ID (id), captures the current timestamp (occurred_at), and executes a SQL INSERT statement into the s2r_runtime_log database table.
If debug tracing is active for the transaction, the runtime subsequently calls insertDebugTrace. This method stores request and response payloads, linking them to the original transaction log via a runtime_log_id. Debug traces have a configurable retention period, after which they are eligible for deletion.
The following diagram illustrates the data flow from the API runtime to the database via the repository.
sequenceDiagram
participant API Gateway Runtime
participant Log Repository
participant Log Database
API Gateway Runtime->>Log Repository: insertRuntimeLog(...)
activate Log Repository
Log Repository->>Log Database: INSERT INTO s2r_runtime_log
Log Database-->>Log Repository: (Success)
Log Repository-->>API Gateway Runtime: logId (UUID)
deactivate Log Repository
alt Debug Trace Enabled
API Gateway Runtime->>Log Repository: insertDebugTrace(...)
activate Log Repository
Log Repository->>Log Database: INSERT INTO s2r_debug_trace
Log Database-->>Log Repository: (Success)
deactivate Log Repository
endTo ensure data integrity and prevent insertion failures, the repository applies transformations to certain fields:
environment, serviceKey, operationKey, and resultCode, null or blank values are replaced with fallback strings such as "unknown" or "error".requestHeaders map provided to insertDebugTrace is serialized into a JSON string. If serialization fails, it defaults to an empty JSON object ({}) to avoid losing the entire trace record.The repository exposes Java methods for use by the API runtime.
insertRuntimeLogThis method inserts a record into the s2r_runtime_log table. It has several overloaded versions to support progressively more detailed logging context. The most comprehensive version accepts all parameters listed below.
Earlier versions exist for backward compatibility and for logging requests that fail before full context (like direction or service version) can be determined.
insertRuntimeLog(correlationId, ...): The base version.insertRuntimeLog(correlationId, direction, ...): A direction-aware overload that adds the direction of the API call (PUBLISH or CONSUME).insertRuntimeLog(..., monitorViolationsJson): A monitor-aware overload that adds a JSON string detailing any detected schema violations.insertRuntimeLog(..., serviceVersionId): A version-aware overload that links the log to a specific service version ID, allowing for per-version traffic analysis.Upon successful insertion, the method returns the UUID generated for the new log record.
insertDebugTracevoid insertDebugTrace(UUID correlationId,
UUID runtimeLogId,
Map<String, String> requestHeaders,
String requestPayload,
String soapRequestPayload,
String soapResponsePayload,
String responsePayload,
int retentionDays)
This method inserts a detailed debug trace into the s2r_debug_trace table. It links the trace to a transaction via correlationId and runtimeLogId. The retentionDays parameter determines the retention_until timestamp, which controls the trace's lifecycle.
IMPORTANT
The retentionDays parameter is treated as a minimum of 1. If a value less than 1 is provided, it will be automatically set to 1 day.
insertRuntimeLog ParametersThe following table details the parameters for the most comprehensive insertRuntimeLog method.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
correlationId | UUID | Yes | — | The unique identifier for the entire transaction. |
direction | String | No | null | The direction of the API call. Must be normalized to PUBLISH or CONSUME. null is used for requests rejected before direction could be determined. |
environment | String | No | "unknown" | The environment in which the transaction occurred. |
serviceKey | String | No | "unknown" | The key identifying the service that was invoked. |
operationKey | String | No | "unknown" | The key identifying the specific operation within the service. |
httpStatus | int | Yes | — | The HTTP status code returned to the API consumer. |
resultCode | String | No | "error" | A platform-specific code indicating the transaction outcome. |
latencyMs | int | Yes | — | The total latency of the request in milliseconds, as measured by the gateway. |
backendLatencyMs | Integer | No | null | The latency of the backend service in milliseconds. |
converterOverheadMs | Integer | No | null | The time spent in request/response conversion logic in milliseconds. |
requestSizeBytes | long | Yes | — | The size of the incoming request payload in bytes. |
responseSizeBytes | Long | No | null | The size of the outgoing response payload in bytes. |
payloadLogged | boolean | Yes | — | A flag indicating if a detailed debug trace was stored for this transaction. |
errorCode | String | No | null | A specific error code if the transaction failed. |
errorMessage | String | No | null | A descriptive error message if the transaction failed. |
monitorViolationsJson | String | No | null | A JSON string of the form {"request":[...],"response":[...]} detailing any schema violations found by the OpenAPI interceptor. null if no violations were found. |
serviceVersionId | UUID | No | null | The ID of the service version (s2r_service_version.id) that handled the call. null if the request did not resolve to a specific route. |
insertDebugTrace Parameters| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
correlationId | UUID | Yes | — | The unique identifier for the transaction, linking it to the runtime log. |
runtimeLogId | UUID | Yes | — | The primary key of the corresponding record in s2r_runtime_log. |
requestHeaders | Map<String, String> | Yes | — | A map of request headers, which will be serialized to a JSONB column. |
requestPayload | String | No | null | The raw request payload body. |
soapRequestPayload | String | No | null | The SOAP request payload, if applicable. |
soapResponsePayload | String | No | null | The SOAP response payload, if applicable. |
responsePayload | String | No | null | The final response payload body sent to the consumer. |
retentionDays | int | Yes | — | The number of days the trace should be retained. A minimum of 1 day is enforced. |
The repository methods ultimately execute SQL INSERT statements.
A call to insertRuntimeLog results in the execution of the following SQL statement. Placeholders (?) are replaced by the method parameters.
insert into s2r_runtime_log (
id, occurred_at, correlation_id, direction, environment, service_key, operation_key, http_status, result_code,
latency_ms, backend_latency_ms, converter_overhead_ms, request_size_bytes, response_size_bytes, payload_logged, error_code, error_message,
monitor_violations, service_version_id
) values (?, now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?::jsonb, ?)
A call to insertDebugTrace results in the execution of the following SQL statement.
insert into s2r_debug_trace (
id, correlation_id, runtime_log_id, request_headers, request_payload, soap_request_payload,
soap_response_payload, response_payload, retention_until, created_at
) values (?, ?, ?, ?::jsonb, ?, ?, ?, ?, ?, ?)
When insertDebugTrace is called, it serializes the requestHeaders map into a JSON string. If this process fails for any reason (e.g., due to unexpected data types), the repository catches the JsonProcessingException and writes an empty JSON object ({}) to the request_headers column in the database. This ensures that the trace record is still saved, even if the headers are lost.
The repository prevents null or empty strings from being inserted for key metadata fields (environment, serviceKey, operationKey, resultCode). If a null or blank value is passed for one of these parameters, a predefined fallback is used (e.g., "unknown"). This ensures that log records are always queryable by these fields and prevents database constraint violations.
serviceVersionId field is critical for distinguishing traffic between different versions of the same service, which can be used for features like per-version analytics.