From b02c97604a09e4550b36c448bc884773f44e9104 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Tue, 27 Sep 2022 19:38:51 +0100 Subject: [PATCH] remove cmd line arg parsing --- .../HoneycombOptions.cs | 42 +-------- .../MeterProviderBuilderExtensions.cs | 8 -- .../TracerProviderBuilderExtensions.cs | 8 -- .../HoneycombOptionsTests.cs | 94 ------------------- 4 files changed, 1 insertion(+), 151 deletions(-) diff --git a/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs b/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs index af7a325..f507a73 100644 --- a/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs +++ b/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs @@ -184,46 +184,6 @@ public string MetricsEndpoint /// If set to true, enables the console span exporter for local debugging. /// public bool Debug { get; set; } = false; - - private static readonly Dictionary CommandLineSwitchMap = new Dictionary - { - { "--honeycomb-apikey", "apikey" }, - { "--honeycomb-traces-apikey", "tracesapikey" }, - { "--honeycomb-metrics-apikey", "metricsapikey" }, - { "--honeycomb-dataset", "dataset" }, - { "--honeycomb-traces-dataset", "tracesdataset" }, - { "--honeycomb-metrics-dataset", "metricsdataset" }, - { "--honeycomb-endpoint", "endpoint" }, - { "--honeycomb-traces-endpoint", "tracesendpoint" }, - { "--honeycomb-metrics-endpoint", "metricsendpoint" }, - { "--honeycomb-samplerate", "samplerate" }, - { "--honeycomb-enable-local-visualizations", "enablelocalvisualizations" }, - { "--honeycomb-add-baggage-span-processor", "addBaggageSpanProcessor" }, - { "--honeycomb-add-determinisitc-sampler", "addDeterministicSampler" }, - { "--service-name", "servicename" }, - { "--service-version", "serviceversion" }, - { "--meter-names", "meternames" }, - { "--debug", "debug" } - }; - - /// - /// Creates an instance of from command line parameters. - /// - public static HoneycombOptions FromArgs(params string[] args) - { - var config = new ConfigurationBuilder() - .AddCommandLine(args, CommandLineSwitchMap) - .Build(); - var honeycombOptions = config.Get(); - - var meterNames = config.GetValue("meternames"); - if (!string.IsNullOrWhiteSpace(meterNames)) - { - honeycombOptions.MeterNames = new List(meterNames.Split(',')); - } - - return honeycombOptions; - } internal string GetTraceHeaders() => GetTraceHeaders(TracesApiKey, TracesDataset); @@ -262,7 +222,7 @@ internal static string GetMetricsHeaders(string apikey, string dataset) $"x-honeycomb-team={apikey}", $"x-honeycomb-dataset={dataset}" }; - + return string.Join(",", headers); } } diff --git a/src/Honeycomb.OpenTelemetry/MeterProviderBuilderExtensions.cs b/src/Honeycomb.OpenTelemetry/MeterProviderBuilderExtensions.cs index d1a23b2..49b966f 100644 --- a/src/Honeycomb.OpenTelemetry/MeterProviderBuilderExtensions.cs +++ b/src/Honeycomb.OpenTelemetry/MeterProviderBuilderExtensions.cs @@ -9,14 +9,6 @@ namespace OpenTelemetry.Metrics /// public static class MeterProviderBuilderExtensions { - /// - /// Configures the to send metrics telemetry data to Honeycomb using options created from command line arguments. - /// - public static MeterProviderBuilder AddHoneycomb(this MeterProviderBuilder builder, string[] args) - { - return builder.AddHoneycomb(HoneycombOptions.FromArgs(args)); - } - /// /// Configures the to send metrics telemetry data to Honeycomb. /// diff --git a/src/Honeycomb.OpenTelemetry/TracerProviderBuilderExtensions.cs b/src/Honeycomb.OpenTelemetry/TracerProviderBuilderExtensions.cs index 6849732..9cbe0bf 100644 --- a/src/Honeycomb.OpenTelemetry/TracerProviderBuilderExtensions.cs +++ b/src/Honeycomb.OpenTelemetry/TracerProviderBuilderExtensions.cs @@ -14,14 +14,6 @@ namespace OpenTelemetry.Trace /// public static class TracerProviderBuilderExtensions { - /// - /// Configures the to send telemetry data to Honeycomb using options created from command line arguments. - /// - public static TracerProviderBuilder AddHoneycomb(this TracerProviderBuilder builder, string[] args) - { - return builder.AddHoneycomb(HoneycombOptions.FromArgs(args)); - } - /// /// Configures the to send telemetry data to Honeycomb. /// diff --git a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs index 4077266..74a2c7c 100644 --- a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs +++ b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs @@ -6,100 +6,6 @@ namespace Honeycomb.OpenTelemetry.Tests { public class HoneycombOptionsHelperTests { - [Fact] - public void DefaultsOptionalArgs() - { - var options = HoneycombOptions.FromArgs( - "--honeycomb-apikey", "my-apikey", - "--honeycomb-dataset", "my-dataset" - ); - - Assert.Equal("my-apikey", options.ApiKey); - Assert.Equal("my-apikey", options.TracesApiKey); - Assert.Equal("my-apikey", options.MetricsApiKey); - Assert.Equal("my-dataset", options.Dataset); - Assert.Equal("my-dataset", options.TracesDataset); - Assert.Null(options.MetricsDataset); - Assert.Equal((uint)1, options.SampleRate); - Assert.Equal(HoneycombOptions.DefaultEndpoint, options.Endpoint); - Assert.Equal(HoneycombOptions.DefaultEndpoint, options.TracesEndpoint); - Assert.Equal(HoneycombOptions.DefaultEndpoint, options.MetricsEndpoint); - Assert.Empty(options.MeterNames); - Assert.False(options.Debug); - } - - [Fact] - public void CanParseOptionsFromSpacedCommandLineArgs() - { - var options = HoneycombOptions.FromArgs( - "--honeycomb-apikey", "my-apikey", - "--honeycomb-traces-apikey", "my-traces-apikey", - "--honeycomb-metrics-apikey", "my-metrics-apikey", - "--honeycomb-dataset", "my-dataset", - "--honeycomb-traces-dataset", "my-traces-dataset", - "--honeycomb-metrics-dataset", "my-metrics-dataset", - "--honeycomb-samplerate", "5", - "--honeycomb-endpoint", "my-endpoint", - "--honeycomb-traces-endpoint", "my-traces-endpoint", - "--honeycomb-metrics-endpoint", "my-metrics-endpoint", - "--meter-names", "meter1,meter2", - "--service-name", "my-service", - "--service-version", "my-version", - "--debug", "true" - ); - - Assert.Equal("my-apikey", options.ApiKey); - Assert.Equal("my-traces-apikey", options.TracesApiKey); - Assert.Equal("my-metrics-apikey", options.MetricsApiKey); - Assert.Equal("my-dataset", options.Dataset); - Assert.Equal("my-traces-dataset", options.TracesDataset); - Assert.Equal("my-metrics-dataset", options.MetricsDataset); - Assert.Equal((uint)5, options.SampleRate); - Assert.Equal("my-endpoint", options.Endpoint); - Assert.Equal("my-traces-endpoint", options.TracesEndpoint); - Assert.Equal("my-metrics-endpoint", options.MetricsEndpoint); - Assert.Equal("my-service", options.ServiceName); - Assert.Equal("my-version", options.ServiceVersion); - Assert.Equal(new List { "meter1", "meter2" }, options.MeterNames); - Assert.True(options.Debug); - } - - [Fact] - public void CanParseOptionsFromInlineCommandLineArgs() - { - var options = HoneycombOptions.FromArgs( - "--honeycomb-apikey=my-apikey", - "--honeycomb-traces-apikey=my-traces-apikey", - "--honeycomb-metrics-apikey=my-metrics-apikey", - "--honeycomb-dataset=my-dataset", - "--honeycomb-traces-dataset=my-traces-dataset", - "--honeycomb-metrics-dataset=my-metrics-dataset", - "--honeycomb-samplerate=5", - "--honeycomb-endpoint=my-endpoint", - "--honeycomb-traces-endpoint=my-traces-endpoint", - "--honeycomb-metrics-endpoint=my-metrics-endpoint", - "--meter-names=meter1,meter2", - "--service-name=my-service", - "--service-version=my-version", - "--debug=true" - ); - - Assert.Equal("my-apikey", options.ApiKey); - Assert.Equal("my-traces-apikey", options.TracesApiKey); - Assert.Equal("my-metrics-apikey", options.MetricsApiKey); - Assert.Equal("my-dataset", options.Dataset); - Assert.Equal("my-traces-dataset", options.TracesDataset); - Assert.Equal("my-metrics-dataset", options.MetricsDataset); - Assert.Equal((uint)5, options.SampleRate); - Assert.Equal("my-endpoint", options.Endpoint); - Assert.Equal("my-traces-endpoint", options.TracesEndpoint); - Assert.Equal("my-metrics-endpoint", options.MetricsEndpoint); - Assert.Equal("my-service", options.ServiceName); - Assert.Equal("my-version", options.ServiceVersion); - Assert.Equal(new List { "meter1", "meter2" }, options.MeterNames); - Assert.True(options.Debug); - } - [Fact] public void CanParseOptionsFromConfiguration() {