From 2a9ad3000a1875285f394c03167ba364ae70e487 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Wed, 27 Jul 2022 18:21:29 -0700 Subject: [PATCH 1/3] fix bugs in the GenevaExporter PrepopulatedField handling --- .../GenevaExporterOptions.cs | 7 ++++++- .../GenevaTraceExporterTests.cs | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs b/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs index c24f76a894..bbeb9314d3 100644 --- a/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs @@ -105,7 +105,12 @@ public IReadOnlyDictionary PrepopulatedFields case string vs: break; default: - throw new ArgumentException($"Type: {entry.Value.GetType()} is not supported. Only bool, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, and string are the supported types for PrepopulatedFields values."); + if (entry.Value == null) + { + throw new ArgumentException($"Null is not allowed (key = `{entry.Key}`)."); + } + + throw new ArgumentException($"Type `{entry.Value.GetType()}` (key = `{entry.Key}`) is not allowed. Only bool, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, and string are supported."); } copy[entry.Key] = val; // shallow copy diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs index cf4b58bd6b..7eb7d6fc56 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs @@ -54,6 +54,19 @@ public void GenevaTraceExporter_constructor_Invalid_Input() }); }); + // null value in the PrepopulatedFields + Assert.Throws(() => + { + using var exporter = new GenevaTraceExporter(new GenevaExporterOptions + { + ConnectionString = "EtwSession=OpenTelemetry", + PrepopulatedFields = new Dictionary + { + ["cloud.roleVer"] = null, + }, + }); + }); + // unsupported types(char) for PrepopulatedFields Assert.Throws(() => { From 3438d90302c4aa506476454734a4e40db1cb8dbd Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Wed, 27 Jul 2022 19:12:02 -0700 Subject: [PATCH 2/3] address comment --- src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs b/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs index bbeb9314d3..809f08d214 100644 --- a/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.Geneva/GenevaExporterOptions.cs @@ -107,7 +107,7 @@ public IReadOnlyDictionary PrepopulatedFields default: if (entry.Value == null) { - throw new ArgumentException($"Null is not allowed (key = `{entry.Key}`)."); + throw new ArgumentNullException(entry.Key, $"{nameof(this.PrepopulatedFields)} must not contain null values."); } throw new ArgumentException($"Type `{entry.Value.GetType()}` (key = `{entry.Key}`) is not allowed. Only bool, byte, sbyte, short, ushort, int, uint, long, ulong, float, double, and string are supported."); From e9418e15d4bab4ecac9154a37ead0b0c44352378 Mon Sep 17 00:00:00 2001 From: Reiley Yang Date: Wed, 27 Jul 2022 19:15:54 -0700 Subject: [PATCH 3/3] update test --- .../GenevaTraceExporterTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs index 7eb7d6fc56..7ebfa8b279 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs @@ -55,7 +55,7 @@ public void GenevaTraceExporter_constructor_Invalid_Input() }); // null value in the PrepopulatedFields - Assert.Throws(() => + Assert.Throws(() => { using var exporter = new GenevaTraceExporter(new GenevaExporterOptions {