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 'rails.db.name' tag to ActiveRecord #270

Merged
merged 2 commits into from
Dec 12, 2017

Conversation

delner
Copy link
Contributor

@delner delner commented Dec 11, 2017

This pull request adds the database name as a tag (rails.db.name) to ActiveRecord traces.

@delner delner added the integrations Involves tracing integrations label Dec 11, 2017
@delner delner self-assigned this Dec 11, 2017
@@ -1,4 +1,5 @@
require 'helper'
require 'pry'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should remove it, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh whoops, totally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, reviews are meant for that 💯

@delner delner force-pushed the add_active_record_database_name_tag branch from 4e27f69 to 2656719 Compare December 11, 2017 19:00
palazzem
palazzem previously approved these changes Dec 11, 2017
@@ -50,6 +50,10 @@ def self.adapter_name
normalize_vendor(connection_adapter)
end

def self.database_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering this method is just an alias, is there any reason for this additional level of indirection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's much reason beyond just having naming and structure consistent with adapter_name. We could reduce this method to an alias or simply remove it altogether.

@@ -21,6 +21,7 @@ def self.sql(_name, start, finish, _id, payload)
tracer = Datadog.configuration[:rails][:tracer]
database_service = Datadog.configuration[:rails][:database_service]
adapter_name = Datadog::Contrib::Rails::Utils.adapter_name
database_name = Datadog::Contrib::Rails::Utils.database_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

p-lambert
p-lambert previously approved these changes Dec 11, 2017
@palazzem palazzem merged commit 45c8150 into master Dec 12, 2017
@palazzem palazzem deleted the add_active_record_database_name_tag branch December 12, 2017 08:55
@palazzem palazzem added this to the 0.11.0 milestone Jan 17, 2018
@senny
Copy link

senny commented Jan 30, 2018

@palazzem I hoped this would help me to implement #238. Unfortunately, the tag does not really respect the query it's annotating, it always defaults to the default connection. Any plans to make this work with multiple database connections in the same app?

@palazzem
Copy link
Contributor

Hello @senny ! I see, let us investigate on it since the meaning of the tag was just to provide the database name and not exactly the database connection. This should be implemented someway, since you may want to separate properly (for instance) replicas queries from the main database connection.

Is that correct?

@senny
Copy link

senny commented Jan 30, 2018

@palazzem yes, ideally we would get the connection name as a tag. In our case though, we are actually using different databases with the same Rails application. What we would need is a way to separate queries that are going to e.g. a reporting or a archive database and not the primary. Since they all have a different database-name, it would have been sufficient for me to implement the split.

We do use follower databases as well where obviously the database name would not be sufficient. In that case we would need the connection name to tell them apart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants