Skip to content

Commit

Permalink
Geneva Exporter - Throw on TableNameMappings null value (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
mic-max authored May 7, 2022
1 parent fc6a092 commit bb01f81
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Throw exception when `TableNameMappings` contains a `null` value.
[322](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/322)

## 1.2.6 [2022-Apr-21]

* Set GenevaMetricExporter temporality preference back to Delta.
Expand Down
25 changes: 24 additions & 1 deletion src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,34 @@ public class GenevaExporterOptions
[Schema.V40.PartA.Ver] = "4.0",
};

private IReadOnlyDictionary<string, string> _tableNameMappings;

public string ConnectionString { get; set; }

public IEnumerable<string> CustomFields { get; set; }

public IReadOnlyDictionary<string, string> TableNameMappings { get; set; }
public IReadOnlyDictionary<string, string> TableNameMappings
{
get => this._tableNameMappings;
set
{
Guard.ThrowIfNull(value);

var copy = new Dictionary<string, string>(value.Count);

foreach (var entry in value)
{
if (entry.Value is null)
{
throw new ArgumentNullException(entry.Key, $"{nameof(this.TableNameMappings)} must not contain null values.");
}

copy[entry.Key] = entry.Value;
}

this._tableNameMappings = copy;
}
}

public IReadOnlyDictionary<string, object> PrepopulatedFields
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
20 changes: 20 additions & 0 deletions test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ public void SpecialChractersInTableNameMappings()
TableNameMappings = new Dictionary<string, string> { ["*"] = "\u0418" },
});
});

// Throw on null value - include key in exception message
var ex = Assert.Throws<ArgumentNullException>(() =>
{
new GenevaExporterOptions
{
TableNameMappings = new Dictionary<string, string> { ["TestCategory"] = null },
};
});
Assert.Contains("TableNameMappings must not contain null values.", ex.Message);
Assert.Equal("TestCategory", ex.ParamName);

// Throw when TableNameMappings is null
Assert.Throws<ArgumentNullException>(() =>
{
new GenevaExporterOptions
{
TableNameMappings = null,
};
});
}

[Theory]
Expand Down

0 comments on commit bb01f81

Please sign in to comment.