7#include <aws/core/monitoring/HttpClientMetrics.h>
8#include <aws/core/utils/logging/LogMacros.h>
9#include <smithy/Smithy_EXPORTS.h>
10#include <smithy/tracing/Meter.h>
16 namespace components {
25 static const char COUNT_METRIC_TYPE[];
26 static const char MICROSECOND_METRIC_TYPE[];
27 static const char BYTES_PER_SECOND_METRIC_TYPE[];
28 static const char SMITHY_CLIENT_DURATION_METRIC[];
29 static const char SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC[];
30 static const char SMITHY_CLIENT_DESERIALIZATION_METRIC[];
31 static const char SMITHY_CLIENT_SIGNING_METRIC[];
32 static const char SMITHY_CLIENT_SERIALIZATION_METRIC[];
33 static const char SMITHY_CLIENT_SERVICE_CALL_METRIC[];
34 static const char SMITHY_CLIENT_SERVICE_BACKOFF_DELAY_METRIC[];
35 static const char SMITHY_CLIENT_SERVICE_ATTEMPTS_METRIC[];
36 static const char SMITHY_METHOD_AWS_VALUE[];
37 static const char SMITHY_SERVICE_DIMENSION[];
38 static const char SMITHY_METHOD_DIMENSION[];
39 static const char SMITHY_SYSTEM_DIMENSION[];
40 static const char SMITHY_METRICS_DNS_DURATION[];
41 static const char SMITHY_METRICS_CONNECT_DURATION[];
42 static const char SMITHY_METRICS_SSL_DURATION[];
43 static const char SMITHY_METRICS_DOWNLOAD_SPEED_METRIC[];
44 static const char SMITHY_METRICS_UPLOAD_SPEED_METRIC[];
45 static const char SMITHY_METRICS_UNKNOWN_METRIC[];
65 auto before = std::chrono::steady_clock::now();
66 auto returnValue = func();
67 auto after = std::chrono::steady_clock::now();
68 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(after - before).count();
69 auto histogram = meter.
CreateHistogram(metricName, MICROSECOND_METRIC_TYPE, description);
71 AWS_LOG_ERROR(
"TracingUtil",
"Failed to create histogram");
93 auto before = std::chrono::steady_clock::now();
95 auto after = std::chrono::steady_clock::now();
96 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(after - before).count();
97 auto histogram = meter.
CreateHistogram(std::move(metricName), MICROSECOND_METRIC_TYPE, std::move(description));
99 AWS_LOG_ERROR(
"TracingUtil",
"Failed to create histogram");
117 for (
auto const &entry: metrics) {
118 auto smithyMetric = ConvertCoreMetricToSmithy(entry.first);
119 if (smithyMetric.first != SMITHY_METRICS_UNKNOWN_METRIC) {
122 std::move(description));
124 AWS_LOG_ERROR(
"TracingUtil",
"Failed to create histogram");
126 histogram->record((
double) entry.second, attributes);
140 std::pair<int, std::pair<Aws::String, Aws::String>>(
142 std::make_pair(SMITHY_METRICS_DNS_DURATION, MICROSECOND_METRIC_TYPE)),
143 std::pair<
int, std::pair<Aws::String, Aws::String>>(
145 std::make_pair(SMITHY_METRICS_CONNECT_DURATION, MICROSECOND_METRIC_TYPE)),
146 std::pair<
int, std::pair<Aws::String, Aws::String>>(
148 std::make_pair(SMITHY_METRICS_SSL_DURATION, MICROSECOND_METRIC_TYPE)),
149 std::pair<
int, std::pair<Aws::String, Aws::String>>(
151 std::make_pair(SMITHY_METRICS_DOWNLOAD_SPEED_METRIC, BYTES_PER_SECOND_METRIC_TYPE)),
152 std::pair<
int, std::pair<Aws::String, Aws::String>>(
154 std::make_pair(SMITHY_METRICS_UPLOAD_SPEED_METRIC, BYTES_PER_SECOND_METRIC_TYPE)),
158 auto it = metricsTypeToName.find(
static_cast<int>(metricType));
159 if (it == metricsTypeToName.end()) {
160 return std::make_pair(SMITHY_METRICS_UNKNOWN_METRIC,
"unknown");
virtual Aws::UniquePtr< Histogram > CreateHistogram(Aws::String name, Aws::String units, Aws::String description) const =0
static void EmitCoreHttpMetrics(const Aws::Monitoring::HttpClientMetricsCollection &metrics, const Meter &meter, Aws::Map< Aws::String, Aws::String > &&attributes, Aws::String description="")
static T MakeCallWithTiming(std::function< T()> func, const Aws::String &metricName, const Meter &meter, Aws::Map< Aws::String, Aws::String > &&attributes, const Aws::String &description="")
static std::pair< Aws::String, Aws::String > ConvertCoreMetricToSmithy(const Aws::String &name)
static void MakeCallWithTiming(std::function< void(void)> func, Aws::String metricName, const Meter &meter, Aws::Map< Aws::String, Aws::String > &&attributes, Aws::String description="")
Aws::Map< Aws::String, int64_t > HttpClientMetricsCollection
AWS_CORE_API HttpClientMetricsType GetHttpClientMetricTypeByName(const Aws::String &name)
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String