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 @@ -551,7 +551,7 @@ internal void LogConfigSources(ILogger logger)
LogConfig(logger, _skipInstrumentationAssemblyScanning);

LogConfig(logger, _opAmpEndpoint);
// TODO - Log headers but redact auth header value
LogConfig(logger, _opAmpHeaders);
LogConfig(logger, _resourceAttributes);

static void LogConfig<T>(ILogger logger, ConfigCell<T> cell)
Expand Down
10 changes: 5 additions & 5 deletions src/Elastic.OpenTelemetry.Core/Configuration/ConfigCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Elastic.OpenTelemetry.Configuration;

internal class ConfigCell<T>
{
internal ConfigCell(string key, T value)
internal ConfigCell(string key, T? value)
{
Key = key;
Value = value;
}

internal ConfigCell(string key, T value, Func<T, T> valueRedactor)
internal ConfigCell(string key, T? value, Func<T?, T?> valueRedactor)
{
Key = key;
Value = value;
Expand All @@ -21,9 +21,9 @@ internal ConfigCell(string key, T value, Func<T, T> valueRedactor)

internal string Key { get; }

internal Func<T, T> ValueRedactor { get; } = original => original;
internal Func<T?, T?> ValueRedactor { get; } = original => original;

internal T Value { get; private set; }
internal T? Value { get; private set; }

internal ConfigSource Source { get; private set; } = ConfigSource.Default;

Expand All @@ -45,5 +45,5 @@ private void Assign(T value, ConfigSource source)
Source = source;
}

public override string ToString() => $"{Key}: '{ValueRedactor(Value)}' from [{Source}]";
public override string ToString() => $"{Key}: '{(Value == null ? "<null>" : ValueRedactor(Value))}' from [{Source}]";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Elastic.OpenTelemetry.Tests.Configuration;

public class CompositeElasticOpenTelemetryOptionsTests(ITestOutputHelper output)
{
private const int ExpectedLogsLength = 11;
private const int ExpectedLogsLength = 12;

[Fact]
public void DefaultCtor_SetsExpectedDefaults_WhenNoEnvironmentVariablesAreConfigured()
Expand Down Expand Up @@ -365,6 +365,26 @@ public void TwoInstancesAreNotEqual_WhenValuesDoNotMatch()
Assert.NotEqual(options1, options2);
}

[Fact]
public void LogValueRedaction_WorksAsExpected()
{
var options = new ElasticOpenTelemetryOptions
{
OpAmpClientOptions = new OpAmpClientOptions
{
Endpoint = "http://my-endpoint.com",
Headers = "Custom=123,Authorization=ApiKey ABC123,Custom2=ABC"
}
};

var sut = new CompositeElasticOpenTelemetryOptions(options);
var logger = new TestLogger(output);

sut.LogConfigSources(logger);

Assert.Contains(logger.Messages, s => s.EndsWith("Configured value for OpAmpHeaders: 'Custom=123,Authorization=<redacted>,Custom2=ABC' from [Options]", StringComparison.Ordinal));
}

[Theory]
[MemberData(nameof(OpAmpIsEnabledTestData))]
public void IsOpAmpEnabled_ReturnsExpectedValue(IConfiguration configuration, ElasticOpenTelemetryOptions options, IDictionary dictionary, bool isEnabled)
Expand Down