# What audit and logging components constitute a robust enterprise integration monitoring framework?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Logging Frameworks, Audit Trails

Read it on the site: https://www.forcechallenges.com/interview-questions/what-audit-and-logging-components-constitute-a-robust-enterprise-integration-monitoring-framework

## Answer

**Basics:** Integrations fail silently unless you build visibility. A logging framework captures each inbound and outbound call so support teams can answer "did this message arrive, what did we send, and why did it fail?". Auditing is the compliance side: proving who changed what and when.

**How it works:** Typical components:
1. **Integration log record** (custom object such as `Integration_Log__c`): correlation ID, direction, endpoint/operation, HTTP status, latency, record IDs, status (Success, Failed, Retrying), retry count, and truncated request/response bodies.
2. **Correlation ID** generated at the origin and passed in a header through middleware and back, so one business transaction can be traced across systems.
3. **Error capture** in try/catch blocks around callouts and in Apex REST handlers, storing exception type, message and stack trace.
4. **Alerting and retry**: a scheduled or queueable job re-processes Failed rows with a retry cap; a report/dashboard or Flow notifies owners.
5. **Platform audit sources**: Setup Audit Trail (180 days), Field History/Field Audit Trail, Login History, and Event Monitoring.

**Advanced / deep dive:** A log written with ordinary DML is rolled back when the transaction fails, which is exactly when you need it. Publish a platform event (publish behavior "Publish Immediately") or log from a separate transaction so the record survives. Log volume can reach millions of rows, so archive to Big Objects or an external store and purge with batch jobs. Mask PII and secrets before logging; request bodies often contain regulated data, and log objects need tight sharing. Event Monitoring (paid add-on, formerly part of Shield) provides ApiEvent, RestApiEvent, LoginEvent and Event Log Files for who-called-the-API analysis, but Event Log Files are retained for a limited time (commonly 30 days; verify in current docs). Middleware (MuleSoft and similar) should emit its own logs using the same correlation ID.

**Code / config example:**
```apex
public with sharing class IntegrationLogger {
    // Event published immediately so it survives a rollback of the caller
    public static void log(String corrId, String endpoint, Integer status, Long ms, String err) {
        EventBus.publish(new Integration_Log_Event__e(
            Correlation_Id__c = corrId, Endpoint__c = endpoint,
            Status_Code__c = status, Duration_Ms__c = ms,
            Error__c = err == null ? null : err.left(2000)));
    }
}
// A trigger on Integration_Log_Event__e then inserts Integration_Log__c rows in bulk.
```

**Hidden gotchas & must-remember points:**
- Plain DML logs vanish on rollback; use events or a separate transaction.
- Setup Audit Trail shows only 180 days and only setup changes, not data changes.
- Do not log tokens, passwords or full PII payloads; truncate long text fields (Long Text Area max 131,072 characters).
- Log inserts consume DML and storage; high-volume logging needs archival.
- Event Monitoring is a separately licensed feature in most editions.
- Callout then DML ordering matters: DML before a callout in the same transaction causes "uncommitted work pending".

**Best practice:** Build one shared logging utility with correlation IDs, publish logs out of band, and define retention and alerting from day one.

---
Source: ForceChallenges · last updated 2026-11-02
