3 #include <XLink/XLinkPublicDefines.h>
4 #ifdef DEPTHAI_ENABLE_CURL
8 #include <ghc/filesystem.hpp>
11 #include <nlohmann/json.hpp>
13 #include <system_error>
15 #include "build/version.hpp"
21 namespace logCollection {
32 case X_LINK_ANY_PLATFORM:
33 return "X_LINK_ANY_PLATFORM";
35 return "X_LINK_MYRIAD_X";
37 return "X_LINK_MYRIAD_2";
39 return "INVALID_ENUM_VALUE";
46 return "X_LINK_USB_VSC";
48 return "X_LINK_USB_CDC";
54 return "X_LINK_TCP_IP";
55 case X_LINK_NMB_OF_PROTOCOLS:
56 return "X_LINK_NMB_OF_PROTOCOLS";
57 case X_LINK_ANY_PROTOCOL:
58 return "X_LINK_ANY_PROTOCOL";
60 return "INVALID_ENUM_VALUE";
83 #ifdef DEPTHAI_ENABLE_CURL
87 if(!pipelineData && !crashDumpData) {
88 logger::error(
"Incorrect usage of sendLogsToServer, at least one of the files must be present");
91 cpr::Multipart multipart{};
93 cpr::Buffer pipelineBuffer(pipelineData->
content.begin(), pipelineData->
content.end(),
"pipeline.json");
94 multipart.parts.emplace_back(
"pipelineFile", pipelineBuffer);
95 multipart.parts.emplace_back(
"pipelineId", pipelineData->
sha1Hash);
99 cpr::Buffer crashDumpBuffer(crashDumpData->
content.begin(), crashDumpData->
content.end(),
"crash_dump.json");
100 multipart.parts.emplace_back(
"crashDumpFile", crashDumpBuffer);
101 multipart.parts.emplace_back(
"crashDumpId", crashDumpData->
sha1Hash);
107 std::string daiVersion = fmt::format(
"{}-{}", build::VERSION, build::COMMIT);
108 multipart.parts.emplace_back(
"depthAiVersion", std::move(daiVersion));
109 multipart.parts.emplace_back(
"productId", deviceInfo.
getMxId());
121 logger::info(
"Not sending the logs to the server, as CURL support is disabled");
128 #ifndef DEPTHAI_ENABLE_CURL
129 (void)pipelineSchema;
131 logger::info(
"Compiled without CURL support, not logging pipeline.");
133 namespace fs = ghc::filesystem;
135 auto loggingEnabled =
utility::getEnv(
"DEPTHAI_ENABLE_ANALYTICS_COLLECTION");
136 if(loggingEnabled.empty()) {
141 auto pipelineJson = nlohmann::json(pipelineSchema);
142 std::string pipelineJsonStr = pipelineJson.dump();
145 fs::path pipelineDir = fs::current_path() /
".cache" /
"depthai" /
"pipelines";
146 fs::path pipelinePath = pipelineDir / pipelineSHA1 /
"pipeline.json";
148 if(fs::exists(pipelinePath)) {
155 fs::create_directories(pipelinePath.parent_path(), ec);
157 logger::error(
"Failed to create log directory: {}", ec.message());
161 std::ofstream pipelineFile(pipelinePath);
162 pipelineFile << pipelineJsonStr;
163 pipelineFile.close();
166 pipelineData.
content = std::move(pipelineJsonStr);
167 pipelineData.
sha1Hash = std::move(pipelineSHA1);
179 namespace fs = ghc::filesystem;
182 fs::path logDir = fs::current_path() /
".cache" /
"depthai" /
"crashdumps";
184 fs::path crashDumpPathLocal;
185 if(crashDumpPath.empty()) {
186 crashDumpPathLocal = logDir / crashDumpHash /
"crash_dump.json";
188 crashDumpPathLocal = crashDumpPath;
190 auto errorString = fmt::format(
191 "Device with id {} has crashed. Crash dump logs are stored in: {} - please report to developers.", deviceInfo.
getMxId(), crashDumpPathLocal.string());
194 fs::create_directories(crashDumpPathLocal.parent_path(), ec);
196 logger::error(
"Failed to create log directory: {}", ec.message());
200 std::ofstream crashDumpFile(crashDumpPathLocal);
201 crashDumpFile << crashDumpJson;
202 crashDumpFile.close();
205 #ifdef DEPTHAI_ENABLE_CURL
208 crashDumpData.
content = std::move(crashDumpJson);
214 std::string pipelineJson = nlohmann::json(*pipelineSchema).dump();
216 pipelineData->
content = std::move(pipelineJson);
217 pipelineData->
sha1Hash = std::move(pipelineSHA1);
221 auto loggingDisabled =
utility::getEnv(
"DEPTHAI_DISABLE_CRASHDUMP_COLLECTION");
222 if(loggingDisabled.empty()) {
227 logger::warn(
"Failed to send crash dump logs to the server.");
233 (void)pipelineSchema;