Skip to content

Calling render inside Appsignal instrument breaks the span stack and fails to report the trace #115

@tombruijn

Description

@tombruijn

From my notes in Slack.

In a Phoenix controller, doing this breaks the reporting for that action:

Appsignal.instrument("event.group", fn span ->
  render(conn, :home)
end)

Order of events:

  • phoenix_endpoint_start
  • phoenix_router_dispatch_start
  • Appsignal.instrument - start
  • phoenix_endpoint_stop:
    • This is called here because of render inside Appsignal.instrument
    • This event closes the span from Appsignal.instrument as it's the current span
  • Appsignal.instrument - stop:
    • This moment closes the same span again as the last step, not the current span (which would also be wrong)
  • phoenix_router_dispatch_stop:
    • This closes the span from phoenix_router_dispatch_start, instead of what it should be closing: phoenix_endpoint_start

The Phoenix events are from our Phoenix package.

Fix it somehow in our Phoenix event handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed and unconfirmed bugs reported by us and customers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions