@@ -79,38 +79,59 @@ class ResponseHandler : public http_client::EventHandler
79
79
stopping_.store (false );
80
80
}
81
81
82
+ std::string BuildResponseLogMessage (http_client::Response &response,
83
+ const std::string &body) noexcept
84
+ {
85
+ std::stringstream ss;
86
+ ss << " Status:" << response.GetStatusCode () << " Header:" ;
87
+ response.ForEachHeader ([&ss](opentelemetry::nostd::string_view header_name,
88
+ opentelemetry::nostd::string_view header_value) {
89
+ ss << " \t " << header_name.data () << " : " << header_value.data () << " ," ;
90
+ return true ;
91
+ });
92
+ ss << " Body:" << body;
93
+
94
+ return ss.str ();
95
+ }
96
+
82
97
/* *
83
98
* Automatically called when the response is received, store the body into a string and notify any
84
99
* threads blocked on this result
85
100
*/
86
101
void OnResponse (http_client::Response &response) noexcept override
87
102
{
103
+ sdk::common::ExportResult result = sdk::common::ExportResult::kSuccess ;
104
+ std::string log_message;
88
105
// Lock the private members so they can't be read while being modified
89
106
{
90
107
std::unique_lock<std::mutex> lk (mutex_);
91
108
92
109
// Store the body of the request
93
110
body_ = std::string (response.GetBody ().begin (), response.GetBody ().end ());
94
111
112
+ if (response.GetStatusCode () != 200 && response.GetStatusCode () != 202 )
113
+ {
114
+ log_message = BuildResponseLogMessage (response, body_);
115
+
116
+ OTEL_INTERNAL_LOG_ERROR (" OTLP HTTP Client] Export failed, " << log_message);
117
+ result = sdk::common::ExportResult::kFailure ;
118
+ }
119
+
95
120
if (console_debug_)
96
121
{
97
- std::stringstream ss;
98
- ss << " [OTLP HTTP Client] Status:" << response.GetStatusCode () << " Header:" ;
99
- response.ForEachHeader ([&ss](opentelemetry::nostd::string_view header_name,
100
- opentelemetry::nostd::string_view header_value) {
101
- ss << " \t " << header_name.data () << " : " << header_value.data () << " ," ;
102
- return true ;
103
- });
104
- ss << " Body:" << body_;
105
- OTEL_INTERNAL_LOG_DEBUG (ss.str ());
122
+ if (log_message.empty ())
123
+ {
124
+ log_message = BuildResponseLogMessage (response, body_);
125
+ }
126
+ OTEL_INTERNAL_LOG_DEBUG (" [OTLP HTTP Client] Export success, " << log_message);
106
127
}
107
128
}
108
129
109
130
{
110
131
bool expected = false ;
111
132
if (stopping_.compare_exchange_strong (expected, true , std::memory_order_release))
112
133
{
113
- Unbind (sdk::common::ExportResult:: kSuccess );
134
+ Unbind (result );
114
135
}
115
136
}
116
137
}
0 commit comments