Skip to content

feat(logging): add request duration to log records - #867

Open
josephfusco wants to merge 4 commits into
mainfrom
feat/logging-request-duration
Open

josephfusco wants to merge 4 commits into
mainfrom
feat/logging-request-duration

Conversation

@josephfusco

@josephfusco josephfusco commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Adds request_duration_ms to every log record written during a WPGraphQL request, with the request total on the response events.

Closes #443

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Assisting with adding request duration to log context.

Time the WPGraphQL request lifecycle from the earliest hook (graphql_request_data, falling back to do_graphql_request) until graphql_after_execute. A new RequestDurationProcessor adds the elapsed milliseconds to every record's extra data as request_duration_ms, and the response events add the total to their context so EventManager subscribers receive it.
…nst leaks

Start timing HTTP requests at graphql_process_http_request (before the WPGraphQL Request exists) and clear all timer state there and on graphql_process_http_request_response, so a request that throws before graphql_after_execute cannot leak its timer into later records. graphql_request_data no longer restarts a timer that is already pending. Accept any value in the graphql_request_data callback and fall back to microtime() if hrtime() is unavailable, so the timer can never break a GraphQL request.
…helper

Assert QueryEventLifecycle registers the timer hooks, and test an internal batched graphql() call and LoggingHelper::add_request_duration. Fix two psalm errors: use a float literal in the microtime() fallback so the multiplication is not mixed int/float, and register the graphql_request_data filter by its literal name so psalm's hook checks stop flagging DataDeletionScheduler's action.
Document request_duration_ms, where the timer starts and stops, and how batches and nested graphql() calls behave, in the plugin docs and readme.txt. Use a single RequestTimer::DURATION_KEY for the extra and context key instead of a processor constant plus a string literal, and drop RequestTimer::is_running(), which only the tests used.
@josephfusco josephfusco added this to the WPGraphQL Logging Plugin milestone Oct 30, 2026
@josephfusco josephfusco added [Type] Enhancement A suggestion for improvement of an existing feature [Area] Logging Issues for the WPGraphQL Logging plugin labels Oct 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Plugin Artifacts Ready!

Download from GitHub Actions run

Available plugins:

  • ✅ wpgraphql-logging.zip

See the "Artifacts" section at the bottom of the Actions run page

@josephfusco
josephfusco marked this pull request as ready for review October 30, 2026 19:56
@josephfusco
josephfusco requested review from a team and colinmurphy as code owners October 30, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Logging Issues for the WPGraphQL Logging plugin [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add overall time to logging plugin

1 participant