Skip to content

Commit

Permalink
feat(tracing): Restrict sentry_capture_event so it only sends non-t…
Browse files Browse the repository at this point in the history
…ransaction events (#629)

Prevent the public API from being used to send transaction events
as another transaction-specific function is meant to be used to 
accomplish this.
  • Loading branch information
relaxolotl authored Dec 21, 2021
1 parent a9f76e6 commit 737a654
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,8 @@ SENTRY_API void sentry_user_consent_reset(void);
SENTRY_API sentry_user_consent_t sentry_user_consent_get(void);

/**
* Sends a sentry event.
* Sends a sentry event. Returns a nil UUID if the event being passed in is a
* transaction; `sentry_transaction_finish` should be used to send transactions.
*/
SENTRY_API sentry_uuid_t sentry_capture_event(sentry_value_t event);

Expand Down
16 changes: 15 additions & 1 deletion src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,28 @@ sentry__event_is_transaction(sentry_value_t event)

sentry_uuid_t
sentry_capture_event(sentry_value_t event)
{
if (sentry__event_is_transaction(event)) {
return sentry_uuid_nil();
} else {
return sentry__capture_event(event);
}
}

sentry_uuid_t
sentry__capture_event(sentry_value_t event)
{
sentry_uuid_t event_id;
sentry_envelope_t *envelope = NULL;

bool was_captured = false;
SENTRY_WITH_OPTIONS (options) {
was_captured = true;
envelope = sentry__prepare_event(options, event, &event_id);
if (sentry__event_is_transaction(event)) {
return sentry_uuid_nil();
} else {
envelope = sentry__prepare_event(options, event, &event_id);
}
if (envelope) {
if (options->session) {
SENTRY_WITH_OPTIONS_MUT (mut_options) {
Expand Down
5 changes: 5 additions & 0 deletions src/sentry_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ bool sentry__event_is_transaction(sentry_value_t event);
sentry_envelope_t *sentry__prepare_event(const sentry_options_t *options,
sentry_value_t event, sentry_uuid_t *event_id);

/**
* Sends a sentry event, regardless of its type.
*/
sentry_uuid_t sentry__capture_event(sentry_value_t event);

/**
* This function will submit the `envelope` to the given `transport`, first
* checking for consent.
Expand Down

0 comments on commit 737a654

Please sign in to comment.