Enhancement Request: Allow Manual Setting of Resource Name for Requests Failing in before_action #3611
Labels
community
Was opened by a community member
feature-request
A request for a new feature or change to an existing one
Hello ddtrace team,
I'm experiencing an issue with resource naming in traces when requests fail during a before_action callback in a Rails controller. Specifically, if an authentication fails in before_action, the trace's resource is captured as "GET 401" instead of "UserController#show". This behavior prevents us from grouping error responses (401, 403, 500, etc.) by the actual controller action that was called.
Here's a simplified version of my controller setup:
Upon debugging, I found that:
The resource name for successful requests is captured in Datadog::Tracing::Contrib::ActionPack::ActionController::Instrumentation#start_processing.
If an exception is raised in the before_action, start_processing is never called.
The default resource name is then set in Datadog::Tracing::Contrib::Rack::TraceMiddleware#set_request_tags! to a generic "GET 401".
Given this behavior, I propose an enhancement where developers can manually set the trace's resource name earlier in the request lifecycle, perhaps through a custom middleware or directly within the before_action. This would provide greater flexibility in handling traces and allow for more accurate monitoring and debugging of applications.
Would this be considered for a future enhancement? Or is there an existing workaround that I might not be aware of?
The text was updated successfully, but these errors were encountered: