-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add http.route tag to rails, grape, and sinatra integrations #3849
Conversation
BenchmarksBenchmark execution time: 2024-09-18 08:13:40 Comparing candidate commit deaba02 in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 22 metrics, 2 unstable metrics. scenario:profiler - sample timeline=false
|
108627a
to
830bd67
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3849 +/- ##
==========================================
- Coverage 97.85% 97.83% -0.03%
==========================================
Files 1285 1291 +6
Lines 76951 77394 +443
Branches 3789 3845 +56
==========================================
+ Hits 75302 75716 +414
- Misses 1649 1678 +29 ☔ View full report in Codecov by Sentry. |
deleted bunch of duplicated comments from the static code analyzer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few notes!
It wasn't quite clear to me -- do we already have testing for both Rails 7.0 and Rails 7.1?
Also, given their previous work, it may be worth pinging @zarirhamza or @lloeki for a review?
lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb
Outdated
Show resolved
Hide resolved
lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb
Outdated
Show resolved
Hide resolved
@ivoanjo thank you for the review! Regarding Rails 7 tests: we don't have them yet (except system tests for Rails 7.1). The reason for adding rails 7 spec helper was that we are testing The fact that we are not testing against version 7.1 and 7.2 yet is the reason why the test coverage is low for this patch. |
lib/datadog/tracing/contrib/action_pack/action_dispatch/patcher.rb
Outdated
Show resolved
Hide resolved
lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb
Outdated
Show resolved
Hide resolved
lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb
Outdated
Show resolved
Hide resolved
lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb
Outdated
Show resolved
Hide resolved
lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb
Outdated
Show resolved
Hide resolved
a053c22
to
59b5290
Compare
Matrixfile
Outdated
'action_pack' => { | ||
'activesupport' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby', | ||
'actionpack-5.0' => '✅ 2.5 / ✅ 2.6 / ❌ 2.7 / ❌ 3.0 / ❌ 3.1 / ❌ 3.2 / ❌ 3.3 / ❌ 3.4 / ✅ jruby', | ||
'actionpack-6.0' => '❌ 2.5 / ❌ 2.6 / ✅ 2.7 / ❌ 3.0 / ❌ 3.1 / ❌ 3.2 / ❌ 3.3 / ❌ 3.4 / ✅ jruby', | ||
'actionpack-7.0' => '❌ 2.5 / ❌ 2.6 / ❌ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ❌ jruby', | ||
'actionpack-7.1' => '❌ 2.5 / ❌ 2.6 / ❌ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ❌ jruby', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you might've noticed, each separate appraise
that gets added results in an explosion of files to maintain/update.
Since the main dependency needed for these tests is rails, have you considered reusing some of the existing appraisal groups when possible?
E.g. For instance using rails5-mysql2
/ rails6-mysql2
and then adding rails7
and rails71
?
(Our whole setup for appraisals does help us get coverage but it has a lot of sharp edges and most of us are dreaming of something better lol)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, adding appraisals for action_pack was far from being a perfect solution :)
As for reusing existing appraisals - I was not sure if I could just add rails7
or something similar, since all of our existing rails appraisals are bundled together with a database adapter. How do you think, does it makes sense to add appraisals for bare-bones rails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed actionpack
appraisal and added appraisals for rails7
and rails71
here 5ba0fef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my point of view (still lacking context) it's good (with a few questions)
spec/datadog/tracing/contrib/action_pack/action_dispatch/journey/router_spec.rb
Show resolved
Hide resolved
@@ -62,6 +63,15 @@ def endpoint_start_process(_name, _start, _finish, _id, payload) | |||
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) | |||
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ENDPOINT_RUN) | |||
|
|||
if (grape_route = env['grape.routing_args'] && env['grape.routing_args'][:route_info]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add parenthesis here to improve reading clarity in this if
condition?
if (grape_route = env['grape.routing_args'] && env['grape.routing_args'][:route_info]) | |
if ((grape_route = env['grape.routing_args']) && grape_route[:route_info]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed: 7317018
if (grape_route = env['grape.routing_args'] && env['grape.routing_args'][:route_info]) | ||
trace.set_tag( | ||
Tracing::Metadata::Ext::HTTP::TAG_ROUTE, | ||
grape_route.path&.gsub(/\(\.:?\w+\)\z/, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining at a high level what we are matching here with /\(\.:?\w+\)\z/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added c62c24d
# | ||
# To account for the unaccounted nested rack requests of /rack/hello/world, | ||
# we use 'PATH_INFO knowing that rack cannot have named parameters | ||
if last_script_name == '' && env['SCRIPT_NAME'] != '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can env['SCRIPT_NAME']
be nil
here, and thus triggering env['SCRIPT_NAME'] != ''
to be true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I think it actually can. I will add handling for nil
here too
@@ -0,0 +1,213 @@ | |||
# Loaded by the `bin/rails` script in a real Rails application |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for adding Rails 7 to the test matrix!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few minor comments, but it looks great overall!
puts '=' * 80 | ||
puts grape_route[:route_info].path | ||
puts '=' * 80 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, thanks! deaba02
What does this PR do?
This PR adds
http.route
tag to rack spans for Rails (including Rails Engines), Grape, and Sinatra applications.Motivation:
Having
http.route
tag on spans helps grouping requests.Additional Notes:
In Rails version 7.1 internal
ActionDispatch::Journey::Router#find_routes
method was changed, which was the reason why the previous implementation had to be rolled back.This PR fixes this issue by checking action_pack version, and either patching
ActionDispatch::Journey::Router#find_routes
for Rails versions prior to 7.1, or patchingActionDispatch::Journey::Router#serve
and using#route_uri_pattern
that gets set on the request object.How to test the change?
Screenshots from local testing: