Skip to content

Commit 4ce92c9

Browse files
committed
Log API names
1 parent bd1a11b commit 4ce92c9

File tree

7 files changed

+58
-2
lines changed

7 files changed

+58
-2
lines changed

src/aws-cpp-sdk-core/include/aws/core/client/AWSClient.h

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ namespace Aws
7272
typedef Utils::Outcome<std::shared_ptr<Aws::Http::HttpResponse>, AWSError<CoreErrors>> HttpResponseOutcome;
7373
typedef Utils::Outcome<AmazonWebServiceResult<Utils::Stream::ResponseStream>, AWSError<CoreErrors>> StreamOutcome;
7474

75+
class AWS_CORE_API AWSClient;
76+
class FeatureLogger{
77+
public:
78+
void LogFeature(const AWSClient* clientPtr, const std::string& featureMetadata) const;
79+
};
80+
81+
7582
/**
7683
* Abstract AWS Client. Contains most of the functionality necessary to build an http request, get it signed, and send it across the wire.
7784
*/
@@ -333,6 +340,7 @@ namespace Aws
333340
static bool DoesResponseGenerateError(const std::shared_ptr<Aws::Http::HttpResponse>& response);
334341
std::shared_ptr<smithy::components::tracing::TelemetryProvider> m_telemetryProvider;
335342
std::shared_ptr<Aws::Auth::AWSAuthSignerProvider> m_signerProvider;
343+
FeatureLogger m_featureLogger;
336344
private:
337345
/**
338346
* Try to adjust signer's clock
@@ -356,6 +364,8 @@ namespace Aws
356364
Aws::Client::RequestCompressionConfig m_requestCompressionConfig;
357365
std::shared_ptr<smithy::client::UserAgentInterceptor> m_userAgentInterceptor;
358366
Aws::Vector<std::shared_ptr<smithy::interceptor::Interceptor>> m_interceptors;
367+
368+
friend class FeatureLogger;
359369
};
360370

361371
AWS_CORE_API Aws::String GetAuthorizationHeader(const Aws::Http::HttpRequest& httpRequest);

src/aws-cpp-sdk-core/include/aws/core/client/UserAgent.h

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class AWS_CORE_API UserAgent {
3434
Aws::String SerializeWithFeatures(const Aws::Set<UserAgentFeature>& features) const;
3535
void SetApiName(const Aws::String& apiName) { m_api = apiName; }
3636
void AddLegacyFeature(const Aws::String& legacyFeature);
37+
void SetFeatureMetadataIfNotSet(const Aws::String& metadata) { if(m_featureMetadata.empty()){m_featureMetadata = metadata;} }
3738

3839
private:
3940
const Aws::String m_sdkVersion;
@@ -48,6 +49,7 @@ class AWS_CORE_API UserAgent {
4849
const Aws::String m_execEnv;
4950
const Aws::String m_appId;
5051
const Aws::String m_customizations;
52+
Aws::String m_featureMetadata;
5153
Aws::Set<UserAgentFeature> m_features;
5254
};
5355
} // namespace Client

src/aws-cpp-sdk-core/include/smithy/client/features/UserAgentInterceptor.h

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class UserAgentInterceptor : public interceptor::Interceptor {
3535
return context.GetTransmitResponse();
3636
}
3737

38+
void SetFeatureMetadataIfNotSet(const Aws::String& metadata) { m_userAgent.SetFeatureMetadataIfNotSet(metadata); }
39+
3840
void SetApiName(const Aws::String& apiName) { m_userAgent.SetApiName(apiName); }
3941

4042
void AddLegacyFeaturesToUserAgent(const Aws::String& valueToAppend) { m_userAgent.AddLegacyFeature(valueToAppend); }

src/aws-cpp-sdk-core/source/client/AWSClient.cpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& u
667667
const char* signerRegionOverride,
668668
const char* signerServiceNameOverride) const
669669
{
670+
m_featureLogger.LogFeature(this, __func__);
670671
HttpResponseOutcome httpResponseOutcome = AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride);
671672
if (httpResponseOutcome.IsSuccess())
672673
{
@@ -685,6 +686,7 @@ StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& u
685686
const char* signerRegionOverride,
686687
const char* signerServiceNameOverride) const
687688
{
689+
m_featureLogger.LogFeature(this, __func__);
688690
HttpResponseOutcome httpResponseOutcome = AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride);
689691
if (httpResponseOutcome.IsSuccess())
690692
{
@@ -703,6 +705,7 @@ StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::AmazonWebSer
703705
const char* signerRegionOverride,
704706
const char* signerServiceNameOverride) const
705707
{
708+
m_featureLogger.LogFeature(this, __func__);
706709
const Aws::Http::URI& uri = endpoint.GetURI();
707710
if (endpoint.GetAttributes()) {
708711
signerName = endpoint.GetAttributes()->authScheme.GetName().c_str();
@@ -727,6 +730,7 @@ XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::AmazonWebServiceR
727730
const char* signerRegionOverride,
728731
const char* signerServiceNameOverride) const
729732
{
733+
m_featureLogger.LogFeature(this, __func__);
730734
const Aws::Http::URI& uri = endpoint.GetURI();
731735
if (endpoint.GetAttributes()) {
732736
signerName = endpoint.GetAttributes()->authScheme.GetName().c_str();
@@ -751,6 +755,7 @@ XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri,
751755
const char* signerRegionOverride,
752756
const char* signerServiceNameOverride) const
753757
{
758+
m_featureLogger.LogFeature(this, __func__);
754759
HttpResponseOutcome httpOutcome = AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride);
755760
if (httpOutcome.IsSuccess())
756761
{
@@ -767,6 +772,7 @@ XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri,
767772
const char* signerRegionOverride,
768773
const char* signerServiceNameOverride) const
769774
{
775+
m_featureLogger.LogFeature(this, __func__);
770776
HttpResponseOutcome httpOutcome = AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride);
771777
if (httpOutcome.IsSuccess())
772778
{
@@ -925,31 +931,37 @@ void AWSClient::BuildHttpRequest(const Aws::AmazonWebServiceRequest& request, co
925931

926932
Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter)
927933
{
934+
m_featureLogger.LogFeature(this, __func__);
928935
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, expirationInSeconds, serviceSpecificParameter);
929936
}
930937

931938
Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter)
932939
{
940+
m_featureLogger.LogFeature(this, __func__);
933941
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, customizedHeaders, expirationInSeconds, serviceSpecificParameter);
934942
}
935943

936944
Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter) const
937945
{
946+
m_featureLogger.LogFeature(this, __func__);
938947
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, region, expirationInSeconds, serviceSpecificParameter);
939948
}
940949

941950
Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter)
942951
{
952+
m_featureLogger.LogFeature(this, __func__);
943953
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, region, customizedHeaders, expirationInSeconds, serviceSpecificParameter);
944954
}
945955

946956
Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter) const
947957
{
958+
m_featureLogger.LogFeature(this, __func__);
948959
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, region, serviceName, expirationInSeconds, serviceSpecificParameter);
949960
}
950961

951962
Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter)
952963
{
964+
m_featureLogger.LogFeature(this, __func__);
953965
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, region, serviceName, customizedHeaders, expirationInSeconds, serviceSpecificParameter);
954966
}
955967

@@ -960,6 +972,7 @@ Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http
960972

961973
Aws::String AWSClient::GeneratePresignedUrl(const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, const char* signerName, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter)
962974
{
975+
m_featureLogger.LogFeature(this, __func__);
963976
return AWSUrlPresigner(*this).GeneratePresignedUrl(uri, method, region, serviceName, signerName, customizedHeaders, expirationInSeconds, serviceSpecificParameter);
964977
}
965978

@@ -972,18 +985,21 @@ Aws::String AWSClient::GeneratePresignedUrl(const Aws::Endpoint::AWSEndpoint& en
972985
const char* signerServiceNameOverride /* = nullptr */,
973986
const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter)
974987
{
988+
m_featureLogger.LogFeature(this, __func__);
975989
return AWSUrlPresigner(*this).GeneratePresignedUrl(endpoint, method, customizedHeaders, expirationInSeconds, signerName, signerRegionOverride, signerServiceNameOverride, serviceSpecificParameter);
976990
}
977991

978992
Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region,
979993
const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter) const
980994
{
995+
m_featureLogger.LogFeature(this, __func__);
981996
return AWSUrlPresigner(*this).GeneratePresignedUrl(request, uri, method, region, extraParams, expirationInSeconds, serviceSpecificParameter);
982997
}
983998

984999
Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, const Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName,
9851000
const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter) const
9861001
{
1002+
m_featureLogger.LogFeature(this, __func__);
9871003
return AWSUrlPresigner(*this).GeneratePresignedUrl(request, uri, method, region, serviceName, extraParams, expirationInSeconds, serviceSpecificParameter);
9881004
}
9891005

@@ -997,17 +1013,20 @@ Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest&
9971013
long long expirationInSeconds,
9981014
const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter) const
9991015
{
1016+
m_featureLogger.LogFeature(this, __func__);
10001017
return AWSUrlPresigner(*this).GeneratePresignedUrl(request, uri, method, region, serviceName, signerName, extraParams, expirationInSeconds, serviceSpecificParameter);
10011018
}
10021019

10031020
Aws::String AWSClient::GeneratePresignedUrl(const Aws::AmazonWebServiceRequest& request, const Aws::Http::URI& uri, Aws::Http::HttpMethod method,
10041021
const Aws::Http::QueryStringParameterCollection& extraParams, long long expirationInSeconds, const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameter) const
10051022
{
1023+
m_featureLogger.LogFeature(this, __func__);
10061024
return AWSUrlPresigner(*this).GeneratePresignedUrl(request, uri, method, extraParams, expirationInSeconds, serviceSpecificParameter);
10071025
}
10081026

10091027
std::shared_ptr<Aws::Http::HttpResponse> AWSClient::MakeHttpRequest(std::shared_ptr<Aws::Http::HttpRequest>& request) const
10101028
{
1029+
m_featureLogger.LogFeature(this, __func__);
10111030
return m_httpClient->MakeRequest(request, m_readRateLimiter.get(), m_writeRateLimiter.get());
10121031
}
10131032

@@ -1045,4 +1064,12 @@ void AWSClient::AppendRecursionDetectionHeader(std::shared_ptr<Aws::Http::HttpRe
10451064
xAmznTraceIdVal = xAmznTraceIdValEncodedStr.str();
10461065

10471066
ioRequest->SetHeaderValue(Aws::Http::X_AMZN_TRACE_ID_HEADER, xAmznTraceIdVal);
1048-
}
1067+
}
1068+
1069+
void FeatureLogger::LogFeature(const AWSClient* clientPtr, const std::string& featureMetadata) const
1070+
{
1071+
if(clientPtr)
1072+
{
1073+
clientPtr->m_userAgentInterceptor->SetFeatureMetadataIfNotSet(featureMetadata);
1074+
}
1075+
}

src/aws-cpp-sdk-core/source/client/AWSJsonClient.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::AmazonWebServiceRequest& reque
5858
const char* signerRegionOverride /* = nullptr */,
5959
const char* signerServiceNameOverride /* = nullptr */) const
6060
{
61+
m_featureLogger.LogFeature(this, __func__);
6162
const Aws::Http::URI& uri = endpoint.GetURI();
6263
if (endpoint.GetAttributes()) {
6364
signerName = endpoint.GetAttributes()->authScheme.GetName().c_str();
@@ -80,6 +81,7 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::Endpoint::AWSEndpoint& endpoin
8081
const char* signerRegionOverride /* = nullptr */,
8182
const char* signerServiceNameOverride /* = nullptr */) const
8283
{
84+
m_featureLogger.LogFeature(this, __func__);
8385
const Aws::Http::URI& uri = endpoint.GetURI();
8486
if (endpoint.GetAttributes()) {
8587
signerName = endpoint.GetAttributes()->authScheme.GetName().c_str();
@@ -103,6 +105,7 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri,
103105
const char* signerRegionOverride,
104106
const char* signerServiceNameOverride) const
105107
{
108+
m_featureLogger.LogFeature(this, __func__);
106109
HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride));
107110
if (!httpOutcome.IsSuccess())
108111
{
@@ -142,6 +145,7 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri,
142145
const char* signerRegionOverride,
143146
const char* signerServiceNameOverride) const
144147
{
148+
m_featureLogger.LogFeature(this, __func__);
145149
HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride));
146150
if (!httpOutcome.IsSuccess())
147151
{
@@ -189,6 +193,7 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri,
189193

190194
JsonOutcome AWSJsonClient::MakeEventStreamRequest(std::shared_ptr<Aws::Http::HttpRequest>& request) const
191195
{
196+
m_featureLogger.LogFeature(this, __func__);
192197
// request is assumed to be signed
193198
std::shared_ptr<HttpResponse> httpResponse = MakeHttpRequest(request);
194199

@@ -223,6 +228,7 @@ JsonOutcome AWSJsonClient::MakeEventStreamRequest(std::shared_ptr<Aws::Http::Htt
223228
AWSError<CoreErrors> AWSJsonClient::BuildAWSError(
224229
const std::shared_ptr<Aws::Http::HttpResponse>& httpResponse) const
225230
{
231+
m_featureLogger.LogFeature(this, __func__);
226232
AWSError<CoreErrors> error;
227233
if (httpResponse->HasClientError())
228234
{

src/aws-cpp-sdk-core/source/client/AWSXmlClient.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ XmlOutcome AWSXMLClient::MakeRequest(const Aws::AmazonWebServiceRequest& request
5252
const char* signerRegionOverride /* = nullptr */,
5353
const char* signerServiceNameOverride /* = nullptr */) const
5454
{
55+
m_featureLogger.LogFeature(this, __func__);
5556
const Aws::Http::URI& uri = endpoint.GetURI();
5657
if (endpoint.GetAttributes()) {
5758
signerName = endpoint.GetAttributes()->authScheme.GetName().c_str();
@@ -98,6 +99,7 @@ XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri,
9899
const char* signerRegionOverride,
99100
const char* signerServiceNameOverride) const
100101
{
102+
m_featureLogger.LogFeature(this, __func__);
101103
HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride));
102104
if (!httpOutcome.IsSuccess())
103105
{
@@ -140,6 +142,7 @@ XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri,
140142
const char* signerRegionOverride,
141143
const char* signerServiceNameOverride) const
142144
{
145+
m_featureLogger.LogFeature(this, __func__);
143146
HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride));
144147
if (!httpOutcome.IsSuccess())
145148
{

src/aws-cpp-sdk-core/source/client/UserAgent.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <numeric>
1414
#include <utility>
15-
15+
#include <iostream>
1616
using namespace Aws::Client;
1717

1818
namespace {
@@ -70,6 +70,7 @@ const char* CPP = "c++";
7070
const char* EXEC_ENV = "exec-env";
7171
const char* APP_ID = "app";
7272
const char* BUSINESS_METRICS = "m";
73+
const char* FEATURE_METADATA = "ft";
7374
} // namespace
7475

7576
UserAgent::UserAgent(const ClientConfiguration& clientConfiguration,
@@ -128,6 +129,11 @@ Aws::String UserAgent::SerializeWithFeatures(const Aws::Set<UserAgentFeature>& f
128129
}
129130

130131
// Does not need to be in order
132+
if (!m_featureMetadata.empty()) {
133+
std::cout<<"m_featureMetadata="<<m_featureMetadata<<std::endl;
134+
SerializeMetadata(FEATURE_METADATA, m_featureMetadata);
135+
}
136+
131137
if (!m_archName.empty()) {
132138
SerializeMetadataWithVersion(METADATA, ARCH, m_archName);
133139
}

0 commit comments

Comments
 (0)