Skip to content
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 ActiveRecord cached tag #291

Merged
merged 3 commits into from
Jan 5, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed: cached tag not being set for Rails ActiveRecord
delner committed Jan 5, 2018
commit 7472ab5720dad7b6d4f6586f99764420a45f85f7
7 changes: 2 additions & 5 deletions lib/ddtrace/contrib/rails/active_record.rb
Original file line number Diff line number Diff line change
@@ -33,13 +33,10 @@ def self.sql(_name, start, finish, _id, payload)
span_type: span_type
)

# find out if the SQL query has been cached in this request. This meta is really
# Find out if the SQL query has been cached in this request. This meta is really
# helpful to users because some spans may have 0ns of duration because the query
# is simply cached from memory, so the notification is fired with start == finish.
# TODO[manu]: this feature has been merged into master but has not yet released.
# We're supporting this action as a best effort, but we should add a test after
# a new version of Rails is out.
cached = payload[:cached]
cached = payload[:cached] || (payload[:name] == 'CACHE')

# the span should have the query ONLY in the Resource attribute,
# so that the ``sql.query`` tag will be set in the agent with an
8 changes: 5 additions & 3 deletions test/contrib/rails/database_test.rb
Original file line number Diff line number Diff line change
@@ -48,9 +48,11 @@ class DatabaseTracingTest < ActiveSupport::TestCase
spans = @tracer.writer.spans
assert_equal(spans.length, 2)

# Assert cached flag set correctly
span = spans.last
assert_equal(true, span.get_tag('rails.db.cached'))
# Assert cached flag not present on first query
assert_nil(spans.first.get_tag('rails.db.cached'))

# Assert cached flag set correctly on second query
assert_equal('true', spans.last.get_tag('rails.db.cached'))
end
end