Skip to content

Commit

Permalink
Move span creation to Routing::RouteSet
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki authored and zarirhamza committed Jan 11, 2024
1 parent d3dfe32 commit 2a26d9c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/datadog/tracing/contrib/rails/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ module Datadog
module Tracing
module Contrib
module Rails
module JourneyRouterPatch
def find_routes(*)
module RoutingRouteSetPatch
def call(*)
result = nil

configuration = Datadog.configuration.tracing[:rails]

Tracing.trace(
Expand All @@ -22,12 +23,18 @@ def find_routes(*)
span_type: Tracing::Metadata::Ext::HTTP::TYPE_INBOUND,
# resource: "#{request.request_method} #{datadog_route}",
) do |span, trace|
binding.pry

result = super
end

binding.pry
result
end
end

module JourneyRouterPatch
def find_routes(*)
result = super

if (span = Datadog::Tracing.active_span)
datadog_route = result.first[2].path.spec.to_s

span.set_tag(Ext::TAG_ROUTE_PATH, datadog_route)
Expand Down Expand Up @@ -68,6 +75,7 @@ def before_initialize(app)
# Sometimes we don't want to activate middleware e.g. OpenTracing, etc.
add_middleware(app) if Datadog.configuration.tracing[:rails][:middleware]

ActionDispatch::Routing::RouteSet.prepend(RoutingRouteSetPatch)
ActionDispatch::Journey::Router.prepend(JourneyRouterPatch)

Rails::LogInjection.configure_log_tags(app.config)
Expand Down

0 comments on commit 2a26d9c

Please sign in to comment.