Skip to content

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

Merged
glensc merged 14 commits into
perftools:mainfrom
glensc:add-request-context
May 9, 2026
Merged

Feature: Add request context providers for long-lived runtimes#96
glensc merged 14 commits into
perftools: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
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 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 3 times, most recently from 2038836 to f6a3dc1 Compare May 9, 2026 07:09
@glensc glensc requested a review from Copilot May 9, 2026 07:10
@glensc glensc force-pushed the add-request-context branch from f6a3dc1 to f924d85 Compare May 9, 2026 07:13
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
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 3 comments.

Comment thread src/Profiler.php
Comment thread tests/TestCase.php Outdated
Comment thread tests/TestCase.php
@glensc glensc force-pushed the add-request-context branch 2 times, most recently from 417706b to 845d5cd Compare May 9, 2026 11:04
@glensc glensc requested a review from Copilot May 9, 2026 11:04
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 no new comments.

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 src/Profiler.php
Comment thread src/Profiler.php
@glensc glensc force-pushed the add-request-context branch from 4babc8d to d692834 Compare May 9, 2026 11:21
@glensc glensc merged commit 6f3ac51 into perftools:main May 9, 2026
9 checks passed
@glensc glensc deleted the add-request-context branch May 9, 2026 11:44
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