Monitoring means collecting and reviewing evidence about what an application is doing, rather than assuming it is healthy or secure. For an API, that includes checking whether requests succeed and whether capacity meets demand. Logs provide a record of activity, but collecting them is only the first step: they need a strategy for review and alerts. section 4.1 section 9.3
In an ACH application, audit logs help establish normal behavior and investigate possible misuse. A logged error is not necessarily the cause of a current incident: it may have been occurring for months. Comparing an event with the application’s usual behavior makes the record more useful. section 9.3
A practical starting point for API activity monitoring is:
- Record each request in FastAPI middleware, using the request and response to capture the client IP address, user agent, HTTP method, response status, URL, and a message. Centralizing this step avoids repeating logging code in every endpoint. section 9.4
- Add a meaningful business message where needed. A decorator can place that message in request state for the middleware to save; otherwise, the log uses a default message. section 9.4
- Make audit records retrievable through a separate API router. From there, expand logging to business scenarios such as invalid input, and decide how records will be monitored, reviewed, and used for alerts. section 9.5.3 section 9.3
Listing 9.26 The middleware layer for logging
@app.middleware("http") #1
async def log_requests(request: Request, call_next): #2
response = await call_next(request) #3
log_message = getattr(request.state, 'log_message', #4
"Default audit log message") #5
log_record = AuditLogRecord( #5
ip_address=request.client.host, #5
user_agent=request.headers.get #5
➥('user-agent', 'unknown'), #5
http_request=request.method, #5
http_response=response.status_code, #5
url=str(request.url), #5
message=log_message, #5
) #5
logger = AuditLog() #6
logger.log_record(log_record) #6
return response #7
The middleware listing shows where an API response becomes an audit record and which request details are saved. section 9.4
Monitoring unexpected debit activity
Monitoring can also look ahead instead of only recording past API calls. If a company expects less than $10,000 in daily debit activity, a $15,000 batch should prompt attention. A Company Limits component is intended to compare daily totals with a configured limit. Customer alerts, permission to proceed, and rejection of a file load still need to be built out. section 10.7 section 10.8
OpenTelemetry, Prometheus, and Grafana are possible tools for API observability; commercial logging tools are also options. A database-backed audit log is a smaller starting point, not a substitute for a plan to analyze the data and act on it. section 4.1 section 9.3








































