mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 09:28:19 +00:00
feat(freight-api): enrich canonical request log line
Emit the request line as raw JSON on stdout (level/time/logger as fields) instead of through Nest's console logger, whose prefix made it unparsable. Collect data points via logCtx at the flow chokepoints: BaseRepository writes (status changes, creates, deletes), invoice transitions, payment intent lifecycle + outbound payment-service calls, booking/contract entry state, review-note reasons, signatures and OTP verify outcomes.
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
import { HttpService } from "@nestjs/axios";
|
||||
import { AxiosError } from "axios";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
import { logCtx } from "@edr/api-common";
|
||||
import {
|
||||
InitiatePaymentRequest,
|
||||
PaymentIntentSnapshot,
|
||||
@@ -111,6 +112,16 @@ export class PaymentClientService {
|
||||
body?: unknown,
|
||||
): Promise<T> {
|
||||
const url = `${this.baseUrl}${path}`;
|
||||
// Every hop to the payment service lands on the request log line: which
|
||||
// call, how slow, and what it answered. A settle that never happened is
|
||||
// almost always one of these coming back 4xx/5xx or timing out.
|
||||
const startedAt = Date.now();
|
||||
const trace = (extra: Record<string, unknown>) =>
|
||||
logCtx(
|
||||
{ method, path, ms: Date.now() - startedAt, ...extra },
|
||||
{ path: "outbound.payment", mode: "push" },
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
this.http.request<T>({
|
||||
@@ -122,9 +133,11 @@ export class PaymentClientService {
|
||||
: {},
|
||||
}),
|
||||
);
|
||||
trace({ status: response.status });
|
||||
return response.data;
|
||||
} catch (err) {
|
||||
if (err instanceof AxiosError && err.response) {
|
||||
trace({ status: err.response.status });
|
||||
if (err.response.status === 404) throw err;
|
||||
const detail =
|
||||
(err.response.data as { message?: string | string[] })?.message ??
|
||||
@@ -136,6 +149,7 @@ export class PaymentClientService {
|
||||
}
|
||||
const message =
|
||||
err instanceof Error && err.message ? err.message : String(err);
|
||||
trace({ unreachable: true, error: message });
|
||||
this.logger.error(
|
||||
`payment service unreachable (${method} ${path}): ${message}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user