appsignal-elixir-phoenix icon indicating copy to clipboard operation
appsignal-elixir-phoenix copied to clipboard

Unable to instrument requests in endpoint plugs, only in router

Open tombruijn opened this issue 11 months ago • 1 comments

Background

Our Phoenix instrumentation listens for events fro mthe Phoenix router here: https://github.com/appsignal/appsignal-elixir-phoenix/blob/abfa9e5654fa329a150b8635f0ea4f9416423e51/lib/appsignal_phoenix/event_handler.ex#L7-L18

Support issues

In support issues like https://github.com/appsignal/support/issues/310 and example code in our test setups, adding a plug to the endpoint of an app that call AppSignal will not work. At time of the request execution in the endpoint no AppSignal span is active. Only when it reaches the router in the endpoint, does our instrumentation trigger and creates a span to modify.

In the case of https://github.com/appsignal/support/issues/310, the solution is to move the plug that sets the namespace to the router. Not sure if that's ideal for all apps. It also means we do not instrument any of the other plugs that are run before the router and their impact on the performance of a request.

This worked in older versions of appsignal_phoenix

Previously, it was possible to modify the root span in plugs added to the endpoint. In version 2.2.1 of the appsignal_phoenix package the instrumentation wasn't telemetry only and the AppSignal instrumentation activates earlier than it does now. This seems like the change that broke it: https://github.com/appsignal/appsignal-elixir-phoenix/commit/2fe4d489149e7a343463eb87e3e64be74a4599c1#diff-114ccb169147f314dbcc8a3c277af03dc9cec1b2977d24ebacb6a3bfa5b08c1f

Next steps

I've found no other telemetry events in Phoenix or Plug to listen to, so that we can start instrumenting earlier. Does anyone else have any ideas how start instrumenting earlier in the request lifetime? Do we want to keep some of the older instrumentation logic? If we decide the current behavior is fine, we need to document this in our docs.

tombruijn avatar Apr 03 '24 09:04 tombruijn

  • This issue has not had any activity in 14 days. Please provide a status update if it is still relevant. Closed it if it is no longer relevant. Or move it to another column if it's blocked or requires another look at it. - (More info)

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] avatar May 07 '24 08:05 backlog-helper[bot]

  • This issue has not had any activity in 14 days. Please provide a status update if it is still relevant. Closed it if it is no longer relevant. Or move it to another column if it's blocked or requires another look at it. - (More info)

This is a message from the daily scheduled checks.

New issue guide | Backlog management | Rules | Feedback

backlog-helper[bot] avatar May 21 '24 08:05 backlog-helper[bot]