Skip to content

Commit

Permalink
feat(tracing): Add config options (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
relaxolotl authored Dec 8, 2021
1 parent 5c42e3b commit 595b496
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,34 @@ SENTRY_API void sentry_start_session(void);
*/
SENTRY_API void sentry_end_session(void);

/**
* Sets the maximum number of spans that can be attached to a
* transaction.
*/
SENTRY_EXPERIMENTAL_API void sentry_options_set_max_spans(
sentry_options_t *opts, size_t max_spans);

/**
* Gets the maximum number of spans that can be attached to a
* transaction.
*/
SENTRY_EXPERIMENTAL_API size_t sentry_options_get_max_spans(
sentry_options_t *opts);

/**
* Sets the sample rate for transactions. Should be a double between
* `0.0` and `1.0`. Transactions will be randomly discarded during
* `sentry_transaction_finish` when the sample rate is < 1.0.
*/
SENTRY_EXPERIMENTAL_API void sentry_options_set_traces_sample_rate(
sentry_options_t *opts, double sample_rate);

/**
* Returns the sample rate for transactions.
*/
SENTRY_EXPERIMENTAL_API double sentry_options_get_traces_sample_rate(
sentry_options_t *opts);

#ifdef __cplusplus
}
#endif
Expand Down
50 changes: 50 additions & 0 deletions src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ sentry_options_new(void)
opts->sample_rate = 1.0;
opts->refcount = 1;
opts->shutdown_timeout = SENTRY_DEFAULT_SHUTDOWN_TIMEOUT;

opts->traces_sample_rate = 0.0;
opts->max_spans = 0;
return opts;
}

Expand Down Expand Up @@ -371,3 +374,50 @@ sentry_options_set_database_pathw(sentry_options_t *opts, const wchar_t *path)
opts->database_path = sentry__path_from_wstr(path);
}
#endif

/**
* Sets the maximum number of spans that can be attached to a
* transaction.
*/
void
sentry_options_set_max_spans(sentry_options_t *opts, size_t max_spans)
{
opts->max_spans = max_spans;
}

/**
* Gets the maximum number of spans that can be attached to a
* transaction.
*/
size_t
sentry_options_get_max_spans(sentry_options_t *opts)
{
return opts->max_spans;
}

/**
* Sets the sample rate for transactions. Should be a double between
* `0.0` and `1.0`. Transactions will be randomly discarded during
* `sentry_transaction_finish` when the sample rate is < 1.0.
*/
void
sentry_options_set_traces_sample_rate(
sentry_options_t *opts, double sample_rate)
{

if (sample_rate < 0.0) {
sample_rate = 0.0;
} else if (sample_rate > 1.0) {
sample_rate = 1.0;
}
opts->traces_sample_rate = sample_rate;
}

/**
* Returns the sample rate for transactions.
*/
double
sentry_options_get_traces_sample_rate(sentry_options_t *opts)
{
return opts->traces_sample_rate;
}
4 changes: 4 additions & 0 deletions src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ typedef struct sentry_options_s {
sentry_event_function_t before_send_func;
void *before_send_data;

/* Experimentally exposed */
double traces_sample_rate;
size_t max_spans;

/* everything from here on down are options which are stored here but
not exposed through the options API */
struct sentry_backend_s *backend;
Expand Down

0 comments on commit 595b496

Please sign in to comment.