-
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
[active_record] decouple ActiveRecord and Sinatra integrations #330
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'active_record' | ||
require 'mysql2' | ||
|
||
logger = Logger.new(STDOUT) | ||
logger.level = Logger::INFO | ||
|
||
# connecting to any kind of database is enough to test the integration | ||
ActiveRecord::Base.establish_connection('mysql2://root:root@127.0.0.1:53306/mysql') | ||
|
||
class ApplicationRecord < ActiveRecord::Base | ||
self.abstract_class = true | ||
end | ||
|
||
class Article < ApplicationRecord | ||
end | ||
|
||
# check if the migration has been executed | ||
# MySQL JDBC drivers require that, otherwise we get a | ||
# "Table '?' already exists" error | ||
begin | ||
Article.count() | ||
rescue ActiveRecord::StatementInvalid | ||
logger.info 'Executing database migrations' | ||
ActiveRecord::Schema.define(version: 20161003090450) do | ||
create_table 'articles', force: :cascade do |t| | ||
t.string 'title' | ||
t.datetime 'created_at', null: false | ||
t.datetime 'updated_at', null: false | ||
end | ||
end | ||
else | ||
logger.info 'Database already exists; nothing to do' | ||
end | ||
|
||
# force an access to prevent extra spans during tests | ||
Article.count() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'spec_helper' | ||
require 'ddtrace' | ||
|
||
require_relative 'app' | ||
|
||
RSpec.describe 'ActiveRecord instrumentation' do | ||
let(:tracer) { ::Datadog::Tracer.new(writer: FauxWriter.new) } | ||
|
||
before(:each) do | ||
Datadog.configure do |c| | ||
c.use :active_record, tracer: tracer | ||
end | ||
end | ||
|
||
it 'calls the instrumentation when is used standalone' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be considered a regression test, since undoing the patch doesn't make it pass |
||
Article.count | ||
spans = tracer.writer.spans | ||
services = tracer.writer.services | ||
|
||
# expect service and trace is sent | ||
expect(spans.size).to eq(1) | ||
expect(services['mysql2']).to eq({'app'=>'active_record', 'app_type'=>'db'}) | ||
|
||
span = spans[0] | ||
expect(span.service).to eq('mysql2') | ||
expect(span.name).to eq('mysql2.query') | ||
expect(span.span_type).to eq('sql') | ||
expect(span.resource.strip).to eq('SELECT COUNT(*) FROM `articles`') | ||
expect(span.get_tag('active_record.db.vendor')).to eq('mysql2') | ||
expect(span.get_tag('active_record.db.name')).to eq('mysql') | ||
expect(span.get_tag('active_record.db.cached')).to eq(nil) | ||
expect(span.get_tag('out.host')).to eq('127.0.0.1') | ||
expect(span.get_tag('out.port')).to eq('53306') | ||
expect(span.get_tag('sql.query')).to eq(nil) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So normally as this is quite internal, nobody was using this. I let you decide wether it's worth mentioning in the release notes, but I'd say no.