Skip to content

feat: Report deprecated method usage through logging dispatcher#1270

Merged
rmi22186 merged 5 commits into
developmentfrom
feat/deprecated-method-usage-logging
May 22, 2026
Merged

feat: Report deprecated method usage through logging dispatcher#1270
rmi22186 merged 5 commits into
developmentfrom
feat/deprecated-method-usage-logging

Conversation

@rmi22186
Copy link
Copy Markdown
Member

@rmi22186 rmi22186 commented May 21, 2026

Summary

  • Add a core helper for deprecated API usage that preserves existing console warnings and emits structured logging dispatcher events.
  • Report deprecated usage with code MP_DEPRECATED_METHOD_USAGE and message set to the deprecated method name.
  • Wire existing deprecated method warnings through the helper across core, identity, session, and consent code paths.

Verification

  • Focused Jest reporting logger spec passed.
  • npm run lint passed.

Notes

  • Existing unrelated workspace changes were left unstaged and are not included in this PR.

@rmi22186 rmi22186 force-pushed the feat/deprecated-method-usage-logging branch from 8ffea9d to c44f7e2 Compare May 21, 2026 17:07
@rmi22186 rmi22186 changed the title Report deprecated method usage through logging dispatcher feat: Report deprecated method usage through logging dispatcher May 21, 2026
@rmi22186 rmi22186 requested a review from alexs-mparticle May 21, 2026 17:14
@rmi22186 rmi22186 marked this pull request as ready for review May 21, 2026 17:15
@rmi22186 rmi22186 requested a review from a team as a code owner May 21, 2026 17:15
@cursor
Copy link
Copy Markdown

cursor Bot commented May 21, 2026

PR Summary

Low Risk
Low risk: behavior is limited to how deprecation warnings are reported, with no changes to core identity/session/consent state logic beyond adding optional structured logging.

Overview
Adds a shared logDeprecatedMethodUsage helper that keeps existing deprecation Logger.warning output while also emitting a structured LoggingDispatcher event with new code MP_DEPRECATED_METHOD_USAGE.

Routes several existing deprecated entry points (Consent removeCCPAState, Identity cart APIs, legacy commerce methods like logCheckout/logPurchase/logRefund, SessionManager getSession, and deprecated onUserAlias) through this helper, and includes Jest coverage to verify dispatcher emission and the no-dispatcher case.

Reviewed by Cursor Bugbot for commit b596fbd. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/reporting/deprecatedApiLogger.ts Outdated
Comment on lines +15 to +24
export function logDeprecatedApiUsage(
mpInstance: DeprecatedApiLoggerInstance,
usage: DeprecatedApiUsage
): void {
mpInstance.Logger?.warning(usage.warningMessage);
mpInstance._LoggingDispatcher?.log({
message: usage.methodName,
code: ErrorCodes.MP_DEPRECATED_METHOD_USAGE,
});
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency: We're switching between Deprecated Method vs Deprecated API in this logger, let's stick to one.

Suggested change
export function logDeprecatedApiUsage(
mpInstance: DeprecatedApiLoggerInstance,
usage: DeprecatedApiUsage
): void {
mpInstance.Logger?.warning(usage.warningMessage);
mpInstance._LoggingDispatcher?.log({
message: usage.methodName,
code: ErrorCodes.MP_DEPRECATED_METHOD_USAGE,
});
}
export function logDeprecatedMethodUsage(
mpInstance: DeprecatedMethodLoggerInstance,
usage: DeprecatedMethodUsage
): void {
mpInstance.Logger?.warning(usage.warningMessage);
mpInstance._LoggingDispatcher?.log({
message: usage.methodName,
code: ErrorCodes.MP_DEPRECATED_METHOD_USAGE,
});
}

Comment thread src/mp-instance.ts Outdated
Comment on lines +776 to +778
logDeprecatedApiUsage(self, {
methodName: 'eCommerce.Cart.add()',
warningMessage: generateDeprecationMessage(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe we reference the module in the log so we know where the entry point was?

Suggested change
logDeprecatedApiUsage(self, {
methodName: 'eCommerce.Cart.add()',
warningMessage: generateDeprecationMessage(
logDeprecatedApiUsage(self, {
methodName: 'mPInstance.eCommerce.Cart.add()',
warningMessage: generateDeprecationMessage(

Comment thread src/identity.js Outdated
identityApiData,
mpInstance.Logger
);
tryOnUserAlias(prevUser, newUser, identityApiData, mpInstance);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wy reimport the whole mPInstance?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because logDeprecatedApiUsage takes it as an argument in order to pass both Logger and _LoggingDispatcher. Would you prefer logDeprecatedApiUsage take Logger and _LoggingDispatcher directly?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that would be preferable.

Comment thread src/consent.ts Outdated
'removeCCPAState is deprecated and will be removed in a future release; use removeCCPAConsentState instead'
);
logDeprecatedApiUsage(mpInstance, {
methodName: 'removeCCPAState',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
methodName: 'removeCCPAState',
methodName: 'Consent.removeCCPAState',

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4495494. Configure here.

Comment thread src/mp-instance.ts Outdated
self.Logger.warning(
generateDeprecationMessage(
logDeprecatedMethodUsage(self, {
methodName: 'mPInstance.eCommerce.Cart.add()',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent methodName prefix across structured log entries

Low Severity

The methodName values in the same file use two different prefixes: mPInstance for Cart methods (e.g. mPInstance.eCommerce.Cart.add()) and mParticle for others (e.g. mParticle.logCheckout). mPInstance isn't a public API name or a variable name used in the codebase — it appears to be an internal shorthand. Since these values are emitted as structured log entries for downstream consumption, the inconsistent prefix makes filtering and aggregating deprecation events unreliable.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4495494. Configure here.

@rmi22186 rmi22186 force-pushed the feat/deprecated-method-usage-logging branch from 4495494 to 29be20b Compare May 21, 2026 19:53
@rmi22186 rmi22186 force-pushed the feat/deprecated-method-usage-logging branch from 29be20b to b53796c Compare May 21, 2026 19:56
Comment thread src/reporting/deprecatedMethodLogger.ts
@sonarqubecloud
Copy link
Copy Markdown

@rmi22186 rmi22186 merged commit 2578b9a into development May 22, 2026
30 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants