API / APIGEE Gateway Interview Questions
What is the MessageLogging policy in Apigee and how is it used for audit and debugging?
The MessageLogging policy sends log messages to an external syslog endpoint or Google Cloud Logging during or after request/response processing. Unlike debug trace (which is ephemeral), MessageLogging persists request/response data to an external system for audit trails, debugging, and compliance.
<!-- MessageLogging to Google Cloud Logging --> <MessageLogging name="ML.AuditLog"> <CloudLogging> <LogName>projects/my-project/logs/apigee-api-access</LogName> <Message contentType="application/json">{ "requestId": "{request.header.x-request-id}", "verb": "{request.verb}", "path": "{request.path}", "clientId": "{verifyapikey.VerifyAPIKey.client_id}", "statusCode": "{response.status.code}", "latency": "{target.elapsed.time}", "timestamp": "{system.timestamp}" }</Message> <Labels> <Label> <Key>environment</Key> <Value>{environment.name}</Value> </Label> </Labels> </CloudLogging> </MessageLogging> <!-- Key placement tip: MessageLogging is typically placed in the PostFlow Response AND in the DefaultFaultRule to capture both successful and error responses. The policy executes ASYNCHRONOUSLY by default -- it does NOT block the response to the client. --> <!-- Alternative: syslog (for on-prem logging systems) --> <MessageLogging name="ML.Syslog"> <Syslog> <Message>{request.verb} {request.path} - {response.status.code}</Message> <Host>logs.example.com</Host> <Port>514</Port> <Protocol>UDP</Protocol> </Syslog> </MessageLogging>
More Related questions...