diff --git a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md index 22111fd53a..472bf8169d 100644 --- a/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md @@ -3,7 +3,12 @@ ## Unreleased * Update OTel SDK version to `1.3.1`. - ([#631](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/631)) + [#631](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/631) + +* The option `TableNameMappings` of `GenevaExporterOptions` will not support + string values that are null, empty, or consist only of white-space characters. + It will also not support string values that contain non-ASCII characters. + [646](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/646) ## 1.4.0-beta.1 diff --git a/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs b/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs index 9664117af3..437569fa4d 100644 --- a/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; +using System.Text; using OpenTelemetry.Internal; namespace OpenTelemetry.Exporter.Geneva; @@ -44,9 +45,14 @@ public IReadOnlyDictionary TableNameMappings foreach (var entry in value) { - if (entry.Value is null) + if (string.IsNullOrWhiteSpace(entry.Value)) { - throw new ArgumentNullException(entry.Key, $"{nameof(this.TableNameMappings)} must not contain null values."); + throw new ArgumentException($"A string-typed value provided for {nameof(this.TableNameMappings)} must not be null, empty, or consist only of white-space characters."); + } + + if (Encoding.UTF8.GetByteCount(entry.Value) != entry.Value.Length) + { + throw new ArgumentException($"A string-typed value provided for {nameof(this.TableNameMappings)} must not contain non-ASCII characters.", entry.Value); } copy[entry.Key] = entry.Value; diff --git a/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs b/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs index 5f7d4cdd5c..f6f17a0011 100644 --- a/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs +++ b/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs @@ -19,7 +19,6 @@ using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Text; using System.Threading; using Microsoft.Extensions.Logging; using OpenTelemetry.Internal; @@ -58,11 +57,6 @@ public GenevaLogExporter(GenevaExporterOptions options) var tempTableMappings = new Dictionary(options.TableNameMappings.Count, StringComparer.Ordinal); foreach (var kv in options.TableNameMappings) { - if (Encoding.UTF8.GetByteCount(kv.Value) != kv.Value.Length) - { - throw new ArgumentException("The value: \"{tableName}\" provided for TableNameMappings option contains non-ASCII characters", kv.Value); - } - if (kv.Key == "*") { if (kv.Value == "*") diff --git a/src/OpenTelemetry.Exporter.Geneva/GenevaTraceExporter.cs b/src/OpenTelemetry.Exporter.Geneva/GenevaTraceExporter.cs index 4dfa3d828c..5ae7849df1 100644 --- a/src/OpenTelemetry.Exporter.Geneva/GenevaTraceExporter.cs +++ b/src/OpenTelemetry.Exporter.Geneva/GenevaTraceExporter.cs @@ -19,7 +19,6 @@ using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; -using System.Text; using System.Threading; using OpenTelemetry.Internal; @@ -36,16 +35,6 @@ public GenevaTraceExporter(GenevaExporterOptions options) if (options.TableNameMappings != null && options.TableNameMappings.TryGetValue("Span", out var customTableName)) { - if (string.IsNullOrWhiteSpace(customTableName)) - { - throw new ArgumentException("TableName mapping for Span is invalid."); - } - - if (Encoding.UTF8.GetByteCount(customTableName) != customTableName.Length) - { - throw new ArgumentException("The \"{customTableName}\" provided for TableNameMappings option contains non-ASCII characters", customTableName); - } - partAName = customTableName; } diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs index 3ec27e5ebf..d86edadca5 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs @@ -62,15 +62,14 @@ public void SpecialCharactersInTableNameMappings() }); // Throw on null value - include key in exception message - var ex = Assert.Throws(() => + var ex = Assert.Throws(() => { new GenevaExporterOptions { TableNameMappings = new Dictionary { ["TestCategory"] = null }, }; }); - Assert.Contains("TableNameMappings must not contain null values.", ex.Message); - Assert.Equal("TestCategory", ex.ParamName); + Assert.Contains("A string-typed value provided for TableNameMappings must not be null, empty, or consist only of white-space characters.", ex.Message); // Throw when TableNameMappings is null Assert.Throws(() =>