22#include <magic_enum.hpp>
26#include <wx/filename.h>
29#include <boost/uuid/uuid_io.hpp>
30#include <boost/uuid/uuid_generators.hpp>
33#ifdef KICAD_USE_SENTRY
48#ifdef KICAD_USE_SENTRY
56#ifdef KICAD_USE_SENTRY
64#ifdef KICAD_USE_SENTRY
65 sentry_set_tag( aKey.c_str(), aValue.c_str() );
72#ifdef KICAD_USE_SENTRY
82 sentryInitFile.Write(
"" );
83 sentryInitFile.Close();
106 boost::uuids::uuid uuid = boost::uuids::random_generator()();
107 wxString userGuid = boost::uuids::to_string( uuid );
110 sentryInitFile.Write( userGuid );
111 sentryInitFile.Close();
135 sentryInitFile.Close();
147#ifdef KICAD_USE_SENTRY
157 sentry_options_t* options = sentry_options_new();
159#ifndef KICAD_SENTRY_DSN
160#error "Project configuration error, missing KICAD_SENTRY_DSN"
163 sentry_options_set_traces_sample_rate( options, 0.05 );
164 sentry_options_set_dsn( options, KICAD_SENTRY_DSN );
169 if( wxFileExists( handlerPath ) )
170 sentry_options_set_handler_path( options, handlerPath.c_str() );
175 tmp.AppendDir(
"sentry" );
178 sentry_options_set_database_pathw( options, tmp.GetPathWithSep().wc_str() );
180 sentry_options_set_database_path( options, tmp.GetPathWithSep().c_str() );
182 sentry_options_set_symbolize_stacktraces( options,
true );
183 sentry_options_set_auto_session_tracking( options,
false );
185 sentry_options_set_release( options,
GetCommitHash().ToStdString().c_str() );
191 sentry_init( options );
193 sentry_value_t user = sentry_value_new_object();
194 sentry_value_set_by_key( user,
"id", sentry_value_new_string(
m_sentryUid.c_str() ) );
195 sentry_set_user( user );
197 sentry_set_tag(
"kicad.version",
GetBuildVersion().ToStdString().c_str() );
218#ifdef KICAD_USE_SENTRY
235#ifdef KICAD_USE_SENTRY
245 sentry_value_t exc = sentry_value_new_exception(
"assert", aAssertMsg.c_str() );
246 sentry_value_set_stacktrace( exc, NULL, 0 );
248 sentry_value_t sentryEvent = sentry_value_new_event();
249 sentry_event_add_exception( sentryEvent, exc );
250 sentry_capture_event( sentryEvent );
259#ifdef KICAD_USE_SENTRY
265 sentry_scope_t* local_scope = sentry_local_scope_new();
266 sentry_scope_set_tag( local_scope,
"unhandled", aUnhandled ?
"true" :
"false" );
268 sentry_value_t exc = sentry_value_new_exception(
"exception", aMsg.c_str() );
269 sentry_value_set_stacktrace( exc, NULL, 0 );
271 sentry_value_t sentryEvent = sentry_value_new_event();
272 sentry_event_add_exception( sentryEvent, exc );
273 sentry_capture_event_with_scope( sentryEvent, local_scope );
277#ifdef KICAD_USE_SENTRY
287 std::string ret( magic_enum::enum_name( aType ) );
289 std::transform( ret.begin(), ret.end(), ret.begin(),
290 [](
unsigned char c )
292 return std::tolower( c );
308 std::string ret( magic_enum::enum_name( aLevel ) );
310 std::transform( ret.begin(), ret.end(), ret.begin(),
311 [](
unsigned char c )
313 return std::tolower( c );
342#ifdef KICAD_USE_SENTRY
348 std::string type = GetSentryBreadCrumbType( aType );
349 sentry_value_t crumb = sentry_value_new_breadcrumb( type.c_str(), aMsg.c_str() );
351 sentry_value_set_by_key( crumb,
"category", sentry_value_new_string( aCategory.c_str() ) );
355 std::string level = GetSentryBreadCrumbLevel( aLevel );
356 sentry_value_set_by_key( crumb,
"level", sentry_value_new_string( level.c_str() ) );
359 sentry_add_breadcrumb( crumb );
366#ifdef KICAD_USE_SENTRY
374#ifdef KICAD_USE_SENTRY
379#ifdef KICAD_USE_SENTRY
380class TRANSACTION_IMPL
383 TRANSACTION_IMPL(
const std::string& aName,
const std::string& aOperation )
385 m_ctx = sentry_transaction_context_new( aName.c_str(), aOperation.c_str() );
388 ~TRANSACTION_IMPL() {
396 m_tx = sentry_transaction_start( m_ctx, sentry_value_new_null() );
405 sentry_transaction_finish( m_tx );
410 void StartSpan(
const std::string& aOperation,
const std::string& aDescription )
418 m_span = sentry_transaction_start_child( m_tx, aOperation.c_str(), aDescription.c_str() );
425 sentry_span_finish( m_span );
431 sentry_transaction_context_t* m_ctx =
nullptr;
432 sentry_transaction_t* m_tx =
nullptr;
433 sentry_span_t* m_span =
nullptr;
441#ifdef KICAD_USE_SENTRY
444 m_impl =
new TRANSACTION_IMPL( aName, aOperation );
452#ifdef KICAD_USE_SENTRY
460#ifdef KICAD_USE_SENTRY
471#ifdef KICAD_USE_SENTRY
474 m_impl->StartSpan( aOperation, aDescription );
482#ifdef KICAD_USE_SENTRY
493#ifdef KICAD_USE_SENTRY
496 m_impl->FinishSpan();
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
wxString GetCommitHash()
Get the commit hash as a string.
wxString GetBuildVersion()
Get the full KiCad version string.
This is a singleton class intended to manage sentry.
std::set< ASSERT_CACHE_KEY > m_assertCache
bool isConfiguredOptedIn()
wxString sentryCreateUid()
wxFileName m_sentry_uid_fn
void LogAssert(const ASSERT_CACHE_KEY &aKey, const wxString &aMsg)
void SetSentryOptIn(bool aOptIn)
void LogException(const wxString &aMsg, bool aUnhandled)
void AddTag(const wxString &aKey, const wxString &aValue)
static SENTRY * m_instance
wxFileName m_sentry_optin_fn
static SENTRY * Instance()
const wxString & GetSentryId()
void StartSpan(const std::string &aOperation, const std::string &aDescription)
TRANSACTION(const std::string &aName, const std::string &aOperation)
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
static const wxString & GetExecutablePath()
void AddTransactionBreadcrumb(const wxString &aMsg, const wxString &aCategory)
Add a transaction breadcrumb.
void AddBreadcrumb(BREADCRUMB_TYPE aType, const wxString &aMsg, const wxString &aCategory, BREADCRUMB_LEVEL aLevel)
Add a sentry breadcrumb.
void AddNavigationBreadcrumb(const wxString &aMsg, const wxString &aCategory)
Add a navigation breadcrumb.
bool operator<(const ASSERT_CACHE_KEY &aKey1, const ASSERT_CACHE_KEY &aKey2)
#define POLICY_KEY_DATACOLLECTION
This struct represents a key being used for the std::set that deduplicates asserts during this runnin...