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 
   51#ifdef KICAD_USE_SENTRY 
 
   59#ifdef KICAD_USE_SENTRY 
 
   67#ifdef KICAD_USE_SENTRY 
   68    sentry_set_tag( aKey.c_str(), aValue.c_str() );
 
 
   75#ifdef KICAD_USE_SENTRY 
   85            sentryInitFile.Write( 
"" );
 
   86            sentryInitFile.Close();
 
 
  109    boost::uuids::uuid uuid = boost::uuids::random_generator()();
 
  110    wxString           userGuid = boost::uuids::to_string( uuid );
 
  113    sentryInitFile.Write( userGuid );
 
  114    sentryInitFile.Close();
 
 
  138        sentryInitFile.Close();
 
 
  150#ifdef KICAD_USE_SENTRY 
  160        sentry_options_t* options = sentry_options_new();
 
  162#ifndef KICAD_SENTRY_DSN 
  163#error "Project configuration error, missing KICAD_SENTRY_DSN" 
  166        sentry_options_set_traces_sample_rate( options, 0.05 );
 
  167        sentry_options_set_dsn( options, KICAD_SENTRY_DSN );
 
  171        tmp.AppendDir( 
"sentry" );
 
  174        sentry_options_set_database_pathw( options, tmp.GetPathWithSep().wc_str() );
 
  176        sentry_options_set_database_path( options, tmp.GetPathWithSep().c_str() );
 
  178        sentry_options_set_symbolize_stacktraces( options, 
true );
 
  179        sentry_options_set_auto_session_tracking( options, 
false );
 
  181        sentry_options_set_release( options, 
GetCommitHash().ToStdString().c_str() );
 
  187        sentry_init( options );
 
  189        sentry_value_t user = sentry_value_new_object();
 
  190        sentry_value_set_by_key( user, 
"id", sentry_value_new_string( 
m_sentryUid.c_str() ) );
 
  191        sentry_set_user( user );
 
  193        sentry_set_tag( 
"kicad.version", 
GetBuildVersion().ToStdString().c_str() );
 
 
  214#ifdef KICAD_USE_SENTRY 
 
  231#ifdef KICAD_USE_SENTRY 
  241        sentry_value_t exc = sentry_value_new_exception( 
"assert", aAssertMsg.c_str() );
 
  242        sentry_value_set_stacktrace( exc, NULL, 0 );
 
  244        sentry_value_t sentryEvent = sentry_value_new_event();
 
  245        sentry_event_add_exception( sentryEvent, exc );
 
  246        sentry_capture_event( sentryEvent );
 
 
  255#ifdef KICAD_USE_SENTRY 
  261    sentry_value_t exc = sentry_value_new_exception( 
"exception", aMsg.c_str() );
 
  262    sentry_value_set_stacktrace( exc, NULL, 0 );
 
  264    sentry_value_t sentryEvent = sentry_value_new_event();
 
  265    sentry_event_add_exception( sentryEvent, exc );
 
  266    sentry_capture_event( sentryEvent );
 
 
  270#ifdef KICAD_USE_SENTRY 
  280    std::string ret( magic_enum::enum_name( aType ) );
 
  282    std::transform( ret.begin(), ret.end(), ret.begin(),
 
  283                    []( 
unsigned char c )
 
  285                        return std::tolower( c );
 
  301    std::string ret( magic_enum::enum_name( aLevel ) );
 
  303    std::transform( ret.begin(), ret.end(), ret.begin(),
 
  304                    []( 
unsigned char c )
 
  306                        return std::tolower( c );
 
  326#ifdef KICAD_USE_SENTRY 
  332    std::string    type = GetSentryBreadCrumbType( aType );
 
  333    sentry_value_t crumb = sentry_value_new_breadcrumb( type.c_str(), aMsg.c_str() );
 
  335    sentry_value_set_by_key( crumb, 
"category", sentry_value_new_string( aCategory.c_str() ) );
 
  339        std::string level = GetSentryBreadCrumbLevel( aLevel );
 
  340        sentry_value_set_by_key( crumb, 
"level", sentry_value_new_string( level.c_str() ) );
 
  343    sentry_add_breadcrumb( crumb );
 
 
  350#ifdef KICAD_USE_SENTRY 
 
  358#ifdef KICAD_USE_SENTRY 
 
  363#ifdef KICAD_USE_SENTRY 
  364class TRANSACTION_IMPL
 
  367    TRANSACTION_IMPL( 
const std::string& aName, 
const std::string& aOperation )
 
  369        m_ctx = sentry_transaction_context_new( aName.c_str(), aOperation.c_str() );
 
  372    ~TRANSACTION_IMPL() {
 
  380        m_tx = sentry_transaction_start( m_ctx, sentry_value_new_null() );
 
  389            sentry_transaction_finish( m_tx );
 
  394    void StartSpan( 
const std::string& aOperation, 
const std::string& aDescription )
 
  402        m_span = sentry_transaction_start_child( m_tx, aOperation.c_str(), aDescription.c_str() );
 
  409            sentry_span_finish( m_span );
 
  415    sentry_transaction_context_t* m_ctx = 
nullptr;
 
  416    sentry_transaction_t*         m_tx = 
nullptr;
 
  417    sentry_span_t*                m_span = 
nullptr;
 
 
  425#ifdef KICAD_USE_SENTRY 
  428        m_impl = 
new TRANSACTION_IMPL( aName, aOperation );
 
 
  436#ifdef KICAD_USE_SENTRY 
 
  444#ifdef KICAD_USE_SENTRY 
 
  455#ifdef KICAD_USE_SENTRY 
  458        m_impl->StartSpan( aOperation, aDescription );
 
 
  466#ifdef KICAD_USE_SENTRY 
 
  477#ifdef KICAD_USE_SENTRY 
  480        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)
 
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.
 
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...