Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom command line argument parsing #282

Merged
merged 1 commit into from
Sep 27, 2022
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
42 changes: 1 addition & 41 deletions src/Honeycomb.OpenTelemetry/HoneycombOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,46 +184,6 @@ public string MetricsEndpoint
/// If set to true, enables the console span exporter for local debugging.
/// </summary>
public bool Debug { get; set; } = false;

private static readonly Dictionary<string, string> CommandLineSwitchMap = new Dictionary<string, string>
{
{ "--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" }
};

/// <summary>
/// Creates an instance of <see cref="HoneycombOptions"/> from command line parameters.
/// </summary>
public static HoneycombOptions FromArgs(params string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args, CommandLineSwitchMap)
.Build();
var honeycombOptions = config.Get<HoneycombOptions>();

var meterNames = config.GetValue<string>("meternames");
if (!string.IsNullOrWhiteSpace(meterNames))
{
honeycombOptions.MeterNames = new List<string>(meterNames.Split(','));
}

return honeycombOptions;
}

internal string GetTraceHeaders() => GetTraceHeaders(TracesApiKey, TracesDataset);

Expand Down Expand Up @@ -262,7 +222,7 @@ internal static string GetMetricsHeaders(string apikey, string dataset)
$"x-honeycomb-team={apikey}",
$"x-honeycomb-dataset={dataset}"
};

return string.Join(",", headers);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ namespace OpenTelemetry.Metrics
/// </summary>
public static class MeterProviderBuilderExtensions
{
/// <summary>
/// Configures the <see cref="MeterProviderBuilder"/> to send metrics telemetry data to Honeycomb using options created from command line arguments.
/// </summary>
public static MeterProviderBuilder AddHoneycomb(this MeterProviderBuilder builder, string[] args)
{
return builder.AddHoneycomb(HoneycombOptions.FromArgs(args));
}

/// <summary>
/// Configures the <see cref="MeterProviderBuilder"/> to send metrics telemetry data to Honeycomb.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ namespace OpenTelemetry.Trace
/// </summary>
public static class TracerProviderBuilderExtensions
{
/// <summary>
/// Configures the <see cref="TracerProviderBuilder"/> to send telemetry data to Honeycomb using options created from command line arguments.
/// </summary>
public static TracerProviderBuilder AddHoneycomb(this TracerProviderBuilder builder, string[] args)
{
return builder.AddHoneycomb(HoneycombOptions.FromArgs(args));
}

/// <summary>
/// Configures the <see cref="TracerProviderBuilder"/> to send telemetry data to Honeycomb.
/// </summary>
Expand Down
94 changes: 0 additions & 94 deletions test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> { "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<string> { "meter1", "meter2" }, options.MeterNames);
Assert.True(options.Debug);
}

[Fact]
public void CanParseOptionsFromConfiguration()
{
Expand Down