HttpShared::GenerateUserAgent() (#6163)

* Rename UserAgentGenerator

* Update includes

* Clang-format

* Move GenerateUserAgent() to HttpShared class

* Update invocations

* Update invocations

* Clang-format

* Drop unnecessary include

* Update release dates

---------

Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
Anton Kolesnyk 2024-11-01 14:07:45 -07:00 committed by GitHub
parent 3ad8f7254a
commit 0180c8ee5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 37 additions and 57 deletions

View File

@ -1,6 +1,6 @@
# Release History
## 1.14.1 (2024-10-31)
## 1.14.1 (2024-11-01)
### Bugs Fixed

View File

@ -90,7 +90,6 @@ set(
inc/azure/core/internal/extendable_enumeration.hpp
inc/azure/core/internal/http/http_sanitizer.hpp
inc/azure/core/internal/http/pipeline.hpp
inc/azure/core/internal/http/user_agent.hpp
inc/azure/core/internal/io/null_body_stream.hpp
inc/azure/core/internal/json/json.hpp
inc/azure/core/internal/json/json_optional.hpp

View File

@ -412,6 +412,34 @@ namespace Azure { namespace Core { namespace Http {
}
return {}; // empty string
}
/**
* @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);
private:
HttpShared() = delete;
~HttpShared() = delete;
};
} // namespace _internal

View File

@ -15,7 +15,6 @@
#include "azure/core/http/http.hpp"
#include "azure/core/http/transport.hpp"
#include "azure/core/internal/http/http_sanitizer.hpp"
#include "azure/core/internal/http/user_agent.hpp"
#include "azure/core/uuid.hpp"
#include <atomic>
@ -550,7 +549,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::_internal::UserAgentGenerator::GenerateUserAgent(
: m_telemetryId(Azure::Core::Http::_internal::HttpShared::GenerateUserAgent(
packageName,
packageVersion,
options.ApplicationId,

View File

@ -1,44 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @file
* @brief Declaration of the UserAgentGenerator type.
*/
#pragma once
#include <string>
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);
};
}}}} // namespace Azure::Core::Http::_internal

View File

@ -4,7 +4,6 @@
#include "azure/core/context.hpp"
#include "azure/core/internal/client_options.hpp"
#include "azure/core/internal/extendable_enumeration.hpp"
#include "azure/core/internal/http/user_agent.hpp"
#include "azure/core/internal/tracing/tracing_impl.hpp"
#pragma once

View File

@ -7,13 +7,12 @@
*/
#include "azure/core/context.hpp"
#include "azure/core/http/http.hpp"
#include "azure/core/http/policies/policy.hpp"
#include "azure/core/internal/strings.hpp"
#include "azure/core/internal/tracing/service_tracing.hpp"
#include "azure/core/platform.hpp"
#include <azure/core/internal/http/user_agent.hpp>
#include <sstream>
#if defined(AZ_PLATFORM_WINDOWS)
@ -150,7 +149,7 @@ std::string TrimString(std::string s)
namespace Azure { namespace Core { namespace Http { namespace _internal {
std::string UserAgentGenerator::GenerateUserAgent(
std::string HttpShared::GenerateUserAgent(
std::string const& componentName,
std::string const& componentVersion,
std::string const& applicationId,

View File

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

View File

@ -1,6 +1,6 @@
# Release History
## 1.0.0-beta.10 (2024-10-31)
## 1.0.0-beta.10 (2024-11-01)
### Bugs Fixed

View File

@ -14,8 +14,8 @@
#include <azure/core/amqp/internal/management.hpp>
#include <azure/core/amqp/internal/session.hpp>
#include <azure/core/context.hpp>
#include <azure/core/http/http.hpp>
#include <azure/core/internal/diagnostics/log.hpp>
#include <azure/core/internal/http/user_agent.hpp>
#include <chrono>
@ -277,7 +277,7 @@ namespace Azure { namespace Messaging { namespace EventHubs { namespace _detail
#endif
options.Properties.emplace(
"user-agent",
Azure::Core::Http::_internal::UserAgentGenerator::GenerateUserAgent(
Azure::Core::Http::_internal::HttpShared::GenerateUserAgent(
packageName, PackageVersion::ToString(), applicationId, cplusplusValue));
}