feat: add logging option to Braintree payment provider for enhanced d…#32
feat: add logging option to Braintree payment provider for enhanced d…#32
Conversation
…ebugging - Introduced a `logging` option in Braintree options to enable console logging for important operations. - Implemented logging functionality in both BraintreeBase and BraintreeImport classes to capture debug information and error details. - Updated README.md to document the new logging feature.
WalkthroughAdds an optional boolean Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In
`@plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts`:
- Around line 964-967: The error log in createBraintreeCustomer is including
customer.email (PII); update the call to logErrorDetail in braintree-base.ts so
the context uses a non-PII identifier (e.g., customer.id or customerId) instead
of customer.email and keep the errors payload intact (refer to the
logErrorDetail call and the customerResult/errors objects to locate the change).
- Line 825: The debug log in createAccountHolder currently outputs the
customer's email via this.logDebug('createAccountHolder', { customerEmail:
input.context.customer?.email }); which exposes PII; change it to avoid logging
the raw email by either removing the customerEmail field or replacing it with a
non-identifying masked value (e.g., hash or partial mask like first/last char +
****) before calling this.logDebug so the log call no longer contains the full
email.
🧹 Nitpick comments (2)
plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts (1)
146-154: Consider usinglogger.warnfor error details instead oflogger.info.The
logErrorDetailmethod logs error information (including stack traces) atinfolevel. While this is gated behind theloggingoption and meant for debugging, usinglogger.warnorlogger.errorwould make it easier to filter and alert on these entries in log aggregation systems.💡 Proposed change
protected logErrorDetail(operation: string, error: unknown, context?: Record<string, unknown>): void { if (!this.options_.logging) return; const msg = error instanceof Error ? error.message : String(error); const stack = error instanceof Error ? error.stack : undefined; const ctx = context ? ` ${JSON.stringify(context)}` : ''; const stackLine = stack ? ` stack: ${stack}` : ''; - this.logger.info(`[Braintree] ERROR ${operation}: ${msg}${ctx}${stackLine}`); + this.logger.warn(`[Braintree] ERROR ${operation}: ${msg}${ctx}${stackLine}`); }plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-import.ts (1)
88-100: Duplicated logging helpers with inconsistent implementation.The
logDebugandlogErrorDetailmethods are duplicated fromBraintreeBase. Additionally,logErrorDetailhere is missing the stack trace logging that exists in the base class implementation. Consider extracting these to a shared utility function to ensure consistency and reduce duplication.♻️ Add missing stack trace and consider extraction
At minimum, align the implementation with
braintree-base.ts:private logErrorDetail(operation: string, error: unknown, context?: Record<string, unknown>): void { if (!this.options.logging) return; const msg = error instanceof Error ? error.message : String(error); + const stack = error instanceof Error ? error.stack : undefined; const ctx = context ? ` ${JSON.stringify(context)}` : ''; - this.logger.info(`[Braintree Import] ERROR ${operation}: ${msg}${ctx}`); + const stackLine = stack ? ` stack: ${stack}` : ''; + this.logger.info(`[Braintree Import] ERROR ${operation}: ${msg}${ctx}${stackLine}`); }Ideally, extract both helpers to a shared utility:
// utils/logging.ts export const createLogDebug = (logger: Logger, prefix: string, enabled: boolean) => (message: string, context?: Record<string, unknown>) => { if (!enabled) return; const msg = context ? `${message} ${JSON.stringify(context)}` : message; logger.info(`${prefix} ${msg}`); };
…core/braintree-base.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
@currybot-lc review |
🍛 Currybot Review — PR #32feat: add logging option to Braintree payment provider SummaryAdds an opt-in Overall AssessmentClean, well-scoped PR. The pattern is consistent and the coverage across operations is thorough. A few things worth considering: Issues1.
|
Add a feature to help developers debug with more detailed errors in their logs.
loggingoption in Braintree options to enable console logging for important operations.Summary by CodeRabbit