Skip to content

Feature: Add request context providers for long-lived runtimes#96

Open
glensc wants to merge 14 commits intoperftools:mainfrom
glensc:add-request-context
Open

Feature: Add request context providers for long-lived runtimes#96
glensc wants to merge 14 commits intoperftools:mainfrom
glensc:add-request-context

Conversation

@glensc
Copy link
Copy Markdown
Contributor

@glensc glensc commented May 9, 2026

Summary

  • Add a request-context abstraction and provider hook so profiler metadata is captured at request start instead of shutdown
  • Keep the current behavior via a default provider while allowing custom integrations to supply per-request URL, query, env, and server snapshots
  • Document and expose the new configuration in the defaults, example config, autoloader, and README

Details

  • Adds RequestContextInterface, RequestContext, RequestContextProviderInterface, DefaultProvider, and RequestContextFactory
  • Updates Profiler to capture request context on enable() / start() and pass it into ProfilingData on stop()
  • Updates ProfilingData to build metadata from the captured context instead of reading mutable globals at shutdown
  • Adds profiler.request_context_provider config support

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a request-context abstraction so profiler metadata (URL, query/env/server snapshots, timestamps) is captured at profiling start rather than relying on mutable globals at shutdown—improving correctness for long-lived PHP runtimes.

Changes:

  • Add RequestContext* abstractions, a default provider, and a factory to select a configured provider.
  • Update Profiler and ProfilingData to capture/pass request context from enable()/start() through disable()/stop().
  • Update defaults/docs/autoloader and adjust tests to use explicit request-context objects.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/TestCase.php Adds a helper to build RequestContextInterface instances for tests.
tests/ProfilingDataTest.php Stops mutating globals; passes explicit request contexts into ProfilingData.
src/RequestContextFactory.php Creates a request-context provider from config (or default).
src/RequestContext/RequestContextInterface.php Defines the request-context contract (url/query/env/server snapshot).
src/RequestContext/RequestContext.php Implements an immutable request-context value object with HTTP/CLI constructors.
src/RequestContext/Providers/RequestContextProviderInterface.php Defines provider hook for capturing request-scoped metadata.
src/RequestContext/Providers/DefaultProvider.php Default capture implementation using superglobals / CLI argv fallback.
src/ProfilingData.php Builds meta from captured context instead of reading globals at shutdown.
src/Profiler.php Captures context at enable() and passes it into ProfilingData at disable().
README.md Documents long-lived runtime guidance and custom request-context providers.
examples/autoload.php Exposes profiler.request_context_provider example config knob.
config/config.default.php Adds default config entry for profiler.request_context_provider.
autoload.php Requires newly added request-context classes for non-Composer usage.

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

Comment thread src/ProfilingData.php
Comment thread src/RequestContext/RequestContext.php Outdated
Comment thread src/Profiler.php
glensc added 4 commits May 9, 2026 04:24
Provide a concrete request snapshot for HTTP and CLI contexts
Capture HTTP and CLI request metadata from superglobals
Instantiate the default provider when config omits one
Copy link
Copy Markdown

Copilot AI left a comment

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 13 out of 13 changed files in this pull request and generated 4 comments.

Comment thread autoload.php Outdated
Comment thread README.md Outdated
Comment thread config/config.default.php Outdated
'profiler.exclude-env' => array(),
'profiler.exclude-all-env' => false,
// Set this to an implementation of
// Xhgui\Profiler\RequestContext\Providers\RequestContextProviderInterface
Comment thread examples/autoload.php Outdated
Copy link
Copy Markdown

Copilot AI left a comment

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 13 out of 13 changed files in this pull request and generated 6 comments.

Comment thread src/Profiler.php
Comment on lines +155 to +159
$context = $this->requestContext;
$this->requestContext = null;
$this->running = false;

return $profile->getProfilingData($profiler->disable());
if (!$context instanceof RequestContextInterface) {
Comment thread tests/TestCase.php
Comment thread src/RequestContext/RequestContext.php
Comment thread README.md Outdated
Comment thread config/config.default.php Outdated
Comment thread examples/autoload.php Outdated
@glensc glensc force-pushed the add-request-context branch 2 times, most recently from 1c37f9c to 2038836 Compare May 9, 2026 07:09
glensc added 6 commits May 9, 2026 10:09
- Explain how long-lived runtimes should capture request data
- Show the new provider hook in the example configuration
Stop mutating global env and server state in profiling tests
@glensc glensc force-pushed the add-request-context branch from 2038836 to f6a3dc1 Compare May 9, 2026 07:09
@glensc glensc requested a review from Copilot May 9, 2026 07:10
Copy link
Copy Markdown

Copilot AI left a comment

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 15 out of 15 changed files in this pull request and generated 2 comments.

Comment thread tests/ProfilerTest.php
Comment thread tests/TestCase.php
glensc added 2 commits May 9, 2026 10:15
Verify disable still clears state after the backend profiler stops
@glensc glensc force-pushed the add-request-context branch from 29f48da to a3ab8f2 Compare May 9, 2026 07:15
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