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 component configuration #810

Open
wants to merge 4 commits into
base: feature/integration_configuration_options
Choose a base branch
from

Conversation

delner
Copy link
Contributor

@delner delner commented Sep 6, 2019

This PR depends on #809.

As a follow-up to #450 and #764, this pull request adds block style configuration for Rails components available, to make configuration more expressive and customizable.

Some new configuration examples include:

# Customize ActiveRecord with block
Datadog.configure do |c|
  c.use :rails do |rails|
    rails.service_name = 'my-app'

    rails.active_record do |active_record|
      active_record.service_name = "#{rails.service_name}-postgres"
    end
  end
end

# Customize different ActiveRecord databases with block
Datadog.configure do |c|
  c.use :rails do |rails|
    rails.service_name = 'my-app'

    rails.active_record describes: :primary_db do |active_record|
      active_record.service_name = "#{rails.service_name}-primary-db"
    end

    rails.active_record describes: :secondary_db do |active_record|
      active_record.service_name = "#{rails.service_name}-secondary-db"
    end
  end
end

# Deactivate ActiveRecord
Datadog.configure do |c|
  c.use :rails do |rails|
    rails.active_record false
  end
end

The Rails configuration now allows all its sub-integrations (rack, active_record, action_view, action_pack, active_support) and their constituent options to configured in this manner.

@delner delner added integrations Involves tracing integrations feature Involves a product feature labels Sep 6, 2019
@delner delner requested review from marcotc, brettlangdon and a team September 6, 2019 18:32
@delner delner self-assigned this Sep 6, 2019
@delner delner added the do-not-merge/WIP Not ready for merge label Sep 6, 2019
@delner
Copy link
Contributor Author

delner commented Sep 6, 2019

This is considered a WIP; still need to add unit and integration tests for this one.

@marcotc
Copy link
Member

marcotc commented Sep 6, 2019

Just to clarify, the describes: keyword argument of your active_record example,

rails.active_record describes: :primary_db do |active_record|

is not functional yet, is it?

@delner
Copy link
Contributor Author

delner commented Sep 9, 2019

describes: is actually a valid, functional option. It's the multiplexer that allows users to define what configuration they want the settings to apply to. In the context of ActiveRecord, this is the name of the database described in databases.yml that they want these trace settings to apply to.

See #451

@marcotc
Copy link
Member

marcotc commented Sep 9, 2019

👏 Looks good!
This should be an easy approval after tests are implemented.

@delner delner force-pushed the feature/rails_component_configuration branch from 29dfdf8 to ad3a87a Compare September 10, 2019 21:36
@delner delner force-pushed the feature/integration_configuration_options branch from 7cb8b61 to 09a774a Compare September 13, 2019 19:21
@delner delner force-pushed the feature/rails_component_configuration branch from ad3a87a to fb2b660 Compare September 13, 2019 19:27
@yijia-zhan
Copy link

@delner Just want to say thank you for this PR to follow up with #764! Any chance this can get in soon? :)

@delner
Copy link
Contributor Author

delner commented Nov 7, 2019

@yijia-zhan we got this most of the way complete, but hit a snag with how defaults are evaluated under certain contexts; I will likely have to rework some of the design here to make it work.

I'm unfortunately quite busy at the moment trying to get some features in order, but I will revisit this as soon as I have a chance.

@mrmason
Copy link

mrmason commented May 25, 2021

This would be really handy, I've got a number of Rails applications that connect out to other databases using ActiveRecord, but all of the config I've tried always puts everything under the same service - I'm assuming from the Rails.application.config.after_initialize.

@delner are you able to advise on any current way to get separate dbs traced differently in a rails app ?

This is what I'm trying to get working...

  c.use(:rails, service_name: api')
  c.use(:sneakers, service_name: 'api-workers')

  c.use(:active_record, describes: { adapter: 'mysql2',
                                     database: "legacy" },
        service_name: 'api-legacy')
  
  c.use(:active_record, describes: { adapter: 'mysql2',
                                     database: "forum" },
        service_name: 'api-forum')

The rails main database is postgres - and all of the queries come through to DD on that service.

@brettlangdon brettlangdon removed their request for review February 10, 2023 13:13
@ivoanjo
Copy link
Member

ivoanjo commented Mar 27, 2024

Since this is very outdated, shall we go ahead and close it for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/WIP Not ready for merge feature Involves a product feature integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants