@@ -45,47 +45,10 @@ const std::string kResponseLatency = "response.latency";
45
45
const std::string kResponseSize = " response.size" ;
46
46
const std::string kResponseTime = " response.time" ;
47
47
48
- Attributes::Value StringValue (const std::string& str) {
49
- Attributes::Value v;
50
- v.type = Attributes::Value::STRING;
51
- v.str_v = str;
52
- return v;
53
- }
54
-
55
- Attributes::Value StringMapValue (
56
- std::map<std::string, std::string>&& string_map) {
57
- Attributes::Value v;
58
- v.type = Attributes::Value::STRING_MAP;
59
- v.string_map_v .swap (string_map);
60
- return v;
61
- }
62
-
63
- Attributes::Value Int64Value (int64_t value) {
64
- Attributes::Value v;
65
- v.type = Attributes::Value::INT64;
66
- v.value .int64_v = value;
67
- return v;
68
- }
69
-
70
- Attributes::Value TimeValue (
71
- std::chrono::time_point<std::chrono::system_clock> value) {
72
- Attributes::Value v;
73
- v.type = Attributes::Value::TIME;
74
- v.time_v = value;
75
- return v;
76
- }
77
-
78
- Attributes::Value DurationValue (std::chrono::nanoseconds value) {
79
- Attributes::Value v;
80
- v.type = Attributes::Value::DURATION;
81
- v.duration_nanos_v = value;
82
- return v;
83
- }
84
-
85
48
void SetStringAttribute (const std::string& name, const std::string& value,
86
49
Attributes* attr) {
87
50
if (!value.empty ()) {
88
- attr->attributes [name] = StringValue (value);
51
+ attr->attributes [name] = Attributes:: StringValue (value);
89
52
}
90
53
}
91
54
@@ -105,39 +68,43 @@ void FillRequestHeaderAttributes(const HeaderMap& header_map,
105
68
Attributes* attr) {
106
69
SetStringAttribute (kRequestPath , header_map.Path ()->value ().c_str (), attr);
107
70
SetStringAttribute (kRequestHost , header_map.Host ()->value ().c_str (), attr);
108
- attr->attributes [kRequestTime ] = TimeValue (std::chrono::system_clock::now ());
71
+ attr->attributes [kRequestTime ] =
72
+ Attributes::TimeValue (std::chrono::system_clock::now ());
109
73
attr->attributes [kRequestHeaders ] =
110
- StringMapValue (ExtractHeaders (header_map));
74
+ Attributes:: StringMapValue (ExtractHeaders (header_map));
111
75
}
112
76
113
77
void FillResponseHeaderAttributes (const HeaderMap* header_map,
114
78
Attributes* attr) {
115
79
if (header_map) {
116
80
attr->attributes [kResponseHeaders ] =
117
- StringMapValue (ExtractHeaders (*header_map));
81
+ Attributes:: StringMapValue (ExtractHeaders (*header_map));
118
82
}
119
- attr->attributes [kResponseTime ] = TimeValue (std::chrono::system_clock::now ());
83
+ attr->attributes [kResponseTime ] =
84
+ Attributes::TimeValue (std::chrono::system_clock::now ());
120
85
}
121
86
122
87
void FillRequestInfoAttributes (const AccessLog::RequestInfo& info,
123
88
int check_status_code, Attributes* attr) {
124
89
if (info.bytesReceived () >= 0 ) {
125
- attr->attributes [kRequestSize ] = Int64Value (info.bytesReceived ());
90
+ attr->attributes [kRequestSize ] =
91
+ Attributes::Int64Value (info.bytesReceived ());
126
92
}
127
93
if (info.bytesSent () >= 0 ) {
128
- attr->attributes [kResponseSize ] = Int64Value (info.bytesSent ());
94
+ attr->attributes [kResponseSize ] = Attributes:: Int64Value (info.bytesSent ());
129
95
}
130
96
131
97
if (info.duration ().count () > 0 ) {
132
- attr->attributes [kResponseLatency ] = DurationValue (
98
+ attr->attributes [kResponseLatency ] = Attributes:: DurationValue (
133
99
std::chrono::duration_cast<std::chrono::nanoseconds>(info.duration ()));
134
100
}
135
101
136
102
if (info.responseCode ().valid ()) {
137
103
attr->attributes [kResponseHttpCode ] =
138
- Int64Value (info.responseCode ().value ());
104
+ Attributes:: Int64Value (info.responseCode ().value ());
139
105
} else {
140
- attr->attributes [kResponseHttpCode ] = Int64Value (check_status_code);
106
+ attr->attributes [kResponseHttpCode ] =
107
+ Attributes::Int64Value (check_status_code);
141
108
}
142
109
}
143
110
0 commit comments