From b2a900d50bc19a3ca07841499dc2d52896c42c51 Mon Sep 17 00:00:00 2001 From: Guido Leenders Date: Tue, 4 Mar 2025 12:49:09 +0100 Subject: [PATCH] Fix detection of api key and secret token When the `ApiKey == string.Empty`, a header will be added. This seems unlikely to be intended. Dito for `SecretToken`. We have had some problems due to this handling in Summer of 2024. Now we are making improvement, inline with other code in this file such as: ``` if (!string.IsNullOrEmpty(service.Name)) ``` --- src/Elastic.Apm/BackendComm/BackendCommUtils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Elastic.Apm/BackendComm/BackendCommUtils.cs b/src/Elastic.Apm/BackendComm/BackendCommUtils.cs index cb47daa17..d68a04db6 100644 --- a/src/Elastic.Apm/BackendComm/BackendCommUtils.cs +++ b/src/Elastic.Apm/BackendComm/BackendCommUtils.cs @@ -270,9 +270,9 @@ internal static HttpClient BuildHttpClient(IApmLogger loggerArg, IConfiguration } } - if (configuration.ApiKey != null) + if (!string.IsNullOrEmpty(configuration.ApiKey)) httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("ApiKey", configuration.ApiKey); - else if (configuration.SecretToken != null) + else if (!string.IsNullOrEmpty(configuration.SecretToken)) httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", configuration.SecretToken); return httpClient;