Skip to content

Commit aa564a9

Browse files
authored
GH-49169: [C++] Add ApplicationId to AzureFileSystem for SDK calls (#49301)
### Rationale for this change After discussion in #49169, this PR will add a unique identifier to the AzureFileSystem implementation to distinguish calls from the base Azure C++ SDK. ### What changes are included in this PR? This PR adds `azpartner-arrow/{verion}` as the ApplicationId used by AzureFileSystem. ### Are these changes tested? The change has been manually validated. I'm happy to add a test for its persistence, but I wasn't sure what level you'd like to see in Arrow. This is effectively just plumbing a string to the SDK. The ApplicationId functionality is validated in the SDK test suite. ### Are there any user-facing changes? This shouldn't be user facing. Only a user-agent update for the underlying SDK. * GitHub Issue: #49169 Lead-authored-by: Nate Prewitt <nate.prewitt@gmail.com> Co-authored-by: Nate Prewitt <nateprewitt@microsoft.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent 4a4718f commit aa564a9

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

cpp/src/arrow/filesystem/azurefs.cc

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <azure/storage/files/datalake.hpp>
3939

4040
#include "arrow/buffer.h"
41+
#include "arrow/config.h"
4142
#include "arrow/filesystem/path_util.h"
4243
#include "arrow/filesystem/util_internal.h"
4344
#include "arrow/io/util_internal.h"
@@ -303,6 +304,10 @@ Status ExceptionToStatus(const Azure::Core::RequestFailedException& exception,
303304
return Status::IOError(std::forward<PrefixArgs>(prefix_args)..., " Azure Error: [",
304305
exception.ErrorCode, "] ", exception.what());
305306
}
307+
308+
std::string BuildApplicationId() {
309+
return "azpartner-arrow/" + GetBuildInfo().version_string;
310+
}
306311
} // namespace
307312

308313
std::string AzureOptions::AccountBlobUrl(const std::string& account_name) const {
@@ -386,9 +391,12 @@ Result<std::unique_ptr<Blobs::BlobServiceClient>> AzureOptions::MakeBlobServiceC
386391
return Status::Invalid("AzureOptions::blob_storage_scheme must be http or https: ",
387392
blob_storage_scheme);
388393
}
394+
Blobs::BlobClientOptions client_options;
395+
client_options.Telemetry.ApplicationId = BuildApplicationId();
389396
switch (credential_kind_) {
390397
case CredentialKind::kAnonymous:
391-
return std::make_unique<Blobs::BlobServiceClient>(AccountBlobUrl(account_name));
398+
return std::make_unique<Blobs::BlobServiceClient>(AccountBlobUrl(account_name),
399+
client_options);
392400
case CredentialKind::kDefault:
393401
if (!token_credential_) {
394402
token_credential_ = std::make_shared<Azure::Identity::DefaultAzureCredential>();
@@ -399,14 +407,14 @@ Result<std::unique_ptr<Blobs::BlobServiceClient>> AzureOptions::MakeBlobServiceC
399407
case CredentialKind::kCLI:
400408
case CredentialKind::kWorkloadIdentity:
401409
case CredentialKind::kEnvironment:
402-
return std::make_unique<Blobs::BlobServiceClient>(AccountBlobUrl(account_name),
403-
token_credential_);
410+
return std::make_unique<Blobs::BlobServiceClient>(
411+
AccountBlobUrl(account_name), token_credential_, client_options);
404412
case CredentialKind::kStorageSharedKey:
405-
return std::make_unique<Blobs::BlobServiceClient>(AccountBlobUrl(account_name),
406-
storage_shared_key_credential_);
413+
return std::make_unique<Blobs::BlobServiceClient>(
414+
AccountBlobUrl(account_name), storage_shared_key_credential_, client_options);
407415
case CredentialKind::kSASToken:
408-
return std::make_unique<Blobs::BlobServiceClient>(AccountBlobUrl(account_name) +
409-
sas_token_);
416+
return std::make_unique<Blobs::BlobServiceClient>(
417+
AccountBlobUrl(account_name) + sas_token_, client_options);
410418
}
411419
return Status::Invalid("AzureOptions doesn't contain a valid auth configuration");
412420
}
@@ -420,10 +428,12 @@ AzureOptions::MakeDataLakeServiceClient() const {
420428
return Status::Invalid("AzureOptions::dfs_storage_scheme must be http or https: ",
421429
dfs_storage_scheme);
422430
}
431+
DataLake::DataLakeClientOptions client_options;
432+
client_options.Telemetry.ApplicationId = BuildApplicationId();
423433
switch (credential_kind_) {
424434
case CredentialKind::kAnonymous:
425435
return std::make_unique<DataLake::DataLakeServiceClient>(
426-
AccountDfsUrl(account_name));
436+
AccountDfsUrl(account_name), client_options);
427437
case CredentialKind::kDefault:
428438
if (!token_credential_) {
429439
token_credential_ = std::make_shared<Azure::Identity::DefaultAzureCredential>();
@@ -435,13 +445,13 @@ AzureOptions::MakeDataLakeServiceClient() const {
435445
case CredentialKind::kWorkloadIdentity:
436446
case CredentialKind::kEnvironment:
437447
return std::make_unique<DataLake::DataLakeServiceClient>(
438-
AccountDfsUrl(account_name), token_credential_);
448+
AccountDfsUrl(account_name), token_credential_, client_options);
439449
case CredentialKind::kStorageSharedKey:
440450
return std::make_unique<DataLake::DataLakeServiceClient>(
441-
AccountDfsUrl(account_name), storage_shared_key_credential_);
451+
AccountDfsUrl(account_name), storage_shared_key_credential_, client_options);
442452
case CredentialKind::kSASToken:
443453
return std::make_unique<DataLake::DataLakeServiceClient>(
444-
AccountBlobUrl(account_name) + sas_token_);
454+
AccountBlobUrl(account_name) + sas_token_, client_options);
445455
}
446456
return Status::Invalid("AzureOptions doesn't contain a valid auth configuration");
447457
}

0 commit comments

Comments
 (0)