Skip to content

feat(debug): add more metrics in ThreadDebugState#2282

Open
alexandre-daubois wants to merge 1 commit intophp:mainfrom
alexandre-daubois:observability
Open

feat(debug): add more metrics in ThreadDebugState#2282
alexandre-daubois wants to merge 1 commit intophp:mainfrom
alexandre-daubois:observability

Conversation

@alexandre-daubois
Copy link
Member

I'm working on an observability tool and exposing those metrics would be useful. For each thread, it exposes the current URI being processed, the method, the request start date, the request count and the memory usage.

@dunglas
Copy link
Member

dunglas commented Mar 14, 2026

Could we measure the performance cost of this? Maybe should this feature be put behind a flag?

@henderkes
Copy link
Contributor

Did I just spend 10 hours attempting to figure out why my other branch segfaults on 8.2 debian images and it's not actually related to my branch in the end?

Certainly seems like it...

@alexandre-daubois
Copy link
Member Author

Could we measure the performance cost of this? Maybe should this feature be put behind a flag?

I'll do benchmarks soon and we'll be able to see from there!

@alexandre-daubois
Copy link
Member Author

This is the impact, on already existing benchmark:

  • HelloWorld:
    • main: 32.14us
    • branch: 33.17us
    • Delta: ~1us
  • Echo:
    • main: 29.07us
    • branch: 29.02us
    • Delta: None
  • ** ServerSuperGlobal**:
    • main: 62.15us
    • branch: 63.12us
    • Delta: ~1us
  • ** UncommonHeaders**:
    • main: 59.20
    • branch: 60.12
    • Delta: ~1us

Also, 0 additional allocation is recorded on the hot path. The impact is negligible and the metrics newly exposed would really help better monitor how things are going while processing requests.

@henderkes
Copy link
Contributor

Also, 0 additional allocation is recorded on the hot path. The impact is negligible and the metrics newly exposed would really help better monitor how things are going while processing requests.

Sounds reasonable to me.

Out of curiosity, does anybody know of a per-route monitoring solution that exposes metrics like number of requests, php request duration, etc.? Much like Sentry, Datadog or Tideways, but without all the low-level insights?

Or perhaps that's a good candidate for a go php extension to hook into the runtime, gather the data, hand it to Go and add it to the prometheus metrics?

@alexandre-daubois
Copy link
Member Author

Not that I'm aware of, but an extension for this purpose could indeed be a good idea

@henderkes
Copy link
Contributor

Not that I'm aware of, but an extension for this purpose could indeed be a good idea

Time to implement something. I'll create a proof of concept (I think this may even be implemented entirely in Go) and perhaps we can merge it upstream later.

@henderkes
Copy link
Contributor

henderkes commented Mar 17, 2026

image

That was actually much simpler than I thought, only around 400 lines of code.

sub.domain.com {
	# need to handle this in the module somehow, not sure how yet
	handle /metrics {
		@denied not remote_ip 127.0.0.1 ::1 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
		respond @denied 403
		metrics
	}
	route_metrics {
		path /metrics
		pattern "/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}" "/:uuid"
		pattern "/(\d+)(/|$)" "/:id$2"
		pattern "^/.*" "$0"

		duration_buckets 1 5 10 25 50 100 250 1000
		status_buckets 204 403 418 # everything else falls in a 2XX or 4XX/5XX bucket
	}
}

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.

3 participants