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();
136 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 );
168 tmp.AppendDir(
"sentry" );
171 sentry_options_set_database_pathw( options, tmp.GetPathWithSep().wc_str() );
173 sentry_options_set_database_path( options, tmp.GetPathWithSep().c_str() );
175 sentry_options_set_symbolize_stacktraces( options,
true );
176 sentry_options_set_auto_session_tracking( options,
false );
178 sentry_options_set_release( options,
GetCommitHash().ToStdString().c_str() );
184 sentry_init( options );
186 sentry_value_t user = sentry_value_new_object();
187 sentry_value_set_by_key( user,
"id", sentry_value_new_string(
m_sentryUid.c_str() ) );
188 sentry_set_user( user );
190 sentry_set_tag(
"kicad.version",
GetBuildVersion().ToStdString().c_str() );
211#ifdef KICAD_USE_SENTRY
228#ifdef KICAD_USE_SENTRY
238 sentry_value_t exc = sentry_value_new_exception(
"assert", aAssertMsg.c_str() );
239 sentry_value_set_stacktrace( exc, NULL, 0 );
241 sentry_value_t sentryEvent = sentry_value_new_event();
242 sentry_event_add_exception( sentryEvent, exc );
243 sentry_capture_event( sentryEvent );
252#ifdef KICAD_USE_SENTRY
258 sentry_value_t exc = sentry_value_new_exception(
"exception", aMsg.c_str() );
259 sentry_value_set_stacktrace( exc, NULL, 0 );
261 sentry_value_t sentryEvent = sentry_value_new_event();
262 sentry_event_add_exception( sentryEvent, exc );
263 sentry_capture_event( sentryEvent );
267#ifdef KICAD_USE_SENTRY
277 std::string ret( magic_enum::enum_name( aType ) );
279 std::transform( ret.begin(), ret.end(), ret.begin(),
280 [](
unsigned char c )
282 return std::tolower( c );
298 std::string ret( magic_enum::enum_name( aLevel ) );
300 std::transform( ret.begin(), ret.end(), ret.begin(),
301 [](
unsigned char c )
303 return std::tolower( c );
323#ifdef KICAD_USE_SENTRY
329 std::string type = GetSentryBreadCrumbType( aType );
330 sentry_value_t crumb = sentry_value_new_breadcrumb( type.c_str(), aMsg.c_str() );
332 sentry_value_set_by_key( crumb,
"category", sentry_value_new_string( aCategory.c_str() ) );
336 std::string level = GetSentryBreadCrumbLevel( aLevel );
337 sentry_value_set_by_key( crumb,
"level", sentry_value_new_string( level.c_str() ) );
340 sentry_add_breadcrumb( crumb );
347#ifdef KICAD_USE_SENTRY
355#ifdef KICAD_USE_SENTRY
360#ifdef KICAD_USE_SENTRY
361class TRANSACTION_IMPL
364 TRANSACTION_IMPL(
const std::string& aName,
const std::string& aOperation )
366 m_ctx = sentry_transaction_context_new( aName.c_str(), aOperation.c_str() );
369 ~TRANSACTION_IMPL() {
377 m_tx = sentry_transaction_start( m_ctx, sentry_value_new_null() );
386 sentry_transaction_finish( m_tx );
391 void StartSpan(
const std::string& aOperation,
const std::string& aDescription )
399 m_span = sentry_transaction_start_child( m_tx, aOperation.c_str(), aDescription.c_str() );
406 sentry_span_finish( m_span );
412 sentry_transaction_context_t* m_ctx =
nullptr;
413 sentry_transaction_t* m_tx =
nullptr;
414 sentry_span_t* m_span =
nullptr;
422#ifdef KICAD_USE_SENTRY
425 m_impl =
new TRANSACTION_IMPL( aName, aOperation );
433#ifdef KICAD_USE_SENTRY
441#ifdef KICAD_USE_SENTRY
452#ifdef KICAD_USE_SENTRY
455 m_impl->StartSpan( aOperation, aDescription );
463#ifdef KICAD_USE_SENTRY
474#ifdef KICAD_USE_SENTRY
477 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...