Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce sentry_close #518

Merged
merged 1 commit into from
Apr 19, 2021
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ sentry_init(options);

// your application code …

sentry_shutdown();
sentry_close();
```

Other important configuration options include:
Expand Down
2 changes: 1 addition & 1 deletion examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ main(int argc, char **argv)
}

// make sure everything flushes
sentry_shutdown();
sentry_close();
if (has_arg(argc, argv, "sleep-after-shutdown")) {
sleep_s(1);
}
Expand Down
11 changes: 10 additions & 1 deletion include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ SENTRY_API void sentry_options_set_logger(
* Automatic session tracking is enabled by default and is equivalent to calling
* `sentry_start_session` after startup.
* There can only be one running session, and the current session will always be
* closed implicitly by `sentry_shutdown`, when starting a new session with
* closed implicitly by `sentry_close`, when starting a new session with
* `sentry_start_session`, or manually by calling `sentry_end_session`.
*/
SENTRY_API void sentry_options_set_auto_session_tracking(
Expand Down Expand Up @@ -942,6 +942,15 @@ SENTRY_API int sentry_init(sentry_options_t *options);
*
* Returns 0 on success.
*/
SENTRY_API int sentry_close(void);

/**
* Shuts down the sentry client and forces transports to flush out.
*
* This is a **deprecated** alias for `sentry_close`.
*
* Returns 0 on success.
*/
SENTRY_API int sentry_shutdown(void);

/**
Expand Down
10 changes: 8 additions & 2 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ sentry__should_skip_upload(void)
int
sentry_init(sentry_options_t *options)
{
sentry_shutdown();
sentry_close();

sentry_logger_t logger = { NULL, NULL };
if (options->debug) {
Expand Down Expand Up @@ -179,7 +179,7 @@ sentry_init(sentry_options_t *options)
}

int
sentry_shutdown(void)
sentry_close(void)
{
sentry_end_session();

Expand Down Expand Up @@ -219,6 +219,12 @@ sentry_shutdown(void)
return (int)dumped_envelopes;
}

int
sentry_shutdown(void)
{
return sentry_close();
}

int
sentry_reinstall_backend(void)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_attachments.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ SENTRY_TEST(lazy_attachments)
!= NULL);
sentry_free(serialized);

sentry_shutdown();
sentry_close();

sentry__path_remove(existing);
sentry__path_remove(non_existing);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ SENTRY_TEST(basic_function_transport)
sentry_capture_event(sentry_value_new_message_event(SENTRY_LEVEL_INFO,
"root", "not captured either due to revoked consent"));

sentry_shutdown();
sentry_close();

TEST_CHECK_INT_EQUAL(called, 2);
}
Expand Down Expand Up @@ -90,7 +90,7 @@ SENTRY_TEST(sampling_before_send)
sentry_value_new_message_event(SENTRY_LEVEL_INFO, NULL, "foo"));
}

sentry_shutdown();
sentry_close();

TEST_CHECK_INT_EQUAL(called_transport, 0);
// well, its random after all
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_consent.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ SENTRY_TEST(basic_consent_tracking)
init_consenting_sentry();
TEST_CHECK_INT_EQUAL(
sentry_user_consent_get(), SENTRY_USER_CONSENT_UNKNOWN);
sentry_shutdown();
sentry_close();

init_consenting_sentry();
sentry_user_consent_give();
TEST_CHECK_INT_EQUAL(sentry_user_consent_get(), SENTRY_USER_CONSENT_GIVEN);
sentry_shutdown();
sentry_close();
init_consenting_sentry();
TEST_CHECK_INT_EQUAL(sentry_user_consent_get(), SENTRY_USER_CONSENT_GIVEN);

sentry_user_consent_revoke();
TEST_CHECK_INT_EQUAL(
sentry_user_consent_get(), SENTRY_USER_CONSENT_REVOKED);
sentry_shutdown();
sentry_close();
init_consenting_sentry();
TEST_CHECK_INT_EQUAL(
sentry_user_consent_get(), SENTRY_USER_CONSENT_REVOKED);

sentry_user_consent_reset();
TEST_CHECK_INT_EQUAL(
sentry_user_consent_get(), SENTRY_USER_CONSENT_UNKNOWN);
sentry_shutdown();
sentry_close();
init_consenting_sentry();
TEST_CHECK_INT_EQUAL(
sentry_user_consent_get(), SENTRY_USER_CONSENT_UNKNOWN);
sentry_shutdown();
sentry_close();

sentry__path_remove_all(path);
sentry__path_free(path);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_envelopes.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ SENTRY_TEST(serialize_envelope)
sentry_envelope_free(envelope);
sentry_free(str);

sentry_shutdown();
sentry_close();
}
4 changes: 2 additions & 2 deletions tests/unit/test_logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ SENTRY_TEST(custom_logger)
SENTRY_WARNF("Oh this is %s", "bad");
data.assert_now = false;

sentry_shutdown();
sentry_close();

TEST_CHECK_INT_EQUAL(data.called, 1);

// *really* clear the logger instance
options = sentry_options_new();
sentry_init(options);
sentry_shutdown();
sentry_close();
}
4 changes: 2 additions & 2 deletions tests/unit/test_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SENTRY_TEST(session_basics)
user, "username", sentry_value_new_string("swatinem"));
sentry_set_user(user);

sentry_shutdown();
sentry_close();

TEST_CHECK_INT_EQUAL(called, 2);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ SENTRY_TEST(count_sampled_events)
}

assertion.assert_session = true;
sentry_shutdown();
sentry_close();

TEST_CHECK_INT_EQUAL(assertion.called, 1);
}
8 changes: 4 additions & 4 deletions tests/unit/test_uninit.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SENTRY_TEST(uninitialized)
sentry_set_level(SENTRY_LEVEL_DEBUG);
sentry_start_session();
sentry_end_session();
sentry_shutdown();
sentry_close();
}

SENTRY_TEST(empty_transport)
Expand All @@ -44,7 +44,7 @@ SENTRY_TEST(empty_transport)
sentry_uuid_t id = sentry_capture_event(event);
TEST_CHECK(!sentry_uuid_is_nil(&id));

sentry_shutdown();
sentry_close();
}

SENTRY_TEST(invalid_dsn)
Expand All @@ -59,7 +59,7 @@ SENTRY_TEST(invalid_dsn)
sentry_uuid_t id = sentry_capture_event(event);
TEST_CHECK(!sentry_uuid_is_nil(&id));

sentry_shutdown();
sentry_close();
}

SENTRY_TEST(invalid_proxy)
Expand All @@ -74,5 +74,5 @@ SENTRY_TEST(invalid_proxy)
sentry_uuid_t id = sentry_capture_event(event);
TEST_CHECK(!sentry_uuid_is_nil(&id));

sentry_shutdown();
sentry_close();
}