Skip to content

Tracer Configuration

Zach Montoya edited this page Oct 23, 2019 · 4 revisions

The Tracer is configurable by passing a TracerSettings object into its constructor. Before creating a Tracer, the TracerSettings object can be populated manually (using property setters) or by passing a IConfigurationSource into its constructor.

Different IConfigurationSource implementations represent multiple ways in which the Tracer can be configured, but they all basically wrap a key/value store. The basic concrete sources are:

  • EnvironmentConfigurationSource, reads from environment variables
  • NameValueConfigurationSource, reads from a given NameValueCollection
  • JsonConfigurationSource, reads from a given JSON string or file

Since environment variables and NameValueCollection can only store string values, EnvironmentConfigurationSource and NameValueConfigurationSource only implement GetString() and inherit from abstract StringConfigurationSource. This source contains the code required to parse strings and provides getters for the other supported types. For example StringConfigurationSource.GetInt32() calls GetString() and parses the result into an Int32.

JsonConfigurationSource doesn't need to use the parsing code in StringConfigurationSource because JSON can store these types directly.

CompositeConfigurationSource is a special source which is composed of a list of IConfigurationSource. When getting a value from a CompositeConfigurationSource, it will iterate through the list until it finds a source that contains the specified key. The order of the underlying source is important as it determines precedence.

If a TracerSettings is not used, a new Tracer will call TracerSettings.CreateDefaultConfigurationSource() to create the default configuration source. This is a CompositeConfigurationSource composed of, in order:

  • an EnvironmentConfigurationSource
  • a NameValueConfigurationSource that wraps ConfigurationManager.AppSettings (.NET Framework only)
  • a JsonConfigurationSource that wraps the file datadog.json, if found
                                                         +-----------------------------+
                                                         |                             |
                  +--------------------------------------+   IConfigurationSource      +---------------------------+
                  |                                      |                             |                           |
                  |                                      +---+-------------------------+                           |
                  |                                          |                                                     |
                  |                                          |                                       +-------------v---------------+
                  |                                          |                                       |                             |
                  |                                          |                                       |  StringConfigurationSource  |
                  |                                          |                                       |                             |
                  |                                          |                                       +----+--------------------+---+
                  |                                          |                                            |                    |
                  |                                          |                                            |                    |
                  |                                          |                                            |                    |
                  |                                          |                                            |                    |
                  |                                          |                                            |                    |
                  |                                          |                                            |                    |
+-----------------v--------------+     +---------------------v-----+       +------------------------------v---+        +-------v------------------------+
|                                |     |                           |       |                                  |        |                                |
|  CompositeConfigurationSource  |     |  JsonConfigurationSource  |       |  EnvironmentConfigurationSource  |        |  NameValueConfigurationSource  |
|                                |     |                           |       |                                  |        |                                |
+--------------------------------+     +---------------------------+       +----------------------------------+        +--------------------------------+

Clone this wiki locally