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

Rails databases: {} option #574

Closed
senny opened this issue Sep 28, 2018 · 5 comments
Closed

Rails databases: {} option #574

senny opened this issue Sep 28, 2018 · 5 comments
Assignees
Labels
community Was opened by a community member question General inquiry that may or may not involve changes
Milestone

Comments

@senny
Copy link

senny commented Sep 28, 2018

Going through the changelogs of recent versions I found that support for multiple AR databases is now supported out of the box! 🎉

I tried to change our setup which was based on span preprocessors to use the new databases: option when configuring Rails. Unfortunately, I was not able to get it to work and everything was tracked in the database service specified as database_service.

My configuration was something like this:

    c.use :rails,
      database_service: 'main-db',
      databases: {
        archive: { service_name: 'archive-db' },
        follower: { service_name: 'follower-db' }
      }

I tried to find how databases: is applied but I was not able to find the right spot. (I was mainly looking at framework.rb)

Would you be able to give me a hint where I can follow-up to get this working? Thanks a lot in advance and great work on the rapid pace of new features!

@delner
Copy link
Contributor

delner commented Sep 28, 2018

Hey @senny , glad to here you're excited about the new database support!

I think what you have above was our original implementation of multi-DB configuration, which we reworked a bit, and migrated to its own integration, active_record. The current way of implementing it (I believe as of 0.14.0) is documented here. It's just a slightly different syntax, and requires the use of use :active_record instead.

Datadog.configure do |c|
  c.use :active_record, describes: :archive, service_name: 'archive-db'
  c.use :active_record, describes: :follower, service_name: 'follower-db'
end

In the future, we might add a shortcut configuration option directly to use :rails, but that hasn't been implemented yet.

The reason for this is was the introduction of multiplexing: subdivisions of unique tracer settings by key (in this case, by each database.) in the future as the integration matures, you'll be able to configure a full set of trace settings for different DBs, instead of just service_name, which should allow for greater customization of trace behavior.

Let me know if this configuration works for you!

@senny
Copy link
Author

senny commented Sep 29, 2018

@delner thanks for the details. I guess I got stuck on the databases option in the docs. One follow up question, how does this use :active_record behave in combination with use :rails. Won't that already define a catch all active record configuration?

@delner
Copy link
Contributor

delner commented Oct 1, 2018

Yeah you're absolutely right @senny the documentation is inaccurate here. I updated the code sample in ActiveRecord, but I neglected all the surrounding information and Rails itself. I'll have to fix this to be a bit more clear.

Also yes, use :rails will activate ActiveRecord automatically if present, and configure it with a service name/tracer as defined in Rails (e.g. database_service, tracer). Basically, the use command is the same thing as patch & apply settings, so if use :active_record is called twice with configuration, the first call will apply the patch, and the second will override the settings applied by the first. Because Rails has a special after_initialize hook in which it activates ActiveRecord, the configuration options passed from Rails should always override those settings set in use :active_record as defined in the initializer file.

To us, this is suboptimal and a bit clumsy. I have some plans to try to streamline this a bit, by basically turning Rails into a "composite" integration, which is composed of sub-integrations like ActiveRecord. The hope is you'll be able to configure ActiveRecord within the Rails group instead of having to configure it separately. Something like:

Datadog.configure do |c|
  c.use :rails do |rails|
    rails.service_name = 'my-app'

    # Settings for ActiveRecord tracing
    rails.active_record do |active_record|
      active_record.service_name = 'my-database'
    end
  end
end

The foundations for this were already laid in #450. Still need to figure out how to introduce the describes option into this, but it'll likely look pretty similar.

@delner delner self-assigned this Oct 1, 2018
@delner delner added question General inquiry that may or may not involve changes community Was opened by a community member labels Oct 1, 2018
@delner
Copy link
Contributor

delner commented Oct 1, 2018

Documentation for this will be fixed by #578.

@delner
Copy link
Contributor

delner commented Oct 30, 2018

The documentation change was merged and will be released with 0.17.0. Going to close this for now. If you have any other questions or comments regarding configuring databases like this, please feel free to comment or re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Was opened by a community member question General inquiry that may or may not involve changes
Projects
None yet
Development

No branches or pull requests

2 participants