26#include <magic_enum.hpp>
30#include <wx/filename.h>
33#include <boost/uuid/uuid_io.hpp>
34#include <boost/uuid/uuid_generators.hpp>
37#ifdef KICAD_USE_SENTRY
52#ifdef KICAD_USE_SENTRY
60#ifdef KICAD_USE_SENTRY
68#ifdef KICAD_USE_SENTRY
69 sentry_set_tag( aKey.c_str(), aValue.c_str() );
76#ifdef KICAD_USE_SENTRY
86 sentryInitFile.Write(
"" );
87 sentryInitFile.Close();
110 boost::uuids::uuid uuid = boost::uuids::random_generator()();
111 wxString userGuid = boost::uuids::to_string( uuid );
114 sentryInitFile.Write( userGuid );
115 sentryInitFile.Close();
139 sentryInitFile.Close();
151#ifdef KICAD_USE_SENTRY
161 sentry_options_t* options = sentry_options_new();
163#ifndef KICAD_SENTRY_DSN
164#error "Project configuration error, missing KICAD_SENTRY_DSN"
167 sentry_options_set_traces_sample_rate( options, 0.05 );
168 sentry_options_set_dsn( options, KICAD_SENTRY_DSN );
173 if( wxFileExists( handlerPath ) )
174 sentry_options_set_handler_path( options, handlerPath.c_str() );
179 tmp.AppendDir(
"sentry" );
182 sentry_options_set_database_pathw( options, tmp.GetPathWithSep().wc_str() );
184 sentry_options_set_database_path( options, tmp.GetPathWithSep().c_str() );
186 sentry_options_set_symbolize_stacktraces( options,
true );
187 sentry_options_set_auto_session_tracking( options,
false );
189 sentry_options_set_release( options,
GetCommitHash().ToStdString().c_str() );
195 sentry_init( options );
197 sentry_value_t user = sentry_value_new_object();
198 sentry_value_set_by_key( user,
"id", sentry_value_new_string(
m_sentryUid.c_str() ) );
199 sentry_set_user( user );
201 sentry_set_tag(
"kicad.version",
GetBuildVersion().ToStdString().c_str() );
222#ifdef KICAD_USE_SENTRY
239#ifdef KICAD_USE_SENTRY
249 sentry_value_t exc = sentry_value_new_exception(
"assert", aAssertMsg.c_str() );
250 sentry_value_set_stacktrace( exc, NULL, 0 );
252 sentry_value_t sentryEvent = sentry_value_new_event();
253 sentry_event_add_exception( sentryEvent, exc );
254 sentry_capture_event( sentryEvent );
263#ifdef KICAD_USE_SENTRY
269 sentry_scope_t* local_scope = sentry_local_scope_new();
270 sentry_scope_set_tag( local_scope,
"unhandled", aUnhandled ?
"true" :
"false" );
272 sentry_value_t exc = sentry_value_new_exception(
"exception", aMsg.c_str() );
273 sentry_value_set_stacktrace( exc, NULL, 0 );
275 sentry_value_t sentryEvent = sentry_value_new_event();
276 sentry_event_add_exception( sentryEvent, exc );
277 sentry_capture_event_with_scope( sentryEvent, local_scope );
281#ifdef KICAD_USE_SENTRY
291 std::string ret( magic_enum::enum_name( aType ) );
293 std::transform( ret.begin(), ret.end(), ret.begin(),
294 [](
unsigned char c )
296 return std::tolower( c );
312 std::string ret( magic_enum::enum_name( aLevel ) );
314 std::transform( ret.begin(), ret.end(), ret.begin(),
315 [](
unsigned char c )
317 return std::tolower( c );
346#ifdef KICAD_USE_SENTRY
352 std::string type = GetSentryBreadCrumbType( aType );
353 sentry_value_t crumb = sentry_value_new_breadcrumb( type.c_str(), aMsg.c_str() );
355 sentry_value_set_by_key( crumb,
"category", sentry_value_new_string( aCategory.c_str() ) );
359 std::string level = GetSentryBreadCrumbLevel( aLevel );
360 sentry_value_set_by_key( crumb,
"level", sentry_value_new_string( level.c_str() ) );
363 sentry_add_breadcrumb( crumb );
370#ifdef KICAD_USE_SENTRY
378#ifdef KICAD_USE_SENTRY
383#ifdef KICAD_USE_SENTRY
384class TRANSACTION_IMPL
387 TRANSACTION_IMPL(
const std::string& aName,
const std::string& aOperation )
389 m_ctx = sentry_transaction_context_new( aName.c_str(), aOperation.c_str() );
392 ~TRANSACTION_IMPL() {
400 m_tx = sentry_transaction_start( m_ctx, sentry_value_new_null() );
409 sentry_transaction_finish( m_tx );
414 void StartSpan(
const std::string& aOperation,
const std::string& aDescription )
422 m_span = sentry_transaction_start_child( m_tx, aOperation.c_str(), aDescription.c_str() );
429 sentry_span_finish( m_span );
435 sentry_transaction_context_t* m_ctx =
nullptr;
436 sentry_transaction_t* m_tx =
nullptr;
437 sentry_span_t* m_span =
nullptr;
445#ifdef KICAD_USE_SENTRY
448 m_impl =
new TRANSACTION_IMPL( aName, aOperation );
456#ifdef KICAD_USE_SENTRY
464#ifdef KICAD_USE_SENTRY
475#ifdef KICAD_USE_SENTRY
478 m_impl->StartSpan( aOperation, aDescription );
486#ifdef KICAD_USE_SENTRY
497#ifdef KICAD_USE_SENTRY
500 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...