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 Configuration API #203

Merged
merged 8 commits into from
Oct 19, 2017
Merged

Add Configuration API #203

merged 8 commits into from
Oct 19, 2017

Conversation

p-lambert
Copy link
Member

@p-lambert p-lambert commented Sep 28, 2017

Overview

This PR provides the core components that will power the new configuration API. All integrations should include the Base module which in turn includes the Registerable and the Configurable modules.

By doing so, the integration will be globally accessible through the name specified in .register_as method call and all of its configuration parameters can be exposed through a series of .option declarations.

As a result, users will be able to configure everything within a single configuration block such as:

Datadog.configure do |c|
  c.use :rails, default_service_name: 'foobar'
  c.use :aws
  c.use :http, distributed_tracing_enabled: true
  c.use :dalli
end

And the integrations will look like:

module Datadog
  module Contrib
    module HTTP
      include Base
      register_as :http
      option :distributed_tracing_enabled, default: false

      def patch
        # Instrumentation Code
      end
    end
  end
end

These changes should obviate the interaction with Datadog::Monkey and Datadog::Pin in the future.

Meta Options! (For Integration Development)

The .option method provided by Configurable has the following features:

Default Values

A default value can be specified as:

option :foo, default: 'bar'

Notice that we also support lazily evaluated defaults, so you can have something like:

option :foo, default: -> { 1 + 1 }

Custom Setters

You can specify custom setters for your option param using either the setter option or providing a block:

option :shout, setter: ->(value) { value.upcase }
# alternative syntax
option(:shout) { |value| value.upcase }

Dependent Options

module AwesomeIntegration
  include Datadog::Contrib::Base
  option :tracer, default: Datadog.tracer
  option :enabled, depends_on: [:tracer] do |value|
    get_option(:tracer).enabled = value
  end
end

@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch 2 times, most recently from 1f40584 to cd31a3c Compare September 29, 2017 15:36
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from 87f767e to 07fc34f Compare September 29, 2017 18:22
@p-lambert p-lambert changed the title Create Configurable module Add Configuration API Sep 29, 2017
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from 07fc34f to 676bbc1 Compare September 29, 2017 18:32
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch 2 times, most recently from 7feb1d7 to af439d8 Compare September 29, 2017 19:37
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from af439d8 to 3ff3f5c Compare September 29, 2017 20:25
@palazzem palazzem added this to the 0.9.0 milestone Sep 30, 2017
@palazzem palazzem added the core Involves Datadog core libraries label Oct 2, 2017
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from 3ff3f5c to d16ecc6 Compare October 2, 2017 06:50
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from d16ecc6 to 97dcf9e Compare October 3, 2017 23:21
@palazzem palazzem modified the milestones: 0.9.0, 0.10.0 Oct 6, 2017
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch 2 times, most recently from 8da0e36 to 35b13b2 Compare October 12, 2017 22:22
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from 35b13b2 to a97420c Compare October 16, 2017 18:53
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch 2 times, most recently from b4a67e4 to 66bb372 Compare October 16, 2017 20:08
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch 2 times, most recently from 19c2020 to 3485012 Compare October 16, 2017 21:58
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from 3485012 to bf5a998 Compare October 16, 2017 22:02
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from 20e4ee9 to af2580b Compare October 17, 2017 20:54
@p-lambert p-lambert force-pushed the pedro/create-configurable-module branch from cdb7aa6 to 57a9807 Compare October 18, 2017 18:33
Copy link
Contributor

@palazzem palazzem left a comment

Choose a reason for hiding this comment

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

Perfect design. It allows us to provide configurations like it should be: crystal clear.

@palazzem palazzem changed the base branch from pedro/create-module-registry to master October 19, 2017 16:20
@palazzem palazzem merged commit 810de9a into master Oct 19, 2017
@palazzem palazzem deleted the pedro/create-configurable-module branch October 19, 2017 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants