Skip to content

Commit

Permalink
Integrate Sentry for better error tracking
Browse files Browse the repository at this point in the history
Sentry has been included to improve error tracking. It has been set to
tag plugins, Cura version and machine names, allowing more specific and
convenient debugging. The actual CuraEngine version has now been set as
the Sentry release.

Contributes to CURA-11443
  • Loading branch information
jellespijker committed Dec 10, 2023
1 parent b7a7a87 commit 2c1ac28
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,13 @@ target_link_libraries(_CuraEngine
asio-grpc::asio-grpc
grpc::grpc
protobuf::libprotobuf
$<$<BOOL:${ENABLE_SENTRY}>:sentry::sentry>
$<$<BOOL:${ENABLE_TESTING}>:GTest::gtest>)

target_compile_definitions(_CuraEngine PRIVATE
$<$<BOOL:${ENABLE_SENTRY}>:SENTRY_URL=\"${SENTRY_URL}\">
)

if (NOT WIN32)
add_executable(CuraEngine src/main.cpp) # Then compile main.cpp as separate executable, and link the library to it.
else ()
Expand Down
11 changes: 10 additions & 1 deletion src/Slice.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright (c) 2022 Ultimaker B.V.
// Copyright (c) 2023 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#include "Slice.h"

#include <spdlog/spdlog.h>
#ifdef SENTRY_URL
#include <sentry.h>
#endif

#include "ExtruderTrain.h"

Expand All @@ -18,6 +21,12 @@ Slice::Slice(const size_t num_mesh_groups)
void Slice::compute()
{
spdlog::info("All settings: {}", scene.getAllSettingsString());
#ifdef SENTRY_URL
{
sentry_set_tag("cura.machine_name", scene.settings.get<std::string>("machine_name").c_str());
}
#endif

for (std::vector<MeshGroup>::iterator mesh_group = scene.mesh_groups.begin(); mesh_group != scene.mesh_groups.end(); mesh_group++)
{
scene.current_mesh_group = mesh_group;
Expand Down
8 changes: 8 additions & 0 deletions src/communication/ArcusCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <Arcus/Socket.h> //The socket to communicate to.
#include <fmt/format.h>
#include <spdlog/spdlog.h>
#ifdef SENTRY_URL
#include <sentry.h>
#endif

#include "Application.h" //To get and set the current slice command.
#include "ExtruderTrain.h"
Expand Down Expand Up @@ -521,6 +524,11 @@ void ArcusCommunication::sliceNext()
#ifdef ENABLE_PLUGINS
for (const auto& plugin : slice_message->engine_plugins())
{
#ifdef SENTRY_URL
{
sentry_set_tag(fmt::format("plugin.{}", plugin.plugin_name()).c_str(), plugin.plugin_version().c_str());
}
#endif
const auto slot_id = static_cast<plugins::v0::SlotID>(plugin.id());
slots::instance().connect(slot_id, plugin.plugin_name(), plugin.plugin_version(), utils::createChannel({ plugin.address(), plugin.port() }));
}
Expand Down
20 changes: 9 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,21 @@ int main(int argc, char** argv)
{
// Not a production build
sentry_options_set_environment(options, "development");
sentry_options_set_release(
options,
fmt::format(
"curaengine@{}.{}.{}-{}.{}",
version.major,
version.minor,
version.patch,
version.prerelease_type == semver::prerelease::alpha ? "alpha" : "beta",
version.prerelease_number)
.c_str());
}
else
{
sentry_options_set_environment(options, "production");
sentry_options_set_release(options, fmt::format("curaengine@{}", version.to_string()).c_str());
}

// Set the actual CuraEngine version
sentry_options_set_release(options, fmt::format("curaengine@{}", cura_engine_version).c_str());
sentry_init(options);

// Set the presumed Cura version as a Sentry tag (this is unknown at the time of compiling
auto prerelease = version.prerelease_type == semver::prerelease::none
? ""
: fmt::format("-{}.{}", version.prerelease_type == semver::prerelease::alpha ? "alpha" : "beta", version.prerelease_number);
sentry_set_tag("cura.version", fmt::format("{}.{}.{}{}", version.major, version.minor, version.patch, prerelease).c_str());
}
#endif

Expand Down

0 comments on commit 2c1ac28

Please sign in to comment.