diff --git a/.circleci/config.yml b/.circleci/config.yml index 9f4a69b..5da9191 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,7 @@ jobs: smoke_test: machine: - image: ubuntu-2004:202107-02 + image: ubuntu-2204:2024.01.1 steps: - checkout - attach_workspace: diff --git a/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs b/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs index 5585c10..da94ddc 100644 --- a/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs +++ b/src/Honeycomb.OpenTelemetry/HoneycombOptions.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.Metrics; +using System.Text.RegularExpressions; namespace Honeycomb.OpenTelemetry { @@ -18,6 +19,8 @@ public class HoneycombOptions private const string OtelExporterOtlpProtocolGrpc = "grpc"; private const string OtelExporterHttpTracesPath = "/v1/traces"; private const string OtelExporterHttpMetricsPath = "/v1/metrics"; + private const string ClassicKeyRegex = "^[a-f0-9]*$"; + private const string IngestClassicKeyRegex = "^hc[a-z]ic_[a-z0-9]*$"; private bool isHttp = false; /// @@ -48,12 +51,27 @@ public class HoneycombOptions public string ApiKey { get; set; } /// - /// Returns whether the provided API key is a legacy key. + /// Returns whether the provided API key is a classic key. /// /// - /// Legacy keys have 32 characters. + /// Classic configuration keys have 32 characters and classic ingest keys have 64 characters. /// - internal static bool IsClassicKey(string apikey) => apikey?.Length == 32; + internal static bool IsClassicKey(string apikey) + { + if (String.IsNullOrEmpty(apikey)) + { + return false; + } + else if (apikey.Length == 32) + { + return Regex.Match(apikey, ClassicKeyRegex).Success; + } + else if (apikey.Length == 64) + { + return Regex.Match(apikey, IngestClassicKeyRegex).Success; + } + return false; + } /// /// Write links to honeycomb traces as they come in diff --git a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs index 34ed169..03ab181 100644 --- a/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs +++ b/test/Honeycomb.OpenTelemetry.Tests/HoneycombOptionsTests.cs @@ -523,17 +523,17 @@ public void DoesNotAppendMetricsPathToGenericEndpointIfPathSpecified(string prot Assert.DoesNotContain("/v1/metrics", options.GetMetricsEndpoint()); } - [Fact] - public void Legacy_key_length() - { - var options = new HoneycombOptions { ApiKey = "1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a" }; - Assert.True(HoneycombOptions.IsClassicKey(options.ApiKey)); - } - [Fact] - public void Not_legacy_key_length() + [Theory] + [InlineData("", false)] + [InlineData("12345678901234567890123456789012", true)] + [InlineData("hcaic_1234567890123456789012345678901234567890123456789012345678", true)] + [InlineData("kgvSpPwegJshQkuowXReLD", false)] + [InlineData("hcaic_12345678901234567890123456", false)] + [InlineData("hcxik_01hqk4k20cjeh63wca8vva5stw70nft6m5n8wr8f5mjx3762s8269j50wc", false)] + public void IsClassicKey(string key, bool expected) { - var options = new HoneycombOptions { ApiKey = "specialenvkey" }; - Assert.False(HoneycombOptions.IsClassicKey(options.ApiKey)); + var options = new HoneycombOptions { ApiKey = key }; + Assert.Equal(HoneycombOptions.IsClassicKey(key), expected); } } -} \ No newline at end of file +}