Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ elseif(SENTRY_BACKEND_NATIVE)
# Build sentry-crash executable for native backend
# Get all sources that were added to sentry target
get_target_property(SENTRY_SOURCES sentry SOURCES)
# Exclude integrations that are not needed in the daemon
list(FILTER SENTRY_SOURCES EXCLUDE REGEX "[/\\\\]integrations[/\\\\]")

# Create daemon executable with same sources (already includes
# sentry_crash_daemon.c and sentry_crash_ipc.c from src/CMakeLists.txt)
Expand All @@ -846,6 +848,7 @@ elseif(SENTRY_BACKEND_NATIVE)
if(SENTRY_COMPILE_DEFS)
# The daemon is always a static executable, never a shared library
list(REMOVE_ITEM SENTRY_COMPILE_DEFS "SENTRY_BUILD_SHARED")
list(FILTER SENTRY_COMPILE_DEFS EXCLUDE REGEX "^SENTRY_INTEGRATION_")
target_compile_definitions(sentry-crash PRIVATE ${SENTRY_COMPILE_DEFS})
endif()

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sentry_target_sources_cwd(sentry
sentry_hint.c
sentry_hint.h
sentry_info.c
sentry_integration.h
sentry_json.c
sentry_json.h
sentry_logger.c
Expand Down
34 changes: 31 additions & 3 deletions src/integrations/sentry_integration_qt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "sentry_integration_qt.h"
#include "sentry_boot.h"

extern "C" {
#include "sentry_alloc.h"
#include "sentry_core.h"
}

#include <QtCore/qglobal.h>
#include <QtCore/qstring.h>
Expand Down Expand Up @@ -52,8 +56,32 @@ sentry_qt_messsage_handler(
originalMessageHandler(type, context, message);
}

void
sentry_integration_setup_qt(void)
static void
register_qt(void *UNUSED(data), sentry_scope_t *UNUSED(scope),
const sentry_options_t *UNUSED(options))
{
SENTRY_DEBUG("registering Qt integration");
originalMessageHandler = qInstallMessageHandler(sentry_qt_messsage_handler);
}

static void
unregister_qt(void *UNUSED(data), sentry_scope_t *UNUSED(scope),
const sentry_options_t *UNUSED(options))
{
qInstallMessageHandler(originalMessageHandler);
originalMessageHandler = nullptr;
}

sentry_integration_t *
sentry_integration_qt_new(void)
{
sentry_integration_t *integration = SENTRY_MAKE(sentry_integration_t);
if (!integration) {
return nullptr;
}

integration->register_func = register_qt;
integration->unregister_func = unregister_qt;

return integration;
}
6 changes: 4 additions & 2 deletions src/integrations/sentry_integration_qt.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#ifndef SENTRY_INTEGRATION_QT_H_INCLUDED
#define SENTRY_INTEGRATION_QT_H_INCLUDED

#include "sentry_integration.h"

#ifdef __cplusplus
# define C_API extern "C"
#else
# define C_API
#endif

/**
* This sets up the Qt integration.
* This creates the Qt integration.
*/
C_API void sentry_integration_setup_qt(void);
C_API sentry_integration_t *sentry_integration_qt_new(void);

#endif
39 changes: 30 additions & 9 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
# include "sentry_screenshot.h"
#endif

#ifdef SENTRY_INTEGRATION_QT
# include "integrations/sentry_integration_qt.h"
#endif

static sentry_options_t *g_options = NULL;
#ifdef SENTRY__MUTEX_INIT_DYN
SENTRY__MUTEX_INIT_DYN(g_options_lock)
Expand Down Expand Up @@ -100,6 +96,28 @@ generate_propagation_context(sentry_value_t propagation_context)
sentry_value_get_by_key(propagation_context, "trace"));
}

static void
register_integrations(sentry_scope_t *scope, const sentry_options_t *options)
{
for (size_t i = 0; i < options->num_integrations; i++) {
sentry_integration_t *integration = options->integrations[i];
if (integration->register_func) {
integration->register_func(integration->data, scope, options);
}
}
}

static void
unregister_integrations(sentry_scope_t *scope, const sentry_options_t *options)
{
for (size_t i = 0; i < options->num_integrations; i++) {
sentry_integration_t *integration = options->integrations[i];
if (integration->unregister_func) {
integration->unregister_func(integration->data, scope, options);
}
}
}

#if defined(SENTRY_PLATFORM_NX) || defined(SENTRY_PLATFORM_PS) \
|| defined(SENTRY_PLATFORM_XBOX)
int
Expand Down Expand Up @@ -228,16 +246,13 @@ sentry_init(sentry_options_t *options)
scope->breadcrumbs, options->max_breadcrumbs);

sentry__scope_update_dsc(scope, options);

register_integrations(scope, options);
}
if (backend && backend->user_consent_changed_func) {
backend->user_consent_changed_func(backend);
}

#ifdef SENTRY_INTEGRATION_QT
SENTRY_DEBUG("setting up Qt integration");
sentry_integration_setup_qt();
#endif

#if defined(SENTRY_PLATFORM_WINDOWS) \
&& (!defined(SENTRY_BUILD_SHARED) || defined(SENTRY_PLATFORM_XBOX))
// This function must be positioned so that any dependents on its cached
Expand Down Expand Up @@ -320,6 +335,12 @@ sentry_close(void)
// flushed. This prevents a potential deadlock on the options during
// envelope creation.
SENTRY_WITH_OPTIONS (options) {
if (options->num_integrations) {
SENTRY_WITH_SCOPE_MUT_NO_FLUSH (scope) {
unregister_integrations(scope, options);
}
}

if (options->enable_logs) {
sentry__logs_shutdown(options->shutdown_timeout);
}
Expand Down
16 changes: 16 additions & 0 deletions src/sentry_integration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef SENTRY_INTEGRATION_H_INCLUDED
#define SENTRY_INTEGRATION_H_INCLUDED

#include "sentry_boot.h"

typedef struct sentry_integration_s {
void *data;

void (*register_func)(
void *data, sentry_scope_t *scope, const sentry_options_t *options);
void (*unregister_func)(
void *data, sentry_scope_t *scope, const sentry_options_t *options);
void (*free_func)(void *data);
} sentry_integration_t;

#endif
48 changes: 48 additions & 0 deletions src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <math.h>
#include <stdlib.h>

#ifdef SENTRY_INTEGRATION_QT
# include "integrations/sentry_integration_qt.h"
#endif

static double
normalize_sample_rate(double sample_rate, double default_value)
{
Expand Down Expand Up @@ -119,6 +123,9 @@ sentry_options_new(void)
opts->http_retry = false;
opts->send_client_reports = true;
opts->enable_large_attachments = false;
#ifdef SENTRY_INTEGRATION_QT
sentry__options_add_integration(opts, sentry_integration_qt_new());
#endif

return opts;
}
Expand All @@ -132,6 +139,18 @@ sentry__options_incref(sentry_options_t *options)
return options;
}

static void
free_integration(sentry_integration_t *integration)
{
if (!integration) {
return;
}
if (integration->free_func) {
integration->free_func(integration->data);
}
sentry_free(integration);
}

void
sentry_options_free(sentry_options_t *opts)
{
Expand All @@ -155,6 +174,10 @@ sentry_options_free(sentry_options_t *opts)
sentry__backend_free(opts->backend);
sentry__attachments_free(opts->attachments);
sentry__run_free(opts->run);
for (size_t i = 0; i < opts->num_integrations; i++) {
free_integration(opts->integrations[i]);
}
sentry_free(opts->integrations);

sentry_free(opts);
}
Expand Down Expand Up @@ -930,6 +953,31 @@ sentry_options_set_backend(sentry_options_t *opts, sentry_backend_t *backend)
opts->backend = backend;
}

void
sentry__options_add_integration(
sentry_options_t *opts, sentry_integration_t *integration)
{
if (!integration) {
return;
}

size_t new_count = opts->num_integrations + 1;
sentry_integration_t **integrations
= sentry__calloc(new_count, sizeof(sentry_integration_t *));
if (!integrations) {
free_integration(integration);
return;
}

for (size_t i = 0; i < opts->num_integrations; i++) {
integrations[i] = opts->integrations[i];
}
integrations[opts->num_integrations] = integration;
sentry_free(opts->integrations);
opts->integrations = integrations;
opts->num_integrations = new_count;
}

void
sentry_options_set_enable_logs(sentry_options_t *opts, int enable_logs)
{
Expand Down
12 changes: 12 additions & 0 deletions src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "sentry_attachment.h"
#include "sentry_database.h"
#include "sentry_integration.h"
#include "sentry_logger.h"
#include "sentry_session.h"
#include "sentry_utils.h"
Expand Down Expand Up @@ -95,6 +96,8 @@ struct sentry_options_s {
not exposed through the options API */
struct sentry_backend_s *backend;
sentry_session_t *session;
sentry_integration_t **integrations;
size_t num_integrations;

long refcount;
uint64_t shutdown_timeout;
Expand Down Expand Up @@ -124,4 +127,13 @@ sentry_options_t *sentry__options_incref(sentry_options_t *options);
*/
const char *sentry__options_get_org_id(const sentry_options_t *options);

/**
* Adds an integration to the options.
*
* Takes ownership of `integration`. If the integration owns `data`, it must
* provide `free_func`.
*/
void sentry__options_add_integration(
sentry_options_t *opts, sentry_integration_t *integration);

#endif
Loading