AWS SDK for C++

AWS SDK for C++ Version 1.11.929

Loading...
Searching...
No Matches
TracingUtils.h
1
5#pragma once
6
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>
11#include <functional>
12#include <chrono>
13#include <utility>
14
15namespace smithy {
16 namespace components {
17 namespace tracing {
21 class SMITHY_API TracingUtils {
22 using SteadyTime = std::chrono::steady_clock::time_point;
23
24 static void RecordExecutionDuration(
25 SteadyTime before,
26 SteadyTime after,
27 Aws::String metricName,
28 const Meter &meter,
30 Aws::String description
31 );
32 public:
34 public:
35 ScopedMetricTimer(Aws::String metricName, std::shared_ptr<Meter> meter, Aws::Map<Aws::String, Aws::String> attributes);
39 private:
40 std::chrono::steady_clock::time_point m_start;
41 Aws::String m_metricName;
42 std::shared_ptr<Meter> m_meter;
44 };
45
46 TracingUtils() = default;
47
48 static const char COUNT_METRIC_TYPE[];
49 static const char MICROSECOND_METRIC_TYPE[];
50 static const char BYTES_PER_SECOND_METRIC_TYPE[];
51 static const char SMITHY_CLIENT_DURATION_METRIC[];
52 static const char SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC[];
53 static const char SMITHY_CLIENT_DESERIALIZATION_METRIC[];
54 static const char SMITHY_CLIENT_SIGNING_METRIC[];
55 static const char SMITHY_CLIENT_SERIALIZATION_METRIC[];
56 static const char SMITHY_CLIENT_SERVICE_CALL_METRIC[];
57 static const char SMITHY_CLIENT_SERVICE_BACKOFF_DELAY_METRIC[];
58 static const char SMITHY_CLIENT_SERVICE_ATTEMPTS_METRIC[];
59 static const char SMITHY_METHOD_AWS_VALUE[];
60 static const char SMITHY_SERVICE_DIMENSION[];
61 static const char SMITHY_METHOD_DIMENSION[];
62 static const char SMITHY_SYSTEM_DIMENSION[];
63 static const char SMITHY_METRICS_DNS_DURATION[];
64 static const char SMITHY_METRICS_CONNECT_DURATION[];
65 static const char SMITHY_METRICS_SSL_DURATION[];
66 static const char SMITHY_METRICS_DOWNLOAD_SPEED_METRIC[];
67 static const char SMITHY_METRICS_UPLOAD_SPEED_METRIC[];
68 static const char SMITHY_METRICS_UNKNOWN_METRIC[];
69
81 template<typename T>
82 static T MakeCallWithTiming(std::function<T()> func,
83 const Aws::String &metricName,
84 const Meter &meter,
86 const Aws::String &description = "")
87 {
88 auto before = std::chrono::steady_clock::now();
89 auto returnValue = func();
90 auto after = std::chrono::steady_clock::now();
91 RecordExecutionDuration(before, after, metricName, meter, attributes, description);
92 return returnValue;
93 }
94
104 static void MakeCallWithTiming(std::function<void(void)> func,
105 Aws::String metricName,
106 const Meter &meter,
108 Aws::String description = "")
109 {
110 auto before = std::chrono::steady_clock::now();
111 func();
112 auto after = std::chrono::steady_clock::now();
113 RecordExecutionDuration(before, after, std::move(metricName), meter, std::move(attributes), std::move(description));
114 }
115
124 const Meter &meter,
126 Aws::String description = "")
127 {
128 for (auto const &entry: metrics) {
129 auto smithyMetric = ConvertCoreMetricToSmithy(entry.first);
130 if (smithyMetric.first != SMITHY_METRICS_UNKNOWN_METRIC) {
131 auto histogram = meter.CreateHistogram(std::move(smithyMetric.first),
132 smithyMetric.second,
133 std::move(description));
134 if (!histogram) {
135 AWS_LOG_ERROR("TracingUtil", "Failed to create histogram");
136 } else {
137 histogram->record((double) entry.second, attributes);
138 }
139 }
140 }
141 }
142
148 static std::pair<Aws::String, Aws::String> ConvertCoreMetricToSmithy(const Aws::String &name) {
150 {
152 return std::make_pair(SMITHY_METRICS_DNS_DURATION, MICROSECOND_METRIC_TYPE);
154 return std::make_pair(SMITHY_METRICS_CONNECT_DURATION, MICROSECOND_METRIC_TYPE);
156 return std::make_pair(SMITHY_METRICS_SSL_DURATION, MICROSECOND_METRIC_TYPE);
158 return std::make_pair(SMITHY_METRICS_DOWNLOAD_SPEED_METRIC, BYTES_PER_SECOND_METRIC_TYPE);
160 return std::make_pair(SMITHY_METRICS_UPLOAD_SPEED_METRIC, BYTES_PER_SECOND_METRIC_TYPE);
161 default:
162 return std::make_pair(SMITHY_METRICS_UNKNOWN_METRIC, "unknown");
163 }
164 }
165 };
166 }
167 }
168}
virtual Aws::UniquePtr< Histogram > CreateHistogram(Aws::String name, Aws::String units, Aws::String description) const =0
ScopedMetricTimer(Aws::String metricName, std::shared_ptr< Meter > meter, Aws::Map< Aws::String, Aws::String > attributes)
ScopedMetricTimer & operator=(const ScopedMetricTimer &)=delete
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
Definition AWSMap.h:20
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97