Skip to content

Commit

Permalink
Fix detection of api key and secret token
Browse files Browse the repository at this point in the history
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))
```
  • Loading branch information
monty241 authored Mar 4, 2025
1 parent 84471b8 commit b2a900d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Elastic.Apm/BackendComm/BackendCommUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b2a900d

Please sign in to comment.