Skip to content

Before/after actions not included in the action_pack span #2100

Open

Description

Current behaviour

Rails callbacks (before/after) are not a part of the action span.
In the before_action callback, active_span is:

SpanOperation(name:rack.request,sid:1008860920845926479,tid:1866324838581500214,pid:0)

But in the action call:

SpanOperation(name:rails.action_controller,sid:3701457545195306293,tid:1866324838581500214,pid:1008860920845926479)

Expected behaviour

active_pack spans should include the callbacks. That could be done either through a separate span or by extending the current one.

I'm raising this as a bug rather than a feature request, because otherwise we end up in situations where (for example) rack seems to own spans from active_record, which is not true:
Screen Shot 2022-06-22 at 4 08 39 pm
Those queries are made in the before_action on the controller.

This is also very important when trying to name the spans something more specific - for example when a top level ApiController that other things inherit knows how to label the span in before_action, but delegating that to all specific Api implementations would be extremely repetitive.

Steps to reproduce

class SomeController < ApplicationController
  before_action :bar

  def foo
    Datadog::Tracing.trace("this.goes.in.controller") {}
  end

  private
  
  def bar
    Datadog::Tracing.trace("this.goes.in.rack") {}
  end
end

Environment

  • ddtrace version: 1.1.0
  • Configuration block (Datadog.configure ...):
    c.tracing.instrument :rails, service_name: 'marketplace'
    c.tracing.instrument :rack, request_queuing: true, web_service_name: 'marketplace-rack'
  • Ruby version: 2.7
  • Operating system: linux
  • Relevant library versions:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

communityWas opened by a community memberfeature-requestA request for a new feature or change to an existing oneintegrationsInvolves tracing integrations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions