Skip to content

fix: include feed source URL and import ID in log context for easier troubleshooting - #1284

Merged
selul merged 14 commits into
developmentfrom
feat/1278-log-feed-context
Aug 4, 2026
Merged

selul merged 14 commits into
developmentfrom
feat/1278-log-feed-context

Conversation

@lucadobrescu

@lucadobrescu lucadobrescu commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Feedzy logs couldn't tell you which import produced an entry, so users with multiple feeds couldn't trace an error back to its source (#1278, from HelpScout conversation 3380282141). This PR tags every log entry written during an import run with the import's ID, title and source, and surfaces them as badges in the log viewer.

What changed

  • run_job() — now a thin wrapper that sets persistent logger context (import_id, import_title, source) through the existing Feedzy_Rss_Feeds_Log::set_context() and clears it in finally; the original body moved unchanged to run_job_logic(). Every entry written during a run — including fetch-layer errors — is attributed automatically.

  • init_single_feed() — a single broken feed URL used to import 0 items with no error logged (it returned early on unparseable feeds); it now logs the SimplePie error with feed_url, matching the multi-feed path.

  • Logs viewer — each entry gets an import badge (Title (#ID)) and a feed-source badge, falling back to the legacy job_id/source context keys; entries without attribution keys render exactly as before, and the raw JSON context stays visible.

Note

No new translatable strings — the badges reuse existing labels, keeping the generated POT unchanged as the Translations Diff job requires. import_title in the logger context is reserved for job attribution; the post-title mapping template uses the separate import_post_title key.

Also in this PR

  • development merge — brings in the e2e infra upgrade (dev: upgrade e2e infra, add copilot setup and expand test coverage #1288); the branch runs Playwright 1.62.0, wp-env 11.11.0 and e2e-test-utils-playwright 1.51.0, and the merged tests/test-plugin-health.php is updated for the class rename below.

  • WordPress.org Plugin Check fixes (pre-existing, plugin-wide — the check fails every PR until resolved): direct-access ABSPATH guards added to 26 PHP files; unlink() → wp_delete_file() (5 call sites), with the deliberate direct-filesystem fast paths (fclose()/readfile() in the guarded log tail/download) carrying phpcs:ignore annotations matching the file's existing fopen() ones; chosen-sprite@2x.png → chosen-sprite-2x.png (special character in filename), CSS reference updated.

  • Feedzy_Rss_Feeds_Util_SimplePie → Feedzy_Rss_Feeds_Util_Feed — the old filename false-matched Plugin Check's bundled-core-library rule; the class is renamed with the file so the autoloader's naming convention resolves it with no special-casing. Pro has no references to the old name.

  • e2e stability — a test-only mu-plugin (tests/e2e/mu-plugins/feedzy-e2e-youtube-feed-mock.php, mounted via the new .wp-env.json mu-plugins mapping) serves a canned YouTube channel feed through pre_http_request, so the classic-block embed test no longer depends on live YouTube availability (GitHub runner IPs get throttled); the run-now AJAX wait allows 60s because a real import with image sideloads exceeds the 10s default.

Import logging flow

flowchart LR
    A["run_now() /<br/>run_cron()"] --> B["New: run_job()<br/>sets logger context,<br/>clears in finally"]:::added
    B --> C["run_job_logic()<br/>(former run_job body)"]
    C --> D{Feed<br/>parses?}
    D -- Yes --> E[Import items]
    D -- No --> F["Changed: error logged<br/>with feed_url<br/>(was silent for single feeds)"]:::changed
    E --> G[JSONL log with context]
    F --> G
    G --> H["Changed: viewer shows<br/>import + feed badges,<br/>legacy-key fallback"]:::changed

    classDef added fill:#1a7f37,color:#fff,stroke:#116329,stroke-width:3px
    classDef changed fill:#9a6700,color:#fff,stroke:#5c3d00,stroke-width:3px,stroke-dasharray:6 3
Loading

Data changes

New optional keys inside each JSONL log entry's context object (file: wp-content/uploads/feedzy-logs/; written only while an import job runs; old entries are never rewritten):

Key Value Set by
import_id Import post ID run_job() wrapper
import_title Import post title run_job() wrapper
source Raw source meta (URL list or category slug) run_job() wrapper; per-call feed_url overrides it for URL-specific entries

Before → after: {"level":"error","message":"..."} → {"level":"error","message":"...","context":{"import_id":12,"import_title":"My import","source":"https://…/feed.xml"}}

QA instructions

  1. In WP Admin → Feedzy → Import Posts → New Import, create two imports — one with a healthy feed URL and one with a dead URL (e.g. https://example.com/nonexistent-feed.xml) — activate both, then click Run Now on each. Open WP Admin → Feedzy → Settings → Logs tab and filter by Error.
    Expect: each error entry carries a Title (#ID) badge naming the failing import plus its feed URL — the healthy import is never blamed.
  2. On WP Admin → Feedzy → Settings → Logs tab, set the logging level to Debug and save, then Run Now on an import and reload the Logs tab.
    Expect: info/debug entries carry the same import and feed badges as errors.
  3. Create a page containing [feedzy-rss feeds="https://example.com/nonexistent-feed.xml"], view it on the front end, then reload WP Admin → Feedzy → Settings → Logs tab.
    Expect: the fetch error shows a feed-source badge but no import badge (no import job was involved).
  4. With logs from a Feedzy version before this change still present, open the Logs tab.
    Expect: old entries render as before (legacy job_id/source keys shown as badges where present, plain rendering otherwise).

Check before Pull Request is ready:

Closes #1278.

🤖 Generated with Claude Code

…troubleshooting

Scope the logger context to each import run so every entry written while a
job runs carries import_id, import_title and source; log single-feed parse
failures that were previously swallowed; surface the import and feed URL as
badges in the logs viewer with fallbacks for legacy job_id/source entries.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Jul 17, 2026
@lucadobrescu lucadobrescu self-assigned this Jul 17, 2026
@pirate-bot

pirate-bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Plugin build for 9187d22 is ready 🛎️!

Note

You can preview the changes in the Playground

Luca Dobrescu and others added 3 commits July 17, 2026 11:57
The Translations Diff CI job fails on any POT change; render the import ID
as a plain (#ID) suffix and drop the badge tooltips so the badges add no
new strings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add direct-access guards to 26 PHP files; replace unlink() with
wp_delete_file(); annotate the deliberate direct-filesystem fast paths;
rename chosen-sprite@2x.png (special character) and the SimplePie util
file that false-matched the core-library check (class name unchanged,
resolved via an autoloader class map). Also raise the run-now wait
timeout in the e2e helper for slow import runs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread feedzy-rss-feed.php Outdated
Comment on lines +62 to +71
// Class files named differently from the autoloader convention
// (e.g. to avoid matching core-library filename patterns).
$class_map = array(
'Feedzy_Rss_Feeds_Util_SimplePie' => 'includes/util/feedzy-rss-feeds-util-feed.php',
);
if ( isset( $class_map[ $class_to_load ] ) ) {
require_once plugin_dir_path( __FILE__ ) . $class_map[ $class_to_load ];

return true;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can remove this.

…Util_Feed

Match the class name to its file (feedzy-rss-feeds-util-feed.php) so the
autoloader's naming convention resolves it, and drop the special-case
class map from feedzy_rss_feeds_autoload().

Addresses review feedback:
#1284 (review)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds import/feed attribution to logs and improves troubleshooting, alongside Plugin Check cleanup.

Changes:

  • Adds scoped import context and feed parsing error attribution.
  • Displays import/source badges with legacy fallbacks and E2E coverage.
  • Adds access guards, safer file deletion, and asset/class renames.

Reviewed changes

Copilot reviewed 35 out of 36 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/e2e/utils.js Adds log-test helpers and import utilities.
tests/e2e/specs/log-attribution.spec.js Tests log attribution flows.
phpstan-baseline.neon Updates renamed utility references.
includes/views/wordai-view.php Adds direct-access guard.
includes/views/spinnerchief-view.php Adds direct-access guard.
includes/views/openrouter-view.php Adds direct-access guard.
includes/views/openai-view.php Adds direct-access guard.
includes/views/misc-view.php Adds direct-access guard.
includes/views/import-metabox-edit.php Adds direct-access guard.
includes/views/css/chosen.css References renamed sprite.
includes/views/css/chosen-sprite-2x.png Renames high-resolution sprite.
includes/views/amazon-product-advertising-view.php Adds direct-access guard.
includes/views/ai-quota-view.php Adds direct-access guard.
includes/util/feedzy-rss-feeds-util-feed.php Renames the SimplePie utility class/file.
includes/layouts/setup-wizard.php Adds direct-access guard.
includes/layouts/settings.php Adds direct-access guard.
includes/layouts/integration.php Adds direct-access guard.
includes/layouts/header.php Adds direct-access guard.
includes/layouts/feedzy-tutorial.php Adds direct-access guard.
includes/layouts/feedzy-support.php Adds direct-access guard.
includes/layouts/feedzy-subscribe-notice.php Adds direct-access guard.
includes/layouts/feedzy-schedules.php Adds direct-access guard.
includes/layouts/feedzy-pro.php Adds direct-access guard.
includes/layouts/feedzy-logs-viewer.php Renders attribution badges and fallbacks.
includes/layouts/feedzy-license.php Adds direct-access guard.
includes/layouts/feedzy-improve.php Adds direct-access guard.
includes/layouts/feedzy-documentation.php Adds direct-access guard.
includes/feedzy-rss-feeds-feed-tweaks.php Adds direct-access guard.
includes/admin/feedzy-rss-feeds-upgrader.php Adds direct-access guard.
includes/admin/feedzy-rss-feeds-options.php Adds direct-access guard.
includes/admin/feedzy-rss-feeds-log.php Documents direct filesystem operations.
includes/admin/feedzy-rss-feeds-import.php Scopes log context and modernizes file deletion.
includes/admin/feedzy-rss-feeds-actions.php Adds direct-access guard.
includes/abstract/feedzy-rss-feeds-admin-abstract.php Logs single-feed failures with URLs.
form/form.php Adds direct-access guard.
css/settings.css Styles attribution badges.
Comments suppressed due to low confidence (1)

includes/util/feedzy-rss-feeds-util-feed.php:31

  • Renaming this public class removes the autoload target for Feedzy_Rss_Feeds_Util_SimplePie. Any extension that still instantiates the old class will now fail before this new file is loaded, and there is no compatibility alias or autoloader mapping. Please keep the old class name resolvable while avoiding the flagged filename, for example via a bootstrap/autoloader alias to this class.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/e2e/utils.js Outdated
Comment on lines +294 to +309
await page
.locator('tr', { hasText: importName })
.getByRole('button', { name: 'Run Now' })
.click();

const runNowResponse = await page.waitForResponse(
(response) =>
response.url().includes('/wp-admin/admin-ajax.php') &&
response.request().method() === 'POST' &&
response
.request()
.postData()
.includes('action=feedzy&_action=run_now'),
// Importing a feed can take a while (remote fetch + image sideloads).
{ timeout: 60000 }
);
Comment on lines +168 to +170
// Backward compatibility: entries whose context has no attribution keys
// (this one only has a `feed_urls` array) render fine, without a badge row.
const keylessEntry = page.locator('.fz-log-container', {

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 35 out of 36 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

tests/e2e/utils.js:297

  • Register the response waiter before clicking. As written, the AJAX response can arrive after the click is dispatched but before waitForResponse() starts listening, causing this helper to wait 60 seconds and time out even though the import completed. Start the click and waiter together with Promise.all, as is required for event-triggering Playwright actions.

$logger->set_context(
array(
'import_id' => $job->ID,
'import_title' => $job->post_title,
@Soare-Robert-Daniel

Copy link
Copy Markdown
Contributor

@lucadobrescu ask Fable to review the copilot comments

lucadobrescu and others added 2 commits July 27, 2026 16:15
- Use a distinct `import_post_title` context key for the post-title
  mapping template so it no longer clobbers the `import_title` job
  attribution set in run_job()
- Register the run-now AJAX response listener before clicking in
  runImportByName and runFeedImport so fast responses are not missed
- Cover the legacy log-context fallback: a test-only mu-plugin seeds an
  entry carrying only `job_id`/`source` and the spec asserts both
  badges render from those keys

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- @wordpress/env ^9.10.0 -> ^11.11.0 and
  @wordpress/e2e-test-utils-playwright ^0.26.0 -> ^1.51.0, matching the
  versions chosen in #1288
- pin adm-zip 0.5.18 in the lockfile: 0.5.12's broken extractAllToAsync
  makes wp-env 11 exit 0 without starting any container
- raise Playwright actionTimeout to 30s; feedzy blocks fetch remote
  feeds during save/render and exceed the 10s default on CI

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Soare-Robert-Daniel

Copy link
Copy Markdown
Contributor

@lucadobrescu let's solve the merge conflict here

…feed-context

# Conflicts:
#	package-lock.json
#	tests/e2e/utils.js
lucadobrescu and others added 4 commits July 28, 2026 09:20
…ed class

The health test added on development still referenced the old
Feedzy_Rss_Feeds_Util_SimplePie class name, which this branch renamed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
YouTube intermittently throttles GitHub runner IPs, making the
classic-block embed-youtube-video test fail on the feed fetch.
Feedzy fetches feeds through WP_SimplePie_File (the WP HTTP API),
so a pre_http_request filter in a test-only mu-plugin can serve a
canned YouTube Atom feed deterministically.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 39 out of 41 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

tests/e2e/utils.js:306

  • Request.postData() can return null. Since this predicate evaluates every POST response to admin-ajax.php, an unrelated bodyless request can throw before the import response arrives and make the E2E test flaky. Guard it with optional chaining, as runFeedImport() already does.

…cate

Copilot review follow-up: an unrelated bodyless POST to admin-ajax.php
could throw inside the waitForResponse predicate and flake the test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lucadobrescu

Copy link
Copy Markdown
Contributor Author

Re: Copilot review — the suppressed low-confidence note on tests/e2e/utils.js:306 is a valid finding, not a false positive: the waitForResponse predicate in runImportByName() called .postData().includes(...) without a null guard, so an unrelated bodyless POST to admin-ajax.php could throw and flake the test.

Fixed in fb7b4a0 by using the same !!...postData()?.includes(...) pattern already used in runFeedImport().

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 39 out of 41 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (4)

includes/admin/feedzy-rss-feeds-import.php:1633

  • The second run_job() call also clears the scoped context before this debug entry, so this message cannot render the promised feed-source badge. Include source in the explicit context as well.
							'job_id'       => $job->ID,
							'import_id'    => $job->ID,
							'import_title' => $job->post_title,
							'result'       => $result,

includes/admin/feedzy-rss-feeds-import.php:1418

  • This manual-run info entry is emitted before run_job() installs the persistent context, so it gets the import badge but not the source badge. That contradicts the PR's QA expectation that info/debug entries from a run carry both badges. Include the job source explicitly here.
				'job_id'       => $job_id,
				'import_id'    => (int) $job_id,
				'import_title' => isset( $job->post_title ) ? $job->post_title : '',

includes/admin/feedzy-rss-feeds-import.php:1620

  • run_job() clears its persistent context in finally before this completion entry is written, and this explicit context omits source. The resulting cron debug entry has no feed-source badge despite the stated attribution behavior. Add the job source to this context.

This issue also appears on line 1630 of the same file.

						'job_id'       => $job->ID,
						'import_id'    => $job->ID,
						'import_title' => $job->post_title,
						'result'       => $result,

includes/admin/feedzy-rss-feeds-import.php:1650

  • When run_job() throws, its finally block clears the scoped source before this error is logged. Because the replacement context adds only import fields, failures that escape the job logic lose the feed-source badge. Add the source explicitly.
						'job_id'       => $job->ID,
						'import_id'    => $job->ID,
						'import_title' => $job->post_title,
						'error'        => $e->getMessage(),

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 39 out of 41 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

includes/util/feedzy-rss-feeds-util-feed.php:31

  • This rename removes the old autoloadable class entirely. Any extension that constructs or type-checks Feedzy_Rss_Feeds_Util_SimplePie will now fail with “class not found,” even though this is only a patch release. Please retain a compatibility alias and teach the autoloader to load this renamed file when the legacy class is requested; that preserves integrations without restoring the filename that Plugin Check rejects.
    includes/admin/feedzy-rss-feeds-import.php:1685
  • Clearing the singleton context here also discards any context that was already set before the import (for example, request or integration metadata set through the existing public set_context() API). This scope should save the previous context and restore it in finally, rather than resetting all logger state after each job.
			$logger->set_context( array() );

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 39 out of 41 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 39 out of 41 changed files in this pull request and generated no new comments.

…learing it

run_job() reset the logger context to an empty array in its finally
block, discarding any context set through the public set_context() API
before the import ran. Save the previous context and restore it instead,
via a new get_context() accessor.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lucadobrescu

Copy link
Copy Markdown
Contributor Author

Re: the two low-confidence notes in Copilot's review:

includes/admin/feedzy-rss-feeds-import.php — context cleared after import: valid, fixed in 9187d22. run_job() now saves the previous logger context and restores it in finally (new get_context() accessor on the logger, plus a unit test), instead of resetting to an empty array. run_job() was the only internal set_context() caller and the pre-job context is empty on every existing code path, so behavior only changes for external code that set context before an import — which is exactly the case being fixed.

includes/util/feedzy-rss-feeds-util-feed.php — missing BC alias for Feedzy_Rss_Feeds_Util_SimplePie: deliberate, not fixing. The original Plugin Check fix (697a98a) kept the legacy class name working via an autoloader class map; @Soare-Robert-Daniel asked for that map's removal in review, which is why 69fc9f7 renamed the class to match the file. The class is an internal SimplePie wrapper — nothing in Feedzy Pro or this repo references the old name — so we're treating the rename as safe. Robert, if you'd rather keep BC here, a guarded class_alias + autoloader mapping is a 3-line follow-up; say the word.

@selul
selul merged commit 70fb964 into development Aug 4, 2026
10 checks passed
@selul
selul deleted the feat/1278-log-feed-context branch August 4, 2026 09:34
selul added a commit that referenced this pull request Aug 4, 2026
PHPStan flagged includes/admin/feedzy-rss-feeds-import.php:1449 after #1284
merged into development. $job is already guarded by the ! $job bail above,
and the other call sites in this file read $job->post_title directly.
@pirate-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 5.2.7 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants