Skip to content

feat(rokt): add diagnostic logging for setter/selectPlacements timing - #1386

Merged
alexs-mparticle merged 4 commits into
mainfrom
feat/diagnostic-setter-placement-timing
Aug 31, 2026
Merged

alexs-mparticle merged 4 commits into
mainfrom
feat/diagnostic-setter-placement-timing

Conversation

@alexs-mparticle

Copy link
Copy Markdown
Collaborator

Summary

  • Logs each attribute/identity setter call (setUserAttribute, removeUserAttribute, onUserIdentified, onLoginComplete, onLogoutComplete, onModifyComplete) via LoggingService.logDiagnostic() with the affected attribute keys (never values).
  • Logs each selectPlacements dispatch with the full set of placement attribute keys.
  • The two log calls are independent — no in-kit correlation or timing math. The delta between "attributes set" and "placement requested" is computed downstream using the logged timestamp-of-receipt and page URL that ReportingTransport already attaches to every log request.
  • logDiagnostic() ships at severity: "INFO" on the wire (same as log()) but through its own ReportingTransport/RateLimiter instance, so a burst of setter/placement diagnostics can't starve the operational INFO budget shared with page-view/quota logging.
  • Only attribute keys are ever logged — never values — since setter payloads can carry customer PII and this ships over the network logging pipeline.

Context

Relands mparticle-integrations/mparticle-javascript-integration-rokt#130 against this monorepo now that the rokt kit lives here under kits/rokt. That PR targeted development on the old standalone repo; this one targets main here since development doesn't carry kits/rokt and the kit source of truth has moved.

The two commits from #130 didn't cherry-pick cleanly since kits/rokt/src/Rokt-Kit.ts and test/src/tests.spec.ts have diverged since the kit moved (new launcherAttachState.ts, reworked pageViewStorage.ts, etc.), so the logic was manually reapplied onto the current file versions instead.

Example log messages

Rokt Kit: setUserAttribute called [attributeKeys=favoriteColor]
Rokt Kit: onUserIdentified called [attributeKeys=email,firstName,loyaltyTier]
Rokt Kit: selectPlacements dispatched [placementAttributeKeys=email,firstName,loyaltyTier,mpid]

Test plan

  • npm run test (kits/rokt) — 340/340 passing, including new unit tests for diagnosticTiming.ts and integration coverage for every setter/identity call site and the selectPlacements dispatch
  • npm run build (kits/rokt) — pre-existing vault.ts generic-constraint type errors reproduce identically on main — unrelated to this change

Logs each attribute/identity setter call (setUserAttribute, removeUserAttribute,
onUserIdentified, onLoginComplete, onLogoutComplete, onModifyComplete) and each
selectPlacements dispatch independently via LoggingService.logDiagnostic(), so
the delta between "attributes set" and "placement requested" can be computed
downstream from the logged timestamp-of-receipt and page URL that
ReportingTransport already attaches to every log request.

Only attribute keys are ever logged, never values, since setter payloads can
carry customer PII. logDiagnostic() ships at severity INFO on the wire (same
as log()) but through its own ReportingTransport/RateLimiter instance, so a
burst of setter/placement diagnostics can't starve the operational INFO budget
shared with page-view/quota logging.

Relands mparticle-integrations/mparticle-javascript-integration-rokt#130 now
that the rokt kit lives in this monorepo under kits/rokt.
@alexs-mparticle
alexs-mparticle requested a review from a team as a code owner August 31, 2026 16:50
@cursor

cursor Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Adds non-blocking diagnostic INFO logs with keys-only payloads and separate rate limiters; no changes to placement or attribute persistence behavior.

Overview
Adds observability for when user attributes are set vs when placements are requested, so timing issues can be analyzed downstream from log timestamps.

The Rokt kit now emits INFO-level diagnostic logs on attribute/identity setter paths (setUserAttribute, removeUserAttribute, and identity callbacks via handleIdentityComplete) and on each selectPlacements dispatch, logging attribute keys only (never values). A new diagnosticTiming helper builds standardized messages and codes (ATTRIBUTE_SETTER_CALLED, SELECT_PLACEMENTS_DISPATCHED).

LoggingService gains logDiagnostic and logPlacementDiagnostic, each using a dedicated ReportingTransport/RateLimiter so bursts of setter or placement diagnostics cannot exhaust the shared operational logging budget used by log().

Tests cover log entry shape, PII-safe messages, integration at call sites, and independent rate-limit budgets.

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 using default effort 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 809c6f8. Configure here.

Comment thread kits/rokt/src/Rokt-Kit.ts
…gnostics

logDiagnostic() shared a single rate-limit bucket between setter/identity
diagnostics and the selectPlacements dispatch diagnostic. A burst of setter
calls (e.g. setUserAttributes looping per key) could exhaust that budget
before a placement dispatch, silencing placement diagnostics for the rest
of the SPA session.

Gives selectPlacements its own ReportingTransport/RateLimiter via a new
logPlacementDiagnostic() method, mirroring the existing log()/logDiagnostic()
isolation, so a setter burst can no longer starve placement diagnostics.

Also addresses SonarQube findings on the reland commit: marks LoggingService
fields readonly, and switches fetchCalls.length assertions to toHaveLength().
…omments

Both comments just restated what's already explained on the
_diagnosticTransport/_placementDiagnosticTransport field declarations
a few lines above.
Each comment repeated what the test name and the loop/expect right
below it already said.
@sonarqubecloud

Copy link
Copy Markdown

@alexs-mparticle
alexs-mparticle merged commit 65bc3d3 into main Aug 31, 2026
65 checks passed
github-actions Bot pushed a commit that referenced this pull request Sep 3, 2026
# [3.1.0](v3.0.0...v3.1.0) (2026-09-03)

### Bug Fixes

* **braze:** point kit homepage URLs at main ([#1383](#1383)) ([21b2fa8](21b2fa8))
* **ci:** reject wrong-major release tag baseline ([#1389](#1389)) ([9396ba7](9396ba7))
* **kits:** point remaining kit homepage URLs at main ([#1384](#1384)) ([8288cc9](8288cc9))
* **kits:** remove QA path smoke logs ([#1388](#1388)) ([121b00c](121b00c))

### Features

* **rokt:** add diagnostic logging for setter/selectPlacements timing ([#1386](#1386)) ([65bc3d3](65bc3d3))
@mparticle-automation

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 3.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants