fastify-xlogger
logBoundary(params)
Log an external API call with vendor, operation, duration, and outcome.
logBoundary(params)
Logs a single external API call at the boundary.call event. Level is info on success and error on failure. Request context is merged in when provided. For automatic duration capture, prefer createBoundaryLogger.
Signature
fastify.xlogger.logBoundary(params: {
vendor: string
operation: string
externalId?: string
durationMs?: number
statusCode?: number
success?: boolean
retryCount?: number
metadata?: Record<string, unknown>
err?: Error
request?: FastifyRequest
}): void
Params
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
vendor | string | Yes | — | External service name (e.g. "stripe", "sendgrid") |
operation | string | Yes | — | Operation name (e.g. "createCustomer", "sendEmail") |
externalId | string | No | — | External resource ID returned by the vendor |
durationMs | number | No | — | Call duration in milliseconds |
statusCode | number | No | — | HTTP response status code from the vendor |
success | boolean | No | true | Whether the call succeeded |
retryCount | number | No | — | Number of retries attempted |
metadata | object | No | {} | Additional non-sensitive metadata |
err | Error | No | — | Error object on failure |
request | FastifyRequest | No | null | Request context to merge in |
Returns
void
Throws
Error: [xLogger] logBoundary requires a string 'vendor' parameter—vendoris missingError: [xLogger] logBoundary requires a string 'operation' parameter—operationis missing
Examples
Log a successful Stripe call
const start = Date.now();
const customer = await stripe.customers.create({ email: user.email });
fastify.xlogger.logBoundary({
vendor: "stripe",
operation: "createCustomer",
externalId: customer.id,
durationMs: Date.now() - start,
statusCode: 200,
request,
});
Log a failed SendGrid call
try {
await sgMail.send(message);
} catch (err) {
fastify.xlogger.logBoundary({
vendor: "sendgrid",
operation: "sendEmail",
durationMs: Date.now() - start,
success: false,
statusCode: err.response?.status,
err,
request,
});
throw err;
}
See also
- createBoundaryLogger(vendor, operation, request) — timed wrapper that handles duration automatically
- logEvent(params) — log application-level events
AI Context
package: "@xenterprises/fastify-xlogger"
method: fastify.xlogger.logBoundary(params)
use-when: Log a single external API call with vendor, operation, duration, and outcome — use createBoundaryLogger instead when you want automatic duration tracking
params: vendor (required), operation (required), externalId, durationMs, statusCode, success, retryCount, metadata, err, request
returns: void
