Skip to content

Commit

Permalink
cleanup env options class
Browse files Browse the repository at this point in the history
  • Loading branch information
pkanal committed Sep 27, 2022
1 parent a49f444 commit b075f6e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 131 deletions.
75 changes: 0 additions & 75 deletions src/Honeycomb.OpenTelemetry/EnvironmentOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,81 +50,6 @@ internal EnvironmentOptions(IDictionary service)
internal string SampleRateValue => GetEnvironmentVariable(SampleRateKey);
internal uint SampleRate => uint.TryParse(SampleRateValue, out var sampleRate) ? sampleRate : DefaultSampleRate;
internal string OtelExporterOtlpProtocol => GetEnvironmentVariable(OtelExporterOtlpProtocolKey);

// TODO: Delete this once the other thing is working
// internal void SetOptionsFromEnvironmentIfTheyExist(HoneycombOptions options)
// {
// if (!string.IsNullOrWhiteSpace(ApiKey))
// {
// options.ApiKey = ApiKey;
// }

// if (!string.IsNullOrWhiteSpace(TracesApiKey))
// {
// options.TracesApiKey = TracesApiKey;
// }

// if (!string.IsNullOrWhiteSpace(MetricsApiKey))
// {
// options.MetricsApiKey = MetricsApiKey;
// }

// if (!string.IsNullOrWhiteSpace(Dataset))
// {
// options.Dataset = Dataset;
// }

// if (!string.IsNullOrWhiteSpace(TracesDataset))
// {
// options.TracesDataset = TracesDataset;
// }

// if (!string.IsNullOrWhiteSpace(MetricsDataset))
// {
// options.MetricsDataset = MetricsDataset;
// }

// if (!string.IsNullOrWhiteSpace(ApiEndpoint))
// {
// options.Endpoint = ApiEndpoint;
// }

// if (!string.IsNullOrWhiteSpace(TracesEndpoint))
// {
// options.TracesEndpoint = TracesEndpoint;
// }

// if (!string.IsNullOrWhiteSpace(MetricsEndpoint))
// {
// options.MetricsEndpoint = MetricsEndpoint;
// }

// if (!string.IsNullOrWhiteSpace(ServiceName))
// {
// options.ServiceName = ServiceName;
// }

// if (!string.IsNullOrWhiteSpace(ServiceVersion))
// {
// options.ServiceVersion = ServiceVersion;
// }

// if (bool.TryParse(GetEnvironmentVariable(EnableLocalVisualizationsKey), out var enableLocalVisualizations))
// {
// options.EnableLocalVisualizations = enableLocalVisualizations;
// }

// if (bool.TryParse(GetEnvironmentVariable(DebugKey), out var debug))
// {
// options.Debug = debug;
// }

// if (uint.TryParse(GetEnvironmentVariable(SampleRateKey), out var sampleRate))
// {
// options.SampleRate = sampleRate;
// }
// }

private string GetEnvironmentVariable(string key, string defaultValue = "")
{
var value = _environmentService[key];
Expand Down
59 changes: 3 additions & 56 deletions test/Honeycomb.OpenTelemetry.Tests/EnvironmentOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public void Can_get_options_from_env_vars()
{"OTEL_SERVICE_NAME", "my-service-name"},
{"SERVICE_VERSION", "my-service-version"},
{"ENABLE_LOCAL_VISUALIZATIONS", "true" },
{"DEBUG", "true"}
{"DEBUG", "true"},
{"OTEL_EXPORTER_OTLP_PROTOCOL", "grpc"},
};
var options = new EnvironmentOptions(values);
Assert.Equal("my-api-key", options.ApiKey);
Expand All @@ -40,61 +41,7 @@ public void Can_get_options_from_env_vars()
Assert.Equal("my-service-version", options.ServiceVersion);
Assert.True(options.EnableLocalVisualizations);
Assert.True(options.Debug);
}

[Fact]
public void EnvironmentOptionsCanOverrideHoneycombOptions()
{
var honeycombOptions = new HoneycombOptions
{
ApiKey = "my-api-key",
TracesApiKey = "my-traces-api-key",
MetricsApiKey = "my-metrics-api-key",
Dataset = "my-dataset",
TracesDataset = "my-traces-dataset",
MetricsDataset = "my-metrics-dataset",
Endpoint = "my-endpoint",
TracesEndpoint = "my-traces-endpoint",
MetricsEndpoint = "my-metrics-endpoint",
SampleRate = 2,
ServiceName = "my-service-name",
ServiceVersion = "my-service-version",
EnableLocalVisualizations = false,
Debug = false
};

var values = new Dictionary<string, string>
{
{"HONEYCOMB_API_KEY", "my-env-api-key"},
{"HONEYCOMB_TRACES_API_KEY", "my-env-traces-api-key"},
{"HONEYCOMB_METRICS_API_KEY", "my-env-metrics-api-key"},
{"HONEYCOMB_DATASET", "my-env-dataset"},
{"HONEYCOMB_TRACES_DATASET", "my-env-traces-dataset"},
{"HONEYCOMB_METRICS_DATASET", "my-env-metrics-dataset"},
{"HONEYCOMB_API_ENDPOINT", "my-env-endpoint"},
{"HONEYCOMB_TRACES_ENDPOINT", "my-env-traces-endpoint"},
{"HONEYCOMB_METRICS_ENDPOINT", "my-env-metrics-endpoint"},
{"HONEYCOMB_SAMPLE_RATE", "10"},
{"OTEL_SERVICE_NAME", "my-env-service-name"},
{"SERVICE_VERSION", "my-env-service-version"},
{"ENABLE_LOCAL_VISUALIZATIONS", "true" },
{"DEBUG", "true"}
};
var options = new EnvironmentOptions(values);
Assert.Equal("my-env-api-key", options.ApiKey);
Assert.Equal("my-env-traces-api-key", options.TracesApiKey);
Assert.Equal("my-env-metrics-api-key", options.MetricsApiKey);
Assert.Equal("my-env-dataset", options.Dataset);
Assert.Equal("my-env-traces-dataset", options.TracesDataset);
Assert.Equal("my-env-metrics-dataset", options.MetricsDataset);
Assert.Equal("my-env-endpoint", options.ApiEndpoint);
Assert.Equal("my-env-traces-endpoint", options.TracesEndpoint);
Assert.Equal("my-env-metrics-endpoint", options.MetricsEndpoint);
Assert.Equal((uint)10, options.SampleRate);
Assert.Equal("my-env-service-name", options.ServiceName);
Assert.Equal("my-env-service-version", options.ServiceVersion);
Assert.True(options.EnableLocalVisualizations);
Assert.True(options.Debug);
Assert.Equal("grpc", options.OtelExporterOtlpProtocol);
}

[Fact]
Expand Down

0 comments on commit b075f6e

Please sign in to comment.