Skip to content

chore(debug): add gated HTTP tracer + e2e production profile#473

Open
Clap404 wants to merge 13 commits into
mainfrom
chore/debug-tracing
Open

chore(debug): add gated HTTP tracer + e2e production profile#473
Clap404 wants to merge 13 commits into
mainfrom
chore/debug-tracing

Conversation

@Clap404

@Clap404 Clap404 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Adds a self-contained tracing mechanism for ps_eventbus, gated by PrestaShop debug mode (_PS_MODE_DEV_). No behavioural change in prod zips.

What it logs

Each line lands in trace-YYYY-MM-DD.log at the module root (rotates per day).

  • Inbound — every hit to apiHealthCheck / apiShopContent: method, URI, remote IP, Authorization presence, content-type, UA, body (500B).
  • Outbound — every cURL request from HttpClient::exec: target URL, response status, body (500B).
  • CloudSync uploadjobId, shopId, item count, fullSync flag, target URL.
  • Sync pipelinehandleDataSync entry, authorize() result, sendFullSync / sendIncrementalSync branch + row count, "skip upload: data empty" reason.

Gate

HttpClient::isTraceEnabled() returns defined('_PS_MODE_DEV_') && _PS_MODE_DEV_. Helpers no-op when off, so prod zips ship with the helpers compiled in but silent.

e2e production profile

e2e-env/docker-compose.yml:

  • New production profile with prestashop-prod + cloudflared-prod services that mount .config.prod.php over config.php, exposing the shop via the Cloudflare tunnel for real ps-accounts.
  • prestashop-prod carries DEBUG_MODE=true so flashlight flips _PS_MODE_DEV_ on boot (the shared prestashop-base env was being silently overridden by service-level env lists).
  • cloudsync-mock and reverse-proxy constrained to non-production profiles.
  • Dev placeholder version bumped from 0.0.0 to 4.0.0 in ps_eventbus.php / config.xml so CloudSync routes to apiShopContent when mounted from raw source. Makefile's replace_version still rewrites this at zip-build from the git tag, so prod zips are unaffected.

Test plan

  • PHP lint on all touched files.
  • e2e: _PS_MODE_DEV_=false → trace file not created.
  • e2e: DEBUG_MODE=true flips _PS_MODE_DEV_=true → trace file written.
  • e2e: full sync triggered via orchestrator CLI → expected sequence of inbound/outbound/upload/branch lines.
  • Sonar (no new issues since the trace helper extraction in handleDataSync).

🤖 Generated with Claude Code

Clap404 and others added 9 commits June 24, 2026 15:00
`HttpClient::traceLog()` appends to `<module-root>/trace.log` (host-
visible via the e2e bind-mount). Hooked in:
- `HttpClient::exec()` — request URL + response status/body (500B)
- `CloudSyncClient::upload()` — jobId, shopId, items, fullSync, url
- `apiHealthCheck` / `apiShopContent` controllers via
  `HttpClient::traceIncoming()` — method, URI, remote, auth presence,
  ctype, UA, body

TODO comments mark the gate spot for a later env-driven toggle.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CloudSync routes sync requests to apiShopContent only when the module
reports v4+. The dev placeholder `0.0.0` made every sync land on legacy
controllers (apiOrders, apiInfo, …) that this module no longer ships,
so PrestaShop 404'd before our controllers ran — looking like sync
never fired at all.

Makefile's replace_version rewrites this at zip build from the git tag,
so prod zips were unaffected. This commit lives on the debug branch
only; do not merge to main.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add traceLog calls in ApiShopContentService::handleDataSync and
SynchronizationService::sendFullSync / sendIncrementalSync so we can
see where a sync request stops short of reaching CloudSyncClient::upload
(empty data, auth failure, wrong branch).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Trace only writes when PrestaShop debug mode is on. No new config key,
no install/uninstall hook touch, no toggle outside the standard
defines_custom.inc.php flip. Drops the scattered TODO placeholders.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The shared prestashop-base environment carries DEBUG_MODE=true, but
docker-compose `environment` list overrides replace the whole list
instead of merging, so prestashop-prod was inheriting nothing from
base — leaving _PS_MODE_DEV_ at its default false. The in-module
tracer (gated by debug mode) stayed silent unless we patched
defines.inc.php by hand.

Re-add DEBUG_MODE=true to the prestashop-prod environment so
flashlight picks it up on boot.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Default trace destination becomes trace-YYYY-MM-DD.log so each day
gets its own file and old ones can be archived/dropped without
touching the live file. PS_EVENTBUS_TRACE_FILE still wins as an
explicit override.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Hoist the trace lines into three private static helpers (traceEntry /
traceAuthorize / traceBranch) so handleDataSync's cognitive complexity
stays under sonar's 15 threshold (php:S3776).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the production-profile docs from the debug branch — they belong
in a separate PR if we want to ship them, not bundled with the fixes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Clap404 Clap404 self-assigned this Jun 24, 2026
@Clap404 Clap404 added the 🥕 Radis to review Ready to reviewed by 1 peer label Jun 24, 2026
Clap404 and others added 4 commits June 24, 2026 15:06
$data already typed array<mixed>; phpstan flagged the narrowed checks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

🥕 Radis to review Ready to reviewed by 1 peer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant