Skip to content

Rename ResponseRecorder to ControllerRecorder#71

Closed
rubenvanassche wants to merge 1 commit into
sampling-and-entry-pointfrom
controller-recorder
Closed

Rename ResponseRecorder to ControllerRecorder#71
rubenvanassche wants to merge 1 commit into
sampling-and-entry-pointfrom
controller-recorder

Conversation

@rubenvanassche

Copy link
Copy Markdown
Member

Summary

Rename ResponseRecorder to ControllerRecorder and adjust the wire format to match. Companion to spatie/laravel-flare#41 which uses the renamed recorder to wrap $dispatch().

Why

The recorder labelled Response was started by DispatchesRoutes::wrapDispatcher after $dispatch() had already returned, so semantically it covered the after-middleware time, not the response. The actual controller execution wasn't wrapped at all. Renaming it to ControllerRecorder and using it to wrap $dispatch() (in laravel-flare) gives an honest controller-execution span; a separate Middleware (after) span (already implemented by RoutingRecorder::recordAfterMiddleware*, just never called from laravel-flare) covers the time after.

Changes

  • Spatie\FlareClient\Recorders\ResponseRecorder\ResponseRecorderSpatie\FlareClient\Recorders\ControllerRecorder\ControllerRecorder
  • RecorderType::Response (response) → RecorderType::Controller (controller)
  • SpanType::Response (php_response) → SpanType::Controller (php_controller) — wire-format change, server-side ingestion needs the matching update
  • Flare::response()Flare::controller()
  • The single-call recordResponse() helper is removed; use recordStart() / recordEnd() around the controller invocation
  • Tracer::gracefullyEndSpans now iterates all unclosed spans instead of walking only the parent chain. An orphaned span (e.g. a View whose recordRendered was skipped because the render threw) is now closed at trace end. Old behavior was leaving such spans open and refusing to send the trace; this hit reliably once Controller started getting popped by the finally in laravel-flare's wrapper
  • SpansRecorder / SpanEventsRecorder: reorder the null guard so phpstan can narrow the type through nameAndAttributes (the instanceof Closure change from the previous commit stays)
  • shared/ExpectTrace::expectLaravelRequestLifecycle now asserts the Controller and Middleware (after) spans when present (skips them on routes that short-circuit before dispatch)
  • UPGRADING.md covers the rename

Caveats

  • Wire format change requires a matching update on the Flare server before this can ship
  • Bundles the gracefullyEndSpans and phpstan-related changes alongside the rename. They could be split out if you'd prefer separate PRs

The recorder previously labelled "Response" actually wrapped the period
between the controller returning and RequestHandled — semantically the
after-middleware phase, not the response. Rename it to ControllerRecorder.
spatie/laravel-flare's DispatchesRoutes trait now uses it to wrap the
actual $dispatch() call.

Wire format change: SpanType::Response (php_response) is now
SpanType::Controller (php_controller). Server-side ingestion needs the
matching update.

Also bundles a few related fixes that surfaced while reworking this:

- Tracer::gracefullyEndSpans now iterates all unclosed spans rather
  than only walking the parent chain. An orphaned span (e.g. a View
  span whose recordRendered call was skipped because the render
  threw) is now closed at trace end instead of blocking the trace
  from being sent.
- SpansRecorder / SpanEventsRecorder: keep the instanceof Closure
  check (added in the previous commit) and reorder the null guard so
  phpstan can follow the type narrowing through nameAndAttributes.
- Lifecycle test rewritten to reflect the new graceful behavior.
- ExpectTrace::expectLaravelRequestLifecycle now also asserts the
  Controller and AfterMiddleware spans when present (skips them on
  routes that short-circuit before dispatch).
- Renames the test directory and rewrites assertions for the new
  recorder shape.
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.

1 participant