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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**Features**:

- Add `sentry_is_enabled` for checking whether the SDK has been initialized. ([#2045](https://github.com/getsentry/sentry-native/pull/2045))
- Add `sentry_event_set_level` for setting the level of an individual event. ([#2038](https://github.com/getsentry/sentry-native/pull/2038))

**Fixes**:
Expand Down
10 changes: 10 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,16 @@ SENTRY_API void sentry_options_set_backend(
*/
SENTRY_API int sentry_init(sentry_options_t *options);

/**
* Returns whether the Sentry SDK has been initialized successfully and has not
* yet been closed.
*
* Returns 1 after `sentry_init()` completes successfully and until
* `sentry_close()` completes. Returns 0 before initialization, after failed
* initialization, and after close.
*/
SENTRY_API int sentry_is_enabled(void);

/**
* Instructs the transport to flush its send-queue.
*
Expand Down
8 changes: 8 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ sentry_init(sentry_options_t *options)
return 1;
}

int
sentry_is_enabled(void)
{
int enabled = sentry__options_lock() != NULL;
sentry__options_unlock();
return enabled;
}

int
sentry_flush(uint64_t timeout)
{
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_failures.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ SENTRY_TEST(init_failure)
}
#else
TEST_CHECK(rv != 0);
TEST_CHECK(!sentry_is_enabled());
#endif
}
19 changes: 19 additions & 0 deletions tests/unit/test_uninit.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ SENTRY_TEST(uninitialized)
sentry_close();
}

SENTRY_TEST(is_enabled)
{
TEST_CHECK(!sentry_is_enabled());

SENTRY_TEST_OPTIONS_NEW(options);
TEST_CHECK(sentry_init(options) == 0);
TEST_CHECK(sentry_is_enabled());

sentry_close();
TEST_CHECK(!sentry_is_enabled());

SENTRY_TEST_OPTIONS_NEW(reinit_options);
TEST_CHECK(sentry_init(reinit_options) == 0);
TEST_CHECK(sentry_is_enabled());

sentry_close();
TEST_CHECK(!sentry_is_enabled());
}

SENTRY_TEST(empty_transport)
{
SENTRY_TEST_OPTIONS_NEW(options);
Expand Down
1 change: 1 addition & 0 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ XX(installation_id)
XX(internal_uuid_api)
XX(invalid_dsn)
XX(invalid_proxy)
XX(is_enabled)
XX(iso_time)
XX(lazy_attachments)
XX(logger_enable_disable_functionality)
Expand Down
Loading