Skip to content

feat(profiler): take the profiles of the Blackfire probe in place of its agent - #390

Merged
roxblnfk merged 1 commit into
masterfrom
feat/blackfire-probe
Nov 25, 2026
Merged

roxblnfk merged 1 commit into
masterfrom
feat/blackfire-probe

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

🔍 What was changed

  • Trap takes the profiles of the Blackfire PHP probe (ext-blackfire) on any of its ports, in place of the agent the probe sends them to: no Blackfire account, agent or upload. Point blackfire.agent_socket at Trap, e.g. tcp://127.0.0.1:9912.
  • The profile is built as an XHProf one: wall and CPU time, memory, peak memory and calls; the details show the request and its response code or the command, tags name (from profile_title) and request or command. The format is Blackfire in the UI and the MCP tools.
  • trap()::profile() skips its own profile, and logs the skip to trap.profiler, while the probe profiles the request: two instrumenting profilers count each other's overhead.

How it works

  • The probe sends Blackfire-Query: … and header lines; Trap answers Blackfire-Response: continue=true, the probe sends the profile and closes the connection.
  • The probe takes the keys for the query signature from its agent; with Trap in place of it any query works as long as expires is in the future and signature is not its first parameter: expires=4102444800&signature=trap.
  • On a web request without a query the probe opens a monitoring connection (file-format: BlackfireApm); Trap closes it unanswered and the probe stops asking for 300 s. blackfire.apm_enabled=0 turns these connections off.

Review notes

  • The protocol is described from the traffic between the probe and an agent only; the probe is not shipped, and the docs say Trap is compatible with the probe, not affiliated with Blackfire.
  • BlackfireProbe::isEnabled() is true only while a query is served, false with the probe merely loaded.

Checklist

  • How was this tested:
    • Tested manually: probe 2026.11.3 on PHP 8.3 in Docker, a CLI run and a web request profiled into Trap, the console and /api/events; the skip of trap()::profile() and blackfire.apm_enabled=0 checked on the probe
    • Unit tests added
    • Unit suite run locally: all pass but two ProtobufCasterTest tests of the protobuf caster, untouched here

Documentation

  • New page docs/blackfire.md, plus docs/profiles.md, docs/profiling.md, docs/mcp.md and the README; the trap skill's profiling reference and detect.php.

@roxblnfk
roxblnfk requested a review from a team November 24, 2026 20:28
@github-actions github-actions Bot added enhancement New feature or request tests Changes in the tests labels Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.67901% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.99%. Comparing base (cd278da) to head (6767da2).

Files with missing lines Patch % Lines
...rc/Module/Profiler/Traffic/BlackfireDispatcher.php 92.64% 5 Missing ⚠️
src/Module/Profiler/Blackfire/ProfileBuilder.php 98.85% 1 Missing ⚠️
src/Module/Profiler/Module.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #390      +/-   ##
==========================================
+ Coverage   81.88%   81.99%   +0.11%     
==========================================
  Files         466      468       +2     
  Lines       19719    19881     +162     
==========================================
+ Hits        16146    16301     +155     
- Misses       3573     3580       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roxblnfk
roxblnfk force-pushed the feat/blackfire-probe branch from 023d10b to ad64e70 Compare November 24, 2026 20:42
…of Trap, in place of its agent

feat(profiler): skip `trap()::profile()` while the Blackfire probe profiles the request

The protocol is described from the traffic between the probe and its agent only. The probe checks the query signature with keys the agent hands it, so with Trap in place of the agent any query with a future `expires` and a `signature` after it works, and no Blackfire account is needed. Two instrumenting profilers count each other's overhead, hence the skip, detected by `BlackfireProbe::isEnabled()`.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@roxblnfk
roxblnfk force-pushed the feat/blackfire-probe branch from ad64e70 to 6767da2 Compare November 25, 2026 04:43
@roxblnfk roxblnfk linked an issue Nov 25, 2026 that may be closed by this pull request
@roxblnfk
roxblnfk merged commit a5e4b95 into master Nov 25, 2026
29 checks passed
@roxblnfk
roxblnfk deleted the feat/blackfire-probe branch November 25, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests Changes in the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blackfire support

1 participant