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: Include performance monitoring by default in experimental API, remove compile flag for feature #678

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

**Features**:

- Removed the `SENTRY_PERFORMANCE_MONITORING` compile flag requirement to access performance monitoring in the Sentry SDK. Performance monitoring is now available to everybody who has opted into the experimental API.

## 0.4.15

**Fixes**:
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,6 @@ if(SENTRY_BUILD_EXAMPLES)
add_executable(sentry_example examples/example.c)
target_link_libraries(sentry_example PRIVATE sentry)

target_compile_definitions(sentry_example PRIVATE SENTRY_PERFORMANCE_MONITORING)

if(MSVC)
target_compile_options(sentry_example PRIVATE $<BUILD_INTERFACE:/wd5105>)
endif()
Expand Down
4 changes: 0 additions & 4 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,13 @@ main(int argc, char **argv)
options, sentry_transport_new(print_envelope));
}

#ifdef SENTRY_PERFORMANCE_MONITORING
if (has_arg(argc, argv, "capture-transaction")) {
sentry_options_set_traces_sample_rate(options, 1.0);
}

if (has_arg(argc, argv, "child-spans")) {
sentry_options_set_max_spans(options, 5);
}
#endif

sentry_init(options);

Expand Down Expand Up @@ -218,7 +216,6 @@ main(int argc, char **argv)
sentry_capture_event(event);
}

#ifdef SENTRY_PERFORMANCE_MONITORING
if (has_arg(argc, argv, "capture-transaction")) {
sentry_transaction_context_t *tx_ctx
= sentry_transaction_context_new("little.teapot",
Expand Down Expand Up @@ -253,7 +250,6 @@ main(int argc, char **argv)

sentry_transaction_finish(tx);
}
#endif

// make sure everything flushes
sentry_close();
Expand Down
11 changes: 3 additions & 8 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ SENTRY_API void sentry_envelope_free(sentry_envelope_t *envelope);
SENTRY_API sentry_value_t sentry_envelope_get_event(
const sentry_envelope_t *envelope);

#ifdef SENTRY_PERFORMANCE_MONITORING
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one is now unbalanced?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for catching this! looks like i didn't remove this one's partner #endif, fixed this.

/**
* Given an Envelope, returns the embedded Transaction if there is one.
*
Expand Down Expand Up @@ -1137,9 +1136,9 @@ SENTRY_API sentry_user_consent_t sentry_user_consent_get(void);
/**
* Sends a sentry event.
*
* If SENTRY_PERFORMANCE_MONITORING is enabled, returns a nil UUID if the event
* being passed in is a transaction, and the transaction will not be sent nor
* consumed. `sentry_transaction_finish` should be used to send transactions.
* If returns a nil UUID if the event being passed in is a transaction, and the
* transaction will not be sent nor consumed. `sentry_transaction_finish` should
* be used to send transactions.
*/
SENTRY_API sentry_uuid_t sentry_capture_event(sentry_value_t event);

Expand Down Expand Up @@ -1229,7 +1228,6 @@ SENTRY_API void sentry_start_session(void);
*/
SENTRY_API void sentry_end_session(void);

#ifdef SENTRY_PERFORMANCE_MONITORING
/**
* Sets the maximum number of spans that can be attached to a
* transaction.
Expand Down Expand Up @@ -1708,9 +1706,6 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_iter_headers(
sentry_transaction_t *tx, sentry_iter_headers_function_t callback,
void *userdata);

#endif

#ifdef __cplusplus
}
#endif
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m also confused by this here?

1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ if(SENTRY_INTEGRATION_QT)
endif()

if(SENTRY_BUILD_EXAMPLES)
target_compile_definitions(sentry PRIVATE SENTRY_PERFORMANCE_MONITORING)
sentry_target_sources_cwd(sentry
sentry_tracing.c
sentry_tracing.h
Expand Down
23 changes: 1 addition & 22 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
#include "sentry_session.h"
#include "sentry_string.h"
#include "sentry_sync.h"
#include "sentry_tracing.h"
#include "sentry_transport.h"
#include "sentry_value.h"

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

#ifdef SENTRY_PERFORMANCE_MONITORING
# include "sentry_tracing.h"
#endif

static sentry_options_t *g_options = NULL;
static sentry_mutex_t g_options_lock = SENTRY__MUTEX_INIT;

Expand Down Expand Up @@ -367,27 +364,21 @@ event_is_considered_error(sentry_value_t event)
return false;
}

#ifdef SENTRY_PERFORMANCE_MONITORING
bool
sentry__event_is_transaction(sentry_value_t event)
{
sentry_value_t event_type = sentry_value_get_by_key(event, "type");
return sentry__string_eq("transaction", sentry_value_as_string(event_type));
}
#endif

sentry_uuid_t
sentry_capture_event(sentry_value_t event)
{
#ifdef SENTRY_PERFORMANCE_MONITORING
if (sentry__event_is_transaction(event)) {
return sentry_uuid_nil();
} else {
return sentry__capture_event(event);
}
#else
return sentry__capture_event(event);
#endif
}

sentry_uuid_t
Expand All @@ -401,15 +392,11 @@ sentry__capture_event(sentry_value_t event)
SENTRY_WITH_OPTIONS (options) {
was_captured = true;

#ifdef SENTRY_PERFORMANCE_MONITORING
if (sentry__event_is_transaction(event)) {
envelope = sentry__prepare_transaction(options, event, &event_id);
} else {
envelope = sentry__prepare_event(options, event, &event_id);
}
#else
envelope = sentry__prepare_event(options, event, &event_id);
#endif
if (envelope) {
if (options->session) {
sentry_options_t *mut_options = sentry__options_lock();
Expand Down Expand Up @@ -439,7 +426,6 @@ sentry__roll_dice(double probability)
|| ((double)rnd / (double)UINT64_MAX) <= probability;
}

#ifdef SENTRY_PERFORMANCE_MONITORING
bool
sentry__should_send_transaction(sentry_value_t tx_cxt)
{
Expand All @@ -456,7 +442,6 @@ sentry__should_send_transaction(sentry_value_t tx_cxt)
}
return send;
}
#endif

sentry_envelope_t *
sentry__prepare_event(const sentry_options_t *options, sentry_value_t event,
Expand Down Expand Up @@ -524,7 +509,6 @@ sentry__prepare_event(const sentry_options_t *options, sentry_value_t event,
return NULL;
}

#ifdef SENTRY_PERFORMANCE_MONITORING
sentry_envelope_t *
sentry__prepare_transaction(const sentry_options_t *options,
sentry_value_t transaction, sentry_uuid_t *event_id)
Expand Down Expand Up @@ -555,7 +539,6 @@ sentry__prepare_transaction(const sentry_options_t *options,
sentry_value_decref(transaction);
return NULL;
}
#endif

void
sentry_handle_exception(const sentry_ucontext_t *uctx)
Expand Down Expand Up @@ -723,11 +706,9 @@ sentry_set_transaction(const char *transaction)
sentry_free(scope->transaction);
scope->transaction = sentry__string_clone(transaction);

#ifdef SENTRY_PERFORMANCE_MONITORING
if (scope->transaction_object) {
sentry_transaction_set_name(scope->transaction_object, transaction);
}
#endif
}
}

Expand All @@ -739,7 +720,6 @@ sentry_set_level(sentry_level_t level)
}
}

#ifdef SENTRY_PERFORMANCE_MONITORING
sentry_transaction_t *
sentry_transaction_start(
sentry_transaction_context_t *opaque_tx_cxt, sentry_value_t sampling_ctx)
Expand Down Expand Up @@ -1019,4 +999,3 @@ sentry_span_finish(sentry_span_t *opaque_span)
sentry__span_free(opaque_span);
return;
}
#endif
6 changes: 0 additions & 6 deletions src/sentry_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
*/
bool sentry__should_skip_upload(void);

#ifdef SENTRY_PERFORMANCE_MONITORING
/**
* Given a well-formed event, returns whether an event is a transaction or not.
* Defaults to false, which will also be returned if the event is malformed.
*/
bool sentry__event_is_transaction(sentry_value_t event);
#endif

/**
* Convert the given event into an envelope. This assumes that the event
Expand All @@ -60,7 +58,6 @@ sentry_envelope_t *sentry__prepare_event(const sentry_options_t *options,
*/
sentry_uuid_t sentry__capture_event(sentry_value_t event);

#ifdef SENTRY_PERFORMANCE_MONITORING
/**
* Convert the given transaction into an envelope. This assumes that the
* event being passed in is a transaction.
Expand All @@ -78,7 +75,6 @@ sentry_uuid_t sentry__capture_event(sentry_value_t event);
*/
sentry_envelope_t *sentry__prepare_transaction(const sentry_options_t *options,
sentry_value_t transaction, sentry_uuid_t *event_id);
#endif

/**
* This function will submit the `envelope` to the given `transport`, first
Expand Down Expand Up @@ -122,9 +118,7 @@ void sentry__options_unlock(void);
// these for now are only needed outside of core for tests
#ifdef SENTRY_UNITTEST
bool sentry__roll_dice(double probability);
# ifdef SENTRY_PERFORMANCE_MONITORING
bool sentry__should_send_transaction(sentry_value_t tx_cxt);
# endif
#endif

#endif
16 changes: 3 additions & 13 deletions src/sentry_envelope.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,15 @@ sentry_envelope_get_event(const sentry_envelope_t *envelope)
}
for (size_t i = 0; i < envelope->contents.items.item_count; i++) {

#ifdef SENTRY_PERFORMANCE_MONITORING
if (!sentry_value_is_null(envelope->contents.items.items[i].event)
&& !sentry__event_is_transaction(
envelope->contents.items.items[i].event)) {
return envelope->contents.items.items[i].event;
}
#else
if (!sentry_value_is_null(envelope->contents.items.items[i].event)) {
return envelope->contents.items.items[i].event;
}
#endif
}
return sentry_value_new_null();
}

#ifdef SENTRY_PERFORMANCE_MONITORING
sentry_value_t
sentry_envelope_get_transaction(const sentry_envelope_t *envelope)
{
Expand All @@ -232,7 +225,6 @@ sentry_envelope_get_transaction(const sentry_envelope_t *envelope)
}
return sentry_value_new_null();
}
#endif

sentry_envelope_item_t *
sentry__envelope_add_event(sentry_envelope_t *envelope, sentry_value_t event)
Expand Down Expand Up @@ -264,7 +256,6 @@ sentry__envelope_add_event(sentry_envelope_t *envelope, sentry_value_t event)
return item;
}

#ifdef SENTRY_PERFORMANCE_MONITORING
sentry_envelope_item_t *
sentry__envelope_add_transaction(
sentry_envelope_t *envelope, sentry_value_t transaction)
Expand Down Expand Up @@ -293,17 +284,16 @@ sentry__envelope_add_transaction(
sentry_value_incref(event_id);
sentry__envelope_set_header(envelope, "event_id", event_id);

# ifdef SENTRY_UNITTEST
#ifdef SENTRY_UNITTEST
sentry_value_t now = sentry_value_new_string("2021-12-16T05:53:59.343Z");
# else
#else
sentry_value_t now = sentry__value_new_string_owned(
sentry__msec_time_to_iso8601(sentry__msec_time()));
# endif
#endif
sentry__envelope_set_header(envelope, "sent_at", now);

return item;
}
#endif

sentry_envelope_item_t *
sentry__envelope_add_session(
Expand Down
2 changes: 0 additions & 2 deletions src/sentry_envelope.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ sentry_uuid_t sentry__envelope_get_event_id(const sentry_envelope_t *envelope);
sentry_envelope_item_t *sentry__envelope_add_event(
sentry_envelope_t *envelope, sentry_value_t event);

#ifdef SENTRY_PERFORMANCE_MONITORING
/**
* Add a transaction to this envelope.
*/
sentry_envelope_item_t *sentry__envelope_add_transaction(
sentry_envelope_t *envelope, sentry_value_t transaction);
#endif

/**
* Add a session to this envelope.
Expand Down
5 changes: 0 additions & 5 deletions src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ sentry_options_new(void)
opts->sample_rate = 1.0;
opts->refcount = 1;
opts->shutdown_timeout = SENTRY_DEFAULT_SHUTDOWN_TIMEOUT;

#ifdef SENTRY_PERFORMANCE_MONITORING
opts->traces_sample_rate = 0.0;
opts->max_spans = 0;
#endif

return opts;
}
Expand Down Expand Up @@ -378,7 +375,6 @@ sentry_options_set_database_pathw(sentry_options_t *opts, const wchar_t *path)
}
#endif

#ifdef SENTRY_PERFORMANCE_MONITORING
/**
* Sets the maximum number of spans that can be attached to a
* transaction.
Expand Down Expand Up @@ -429,4 +425,3 @@ sentry_options_get_traces_sample_rate(sentry_options_t *opts)
{
return opts->traces_sample_rate;
}
#endif
2 changes: 0 additions & 2 deletions src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ typedef struct sentry_options_s {
sentry_event_function_t before_send_func;
void *before_send_data;

#ifdef SENTRY_PERFORMANCE_MONITORING
/* Experimentally exposed */
double traces_sample_rate;
size_t max_spans;
#endif

/* everything from here on down are options which are stored here but
not exposed through the options API */
Expand Down
Loading