-
Notifications
You must be signed in to change notification settings - Fork 142
Tracer Configuration
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 givenNameValueCollection
-
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 wrapsConfigurationManager.AppSettings
(.NET Framework only) - a
JsonConfigurationSource
that wraps the filedatadog.json
, if found
+-----------------------------+
| |
+--------------------------------------+ IConfigurationSource +---------------------------+
| | | |
| +---+-------------------------+ |
| | |
| | +-------------v---------------+
| | | |
| | | StringConfigurationSource |
| | | |
| | +----+--------------------+---+
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
+-----------------v--------------+ +---------------------v-----+ +------------------------------v---+ +-------v------------------------+
| | | | | | | |
| CompositeConfigurationSource | | JsonConfigurationSource | | EnvironmentConfigurationSource | | NameValueConfigurationSource |
| | | | | | | |
+--------------------------------+ +---------------------------+ +----------------------------------+ +--------------------------------+