Move `UserAgentGenerator` to `_internal` (#6067)

* Move UserAgentGenerator to _internal

* Clang-format

* Update release date to November release (Core)

* Update release date to November release (EventHubs)

* _MSVC_LANG

* Move comment up

* Add /Zc:__cplusplus when building the SDK, and add unittest

---------

Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
Anton Kolesnyk 2024-10-31 10:00:12 -07:00 коммит произвёл GitHub
Родитель 9d76fb6c61
Коммит 99e0895a5d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
13 изменённых файлов: 66 добавлений и 36 удалений

Просмотреть файл

@ -15,6 +15,9 @@ if(MSVC)
#https://stackoverflow.com/questions/37527946/warning-unreferenced-inline-function-has-been-removed
add_compile_options(/permissive- /W4 ${WARNINGS_AS_ERRORS_FLAG} /wd5031 /wd4668 /wd4820 /wd4255 /wd4710)
#https://learn.microsoft.com/cpp/build/reference/zc-cplusplus?view=msvc-170
add_compile_options(/Zc:__cplusplus)
# NOTE: Static analysis will slow building time considerably and it is run during CI gates.
# It is better to turn in on to debug errors reported by CI than have it ON all the time.
if (DEFINED ENV{AZURE_ENABLE_STATIC_ANALYSIS})

Просмотреть файл

@ -33,7 +33,7 @@ macro(GetFolderList project)
elseif(${project} STREQUAL DATA_TABLES)
DownloadDepVersion(sdk/core azure-core 1.11.3)
elseif(${project} STREQUAL EVENTHUBS)
DownloadDepVersion(sdk/core azure-core 1.11.3)
DownloadDepVersion(sdk/core azure-core 1.14.1)
DownloadDepVersion(sdk/core azure-core-amqp 1.0.0-beta.9)
elseif(${project} STREQUAL EVENTHUBS_CHECKPOINTSTORE_BLOB)
DownloadDepVersion(sdk/core azure-core 1.10.1)

Просмотреть файл

@ -1,10 +1,6 @@
# Release History
## 1.15.0-beta.1 (Unreleased)
### Features Added
### Breaking Changes
## 1.14.1 (2024-10-31)
### Bugs Fixed
@ -14,6 +10,7 @@
### Other Changes
- [[#6087]](https://github.com/Azure/azure-sdk-for-cpp/pull/6087) Set version property for the compiled SDK binary files. (A community contribution, courtesy of _[chewi](https://github.com/chewi)_)
- [[#6064]](https://github.com/Azure/azure-sdk-for-cpp/issues/6064) Added internal support for the SDK packages to access more of telemetry features.
### Acknowledgments

Просмотреть файл

@ -88,8 +88,13 @@ namespace Azure { namespace Core { namespace Http { namespace Policies {
-1L
#elif defined(_azure_BUILDING_SAMPLES)
0L
#else
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#if defined(_MSVC_LANG) && __cplusplus == 199711L
_MSVC_LANG
#else
__cplusplus
#endif
#endif
;
};
@ -545,7 +550,7 @@ namespace Azure { namespace Core { namespace Http { namespace Policies {
std::string const& packageName,
std::string const& packageVersion,
TelemetryOptions options = TelemetryOptions())
: m_telemetryId(Azure::Core::Http::_detail::UserAgentGenerator::GenerateUserAgent(
: m_telemetryId(Azure::Core::Http::_internal::UserAgentGenerator::GenerateUserAgent(
packageName,
packageVersion,
options.ApplicationId,

Просмотреть файл

@ -10,26 +10,35 @@
#include <string>
namespace Azure { namespace Core { namespace Http { namespace _detail {
// NOTE: Treat Azure::Core::Http::_detail::UserAgentGenerator::GenerateUserAgent() as _internal -
// it is being/has been used by eventhubs.
namespace Azure { namespace Core { namespace Http { namespace _internal {
/**
* @brief Telemetry User-Agent string generator.
*
*/
class UserAgentGenerator {
public:
/**
* @brief Generates User-Agent string for telemetry.
*
* @param componentName the name of the SDK component.
* @param componentVersion the version of the SDK component.
* @param applicationId user application ID
* @param cplusplusValue value of the `__cplusplus` macro.
*
* @return User-Agent string.
*
* @see https://azure.github.io/azure-sdk/general_azurecore.html#telemetry-policy
*
* @note Values for @a cplusplusValue: `__cplusplus` when value comes from the code being built
* after the Azure SDK has been built. `0L` when being sent from sample code, `-1L` when being
* sent from tests code, `-2L` when being sent from the SDK code, and `-3L` when being sent from
* the SDK code for compatibility reasons.
*
*/
static std::string GenerateUserAgent(
std::string const& componentName,
std::string const& componentVersion,
std::string const& applicationId,
long cplusplusValue);
[[deprecated("Use an overload with additional cplusplusValue parameter.")]] static std::string
GenerateUserAgent(
std::string const& componentName,
std::string const& componentVersion,
std::string const& applicationId)
{
// The value of -3L is to signify that an old version of signature has been used (older
// version of eventhubs); we can't rely on cpp version reported by it.
return GenerateUserAgent(componentName, componentVersion, applicationId, -3L);
}
};
}}}} // namespace Azure::Core::Http::_detail
}}}} // namespace Azure::Core::Http::_internal

Просмотреть файл

@ -148,7 +148,7 @@ std::string TrimString(std::string s)
}
} // namespace
namespace Azure { namespace Core { namespace Http { namespace _detail {
namespace Azure { namespace Core { namespace Http { namespace _internal {
std::string UserAgentGenerator::GenerateUserAgent(
std::string const& componentName,
@ -170,4 +170,4 @@ namespace Azure { namespace Core { namespace Http { namespace _detail {
return telemetryId.str();
}
}}}} // namespace Azure::Core::Http::_detail
}}}} // namespace Azure::Core::Http::_internal

Просмотреть файл

@ -11,9 +11,9 @@
#include <cstdint>
#define AZURE_CORE_VERSION_MAJOR 1
#define AZURE_CORE_VERSION_MINOR 15
#define AZURE_CORE_VERSION_PATCH 0
#define AZURE_CORE_VERSION_PRERELEASE "beta.1"
#define AZURE_CORE_VERSION_MINOR 14
#define AZURE_CORE_VERSION_PATCH 1
#define AZURE_CORE_VERSION_PRERELEASE ""
#define AZURE_CORE_VERSION_ITOA_HELPER(i) #i
#define AZURE_CORE_VERSION_ITOA(i) AZURE_CORE_VERSION_ITOA_HELPER(i)

Просмотреть файл

@ -95,7 +95,12 @@ TEST(TelemetryPolicy, telemetryString)
TEST(TelemetryPolicy, UserAgentCppVer)
{
{
const std::string ua = Http::_detail::UserAgentGenerator::GenerateUserAgent(
std::ostringstream cppversion;
cppversion << "TEST:" << __cplusplus;
EXPECT_EQ(cppversion.str(), "TEST:201402");
}
{
const std::string ua = Http::_internal::UserAgentGenerator::GenerateUserAgent(
"storage.blobs", "11.0.0-beta.1", "MyApp", 201402L);
EXPECT_GE(ua.length(), 11);
@ -103,7 +108,7 @@ TEST(TelemetryPolicy, UserAgentCppVer)
}
{
const std::string ua = Http::_detail::UserAgentGenerator::GenerateUserAgent(
const std::string ua = Http::_internal::UserAgentGenerator::GenerateUserAgent(
"storage.blobs", "11.0.0-beta.1", "MyApp", 201703L);
EXPECT_GE(ua.length(), 11);

Просмотреть файл

@ -1,14 +1,10 @@
# Release History
## 1.0.0-beta.10 (Unreleased)
### Features Added
### Breaking Changes
## 1.0.0-beta.10 (2024-10-31)
### Bugs Fixed
### Other Changes
- [[#6064]](https://github.com/Azure/azure-sdk-for-cpp/issues/6064) Utilize new telemetry features from Azure Core.
## 1.0.0-beta.9 (2024-06-11)

Просмотреть файл

@ -55,8 +55,13 @@ namespace Azure { namespace Messaging { namespace EventHubs {
-1L
#elif defined(_azure_BUILDING_SAMPLES)
0L
#else
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#if defined(_MSVC_LANG) && __cplusplus == 199711L
_MSVC_LANG
#else
__cplusplus
#endif
#endif
;
};

Просмотреть файл

@ -57,8 +57,13 @@ namespace Azure { namespace Messaging { namespace EventHubs {
-1L
#elif defined(_azure_BUILDING_SAMPLES)
0L
#else
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#if defined(_MSVC_LANG) && __cplusplus == 199711L
_MSVC_LANG
#else
__cplusplus
#endif
#endif
;
};

Просмотреть файл

@ -277,7 +277,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace _detail
#endif
options.Properties.emplace(
"user-agent",
Azure::Core::Http::_detail::UserAgentGenerator::GenerateUserAgent(
Azure::Core::Http::_internal::UserAgentGenerator::GenerateUserAgent(
packageName, PackageVersion::ToString(), applicationId, cplusplusValue));
}

Просмотреть файл

@ -15,6 +15,11 @@
"homepage": "https://github.com/Azure/azure-sdk-for-cpp/tree/main/sdk/eventhubs/azure-messaging-eventhubs",
"license": "MIT",
"dependencies": [
{
"name": "azure-core-cpp",
"default-features": false,
"version>=": "1.14.1"
},
{
"name": "azure-core-amqp-cpp",
"default-features": false,