Prompt
How do I log webhook requests and responses for debugging?
Latest observation
Nov 12, 2026
OpenAI APIWeb search: off
To log webhook requests and responses for debugging, you typically want to capture:
- Request method, URL, headers
- Request body
- Response status, headers, body
- Timing / latency
- Any errors/exceptions
A simple pattern is to add middleware or a wrapper around your webhook handler.
Example: basic logging in Node.js/Express
app.post('/webhook', express.json(), async (req, res) => {
const start = Date.now();
console.log('Webhook request:', {
method: req.method,
path: req.path,
headers: req.headers,
body: req.body,
});
try {
// Your webhook processing here
const result = { ok: true };
console.log('Webhook response:', {
status: 200,
body: result,
durationMs: Date.now() - start,
});
res.status(200).json(result);
} catch (err) {
console.error('Webhook error:', err);
console.log('Webhook response:', {
status: 500,
body: { error: 'Internal Server Error' },
durationMs: Date.now() - start,
});
res.status(500).json({ error: 'Internal Server Error' });
}
});
Better: log all incoming webhook traffic in middleware
app.use((req, res, next) => {
const start = Date.now();
const originalJson = res.json;
res.json = function (body) {
console.log('Webhook completed:', {
method: req.method,
url: req.originalUrl,
requestBody: req.body,
responseBody: body,
statusCode: res.statusCode,
durationMs: Date.now() - start,
});
return originalJson.call(this, body);
};
next();
});
Things to watch out for
- Sensitive data: redact secrets, tokens, passwords, signatures, and PII.
- Large payloads: truncate very large bodies to avoid huge logs.
- Binary data: don’t dump raw buffers unless needed.
- Signature verification: if the provider signs the raw body, log the raw body before parsing if necessary.
Useful debugging tips
- Log a request ID so you can trace a single webhook end-to-end.
- Include timestamps and latency.
- Log both success and failure paths.
- If using a reverse proxy or platform, check its access logs too.
If you tell me your stack (Node, Python, PHP, Rails, etc.) and webhook provider, I can show the exact logging setup for it.