8
8
9
9
#include < chrono>
10
10
#include < iostream>
11
+ #include < fstream>
11
12
#include < ixwebsocket/IXWebSocketHttpHeaders.h>
12
- #include < spdlog/spdlog .h>
13
+ #include < ixcore/utils/IXCoreLogger .h>
13
14
14
15
15
16
namespace ix
@@ -18,6 +19,7 @@ namespace ix
18
19
: _dsn(dsn)
19
20
, _validDsn(false )
20
21
, _luaFrameRegex(" \t ([^/]+):([0-9]+): in function ['<]([^/]+)['>]" )
22
+ , _httpClient(std::make_shared<HttpClient>(true ))
21
23
{
22
24
const std::regex dsnRegex (" (http[s]?)://([^:]+):([^@]+)@([^/]+)/([0-9]+)" );
23
25
std::smatch group;
@@ -169,39 +171,64 @@ namespace ix
169
171
170
172
std::pair<HttpResponsePtr, std::string> SentryClient::send (const Json::Value& msg, bool verbose)
171
173
{
172
- auto args = _httpClient. createRequest ();
174
+ auto args = _httpClient-> createRequest ();
173
175
args->extraHeaders [" X-Sentry-Auth" ] = SentryClient::computeAuthHeader ();
174
176
args->connectTimeout = 60 ;
175
177
args->transferTimeout = 5 * 60 ;
176
178
args->followRedirects = true ;
177
179
args->verbose = verbose;
178
- args->logger = [](const std::string& msg) { spdlog::info ( " request logger: {} " , msg); };
180
+ args->logger = [](const std::string& msg) { ix::IXCoreLogger::Log ( msg. c_str () ); };
179
181
180
182
std::string body = computePayload (msg);
181
- HttpResponsePtr response = _httpClient. post (_url, body, args);
183
+ HttpResponsePtr response = _httpClient-> post (_url, body, args);
182
184
183
- if (verbose)
184
- {
185
- for (auto it : response->headers )
186
- {
187
- spdlog::info (" {}: {}" , it.first , it.second );
188
- }
185
+ return std::make_pair (response, body);
186
+ }
189
187
190
- spdlog::info (" Upload size: {}" , response->uploadSize );
191
- spdlog::info (" Download size: {}" , response->downloadSize );
188
+ // https://sentry.io/api/12345/minidump?sentry_key=abcdefgh");
189
+ std::string SentryClient::computeUrl (const std::string& project, const std::string& key)
190
+ {
191
+ std::stringstream ss;
192
+ ss << " https://sentry.io/api/"
193
+ << project
194
+ << " /minidump?sentry_key="
195
+ << key;
192
196
193
- spdlog::info (" Status: {}" , response->statusCode );
194
- if (response->errorCode != HttpErrorCode::Ok)
195
- {
196
- spdlog::info (" error message: {}" , response->errorMsg );
197
- }
197
+ return ss.str ();
198
+ }
198
199
199
- if (response->headers [" Content-Type" ] != " application/octet-stream" )
200
- {
201
- spdlog::info (" payload: {}" , response->payload );
202
- }
203
- }
200
+ //
201
+ // curl -v -X POST -F upload_file_minidump=@ws/crash.dmp 'https://sentry.io/api/123456/minidump?sentry_key=12344567890'
202
+ //
203
+ void SentryClient::uploadMinidump (
204
+ const std::string& sentryMetadata,
205
+ const std::string& minidumpBytes,
206
+ const std::string& project,
207
+ const std::string& key,
208
+ bool verbose,
209
+ const OnResponseCallback& onResponseCallback)
210
+ {
211
+ std::string multipartBoundary = _httpClient->generateMultipartBoundary ();
204
212
205
- return std::make_pair (response, body);
213
+ auto args = _httpClient->createRequest ();
214
+ args->verb = HttpClient::kPost ;
215
+ args->connectTimeout = 60 ;
216
+ args->transferTimeout = 5 * 60 ;
217
+ args->followRedirects = true ;
218
+ args->verbose = verbose;
219
+ args->multipartBoundary = multipartBoundary;
220
+ args->logger = [](const std::string& msg) { ix::IXCoreLogger::Log (msg.c_str ()); };
221
+
222
+ HttpFormDataParameters httpFormDataParameters;
223
+ httpFormDataParameters[" upload_file_minidump" ] = minidumpBytes;
224
+
225
+ HttpParameters httpParameters;
226
+ httpParameters[" sentry" ] = sentryMetadata;
227
+
228
+ args->url = computeUrl (project, key);
229
+ args->body = _httpClient->serializeHttpFormDataParameters (multipartBoundary, httpFormDataParameters, httpParameters);
230
+
231
+
232
+ _httpClient->performRequest (args, onResponseCallback);
206
233
}
207
234
} // namespace ix
0 commit comments