Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static void OnConfigurationChanged(ConfigurationBuilder settings)
{
var oldSettings = Tracer.Instance.Settings;

var headerTags = TracerSettings.InitializeHeaderTags(settings, ConfigurationKeys.HeaderTags, headerTagsNormalizationFixEnabled: true);
var headerTags = MutableSettings.InitializeHeaderTags(settings, ConfigurationKeys.HeaderTags, headerTagsNormalizationFixEnabled: true);
// var serviceNameMappings = TracerSettings.InitializeServiceNameMappings(settings, ConfigurationKeys.ServiceNameMappings);

var globalTags = settings.WithKeys(ConfigurationKeys.GlobalTags).AsDictionary();
Expand Down
145 changes: 118 additions & 27 deletions tracer/src/Datadog.Trace/Configuration/ExporterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,52 +84,47 @@ internal ExporterSettings(IConfigurationSource? source, IConfigurationTelemetry
/// Direct use in tests only.
/// </summary>
internal ExporterSettings(IConfigurationSource? source, Func<string, bool> fileExists, IConfigurationTelemetry telemetry)
: this(new Raw(source ?? NullConfigurationSource.Instance, telemetry), fileExists, telemetry)
{
}

internal ExporterSettings(Raw rawSettings, Func<string, bool> fileExists, IConfigurationTelemetry telemetry)
{
_fileExists = fileExists;
_telemetry = telemetry;
RawSettings = rawSettings;

ValidationWarnings = new List<string>();

source ??= NullConfigurationSource.Instance;
Copy link
Member Author

Choose a reason for hiding this comment

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

This config is all just moved as-is to the Raw nested type


// Get values from the config
var config = new ConfigurationBuilder(source, telemetry);
var traceAgentUrl = config.WithKeys(ConfigurationKeys.AgentUri).AsString();
var tracesPipeName = config.WithKeys(ConfigurationKeys.TracesPipeName).AsString();
var tracesUnixDomainSocketPath = config.WithKeys(ConfigurationKeys.TracesUnixDomainSocketPath).AsString();

var agentHost = config
.WithKeys(ConfigurationKeys.AgentHost, "DD_TRACE_AGENT_HOSTNAME", "DATADOG_TRACE_AGENT_HOSTNAME")
.AsString();
var traceSettings = GetTraceTransport(
agentUri: rawSettings.TraceAgentUri,
tracesPipeName: rawSettings.TracesPipeName,
agentHost: rawSettings.TraceAgentHost,
agentPort: rawSettings.TraceAgentPort,
tracesUnixDomainSocketPath: rawSettings.TracesUnixDomainSocketPath);

var agentPort = config
.WithKeys(ConfigurationKeys.AgentPort, "DATADOG_TRACE_AGENT_PORT")
.AsInt32();

var metricsUrl = config.WithKeys(ConfigurationKeys.MetricsUri).AsString();
var dogStatsdPort = config.WithKeys(ConfigurationKeys.DogStatsdPort).AsInt32(0);
var metricsPipeName = config.WithKeys(ConfigurationKeys.MetricsPipeName).AsString();
var metricsUnixDomainSocketPath = config.WithKeys(ConfigurationKeys.MetricsUnixDomainSocketPath).AsString();

var traceSettings = GetTraceTransport(traceAgentUrl, tracesPipeName, agentHost, agentPort, tracesUnixDomainSocketPath);
TracesTransport = traceSettings.Transport;
TracesPipeName = traceSettings.PipeName;
TracesUnixDomainSocketPath = traceSettings.UdsPath;
AgentUri = traceSettings.AgentUri;

var metricsSettings = ConfigureMetricsTransport(metricsUrl, traceAgentUrl, agentHost, dogStatsdPort, metricsPipeName, metricsUnixDomainSocketPath);
var metricsSettings = ConfigureMetricsTransport(
metricsUrl: rawSettings.MetricsUrl,
traceAgentUrl: rawSettings.TraceAgentUri,
agentHost: rawSettings.TraceAgentHost,
dogStatsdPort: rawSettings.DogStatsdPort,
metricsPipeName: rawSettings.MetricsPipeName,
metricsUnixDomainSocketPath: rawSettings.MetricsUnixDomainSocketPath);

MetricsHostname = metricsSettings.Hostname;
MetricsUnixDomainSocketPath = metricsSettings.UdsPath;
MetricsTransport = metricsSettings.Transport;
MetricsPipeName = metricsSettings.PipeName;
DogStatsdPort = metricsSettings.DogStatsdPort > 0
? metricsSettings.DogStatsdPort
: (dogStatsdPort > 0 ? dogStatsdPort : DefaultDogstatsdPort);
: (rawSettings.DogStatsdPort > 0 ? rawSettings.DogStatsdPort : DefaultDogstatsdPort);

TracesPipeTimeoutMs = config
.WithKeys(ConfigurationKeys.TracesPipeTimeoutMs)
.AsInt32(500, value => value > 0)
.Value;
TracesPipeTimeoutMs = rawSettings.TracesPipeTimeoutMs;
}

/// <summary>
Expand Down Expand Up @@ -217,6 +212,8 @@ internal ExporterSettings(IConfigurationSource? source, Func<string, bool> fileE

internal IConfigurationTelemetry Telemetry => _telemetry;

internal Raw RawSettings { get; }

// internal for testing
internal static ExporterSettings Create(Dictionary<string, object?> settings)
=> new(new DictionaryConfigurationSource(settings.ToDictionary(x => x.Key, x => x.Value?.ToString()!)), new ConfigurationTelemetry());
Expand Down Expand Up @@ -433,5 +430,99 @@ private void RecordTraceTransport(string transport, ConfigurationOrigins origin
=> _telemetry.Record(ConfigTelemetryData.AgentTraceTransport, transport, recordValue: true, origin);

private readonly record struct MetricsTransportSettings(MetricsTransportType Transport, string Hostname = DefaultDogstatsdHostname, int DogStatsdPort = 0, string? UdsPath = null, string? PipeName = null);

/// <summary>
/// These contain the "raw" settings loaded from config. If these don't change, the exporter settings also won't change
/// </summary>
internal record Raw
{
public Raw(IConfigurationSource source, IConfigurationTelemetry telemetry)
{
// Get values from the config
var config = new ConfigurationBuilder(source, telemetry);
TraceAgentUri = config.WithKeys(ConfigurationKeys.AgentUri).AsString();
TracesPipeName = config.WithKeys(ConfigurationKeys.TracesPipeName).AsString();
TracesUnixDomainSocketPath = config.WithKeys(ConfigurationKeys.TracesUnixDomainSocketPath).AsString();

TraceAgentHost = config
.WithKeys(ConfigurationKeys.AgentHost, "DD_TRACE_AGENT_HOSTNAME", "DATADOG_TRACE_AGENT_HOSTNAME")
.AsString();

TraceAgentPort = config
.WithKeys(ConfigurationKeys.AgentPort, "DATADOG_TRACE_AGENT_PORT")
.AsInt32();

MetricsUrl = config.WithKeys(ConfigurationKeys.MetricsUri).AsString();
DogStatsdPort = config.WithKeys(ConfigurationKeys.DogStatsdPort).AsInt32(0);
MetricsPipeName = config.WithKeys(ConfigurationKeys.MetricsPipeName).AsString();
MetricsUnixDomainSocketPath = config.WithKeys(ConfigurationKeys.MetricsUnixDomainSocketPath).AsString();

TracesPipeTimeoutMs = config
.WithKeys(ConfigurationKeys.TracesPipeTimeoutMs)
.AsInt32(500, value => value > 0)
.Value;
}

/// <summary>
/// Gets the Uri where the Tracer can connect to the Agent.
/// </summary>
/// <seealso cref="ConfigurationKeys.AgentUri"/>
public string? TraceAgentUri { get; }

/// <summary>
/// Gets the host where the Tracer can connect to the Agent.
/// </summary>
/// <seealso cref="ConfigurationKeys.AgentUri"/>
public string? TraceAgentHost { get; }

/// <summary>
/// Gets the port where the Tracer can connect to the Agent.
/// </summary>
/// <seealso cref="ConfigurationKeys.AgentUri"/>
public int? TraceAgentPort { get; }

/// <summary>
/// Gets the windows pipe name where the Tracer can connect to the Agent.
/// </summary>
/// <seealso cref="ConfigurationKeys.TracesPipeName"/>
public string? TracesPipeName { get; }

/// <summary>
/// Gets the timeout in milliseconds for the windows named pipe requests.
/// Default is <c>100</c>.
/// </summary>
/// <seealso cref="ConfigurationKeys.TracesPipeTimeoutMs"/>
public int TracesPipeTimeoutMs { get; }

/// <summary>
/// Gets the Uri where the Tracer can connect to statsd.
/// </summary>
/// <seealso cref="ConfigurationKeys.AgentUri"/>
public string? MetricsUrl { get; }

/// <summary>
/// Gets the windows pipe name where the Tracer can send stats.
/// Default is <c>null</c>.
/// </summary>
/// <seealso cref="ConfigurationKeys.MetricsPipeName"/>
public string? MetricsPipeName { get; }

/// <summary>
/// Gets the unix domain socket path where the Tracer can connect to the Agent.
/// This parameter is deprecated and shall be removed. Consider using AgentUri instead
/// </summary>
public string? TracesUnixDomainSocketPath { get; }

/// <summary>
/// Gets the unix domain socket path where the Tracer can send stats.
/// </summary>
/// <seealso cref="ConfigurationKeys.MetricsUnixDomainSocketPath"/>
public string? MetricsUnixDomainSocketPath { get; }

/// <summary>
/// Gets the port where the DogStatsd server is listening for connections.
/// </summary>
public int DogStatsdPort { get; }
}
}
}
49 changes: 48 additions & 1 deletion tracer/src/Datadog.Trace/Configuration/IntegrationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#nullable enable

using System;
using System.Collections.Generic;
using Datadog.Trace.Configuration.Telemetry;

Expand All @@ -13,7 +14,7 @@ namespace Datadog.Trace.Configuration
/// <summary>
/// Contains integration-specific settings.
/// </summary>
public class IntegrationSettings
public class IntegrationSettings : IEquatable<IntegrationSettings>
{
/// <summary>
/// Initializes a new instance of the <see cref="IntegrationSettings"/> class.
Expand Down Expand Up @@ -82,5 +83,51 @@ internal IntegrationSettings(string integrationName, IConfigurationSource? sourc
/// that determines the sampling rate for this integration.
/// </summary>
public double AnalyticsSampleRate { get; }

/// <inheritdoc/>
public bool Equals(IntegrationSettings? other)
{
if (other is null)
{
return false;
}

if (ReferenceEquals(this, other))
{
return true;
}

return IntegrationName == other.IntegrationName &&
Enabled == other.Enabled &&
AnalyticsEnabled == other.AnalyticsEnabled &&
AnalyticsSampleRate.Equals(other.AnalyticsSampleRate);
}

/// <inheritdoc/>
public override bool Equals(object? obj)
{
if (obj is null)
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != GetType())
{
return false;
}

return Equals((IntegrationSettings)obj);
}

/// <inheritdoc/>
public override int GetHashCode()
{
return HashCode.Combine(IntegrationName, Enabled, AnalyticsEnabled, AnalyticsSampleRate);
}
}
}
Loading
Loading