From 26ff58aab6b0ab289ff42da688b5374bedbd06ff Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:04:37 +0100 Subject: [PATCH] added sampling context --- include/sentry.h | 4 +++- src/CMakeLists.txt | 2 ++ src/sentry_sampling_context.c | 21 +++++++++++++++++++++ src/sentry_sampling_context.h | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/sentry_sampling_context.c create mode 100644 src/sentry_sampling_context.h diff --git a/include/sentry.h b/include/sentry.h index 28a15af3c..ed54c5367 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1533,7 +1533,9 @@ SENTRY_EXPERIMENTAL_API void sentry_options_set_traces_sample_rate( SENTRY_EXPERIMENTAL_API double sentry_options_get_traces_sample_rate( sentry_options_t *opts); -typedef double (*sentry_traces_sampler_function)(sentry_value_t *sampling_ctx); +struct sentry_sampling_context_s; +typedef struct sentry_sampling_context_s sentry_sampling_context_t; +typedef double (*sentry_traces_sampler_function)(sentry_sampling_context_t *sampling_ctx); /** * Sets the traces sampler callback. Should be a function that returns a double diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1a7ba5949..e79e2c493 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,8 @@ sentry_target_sources_cwd(sentry sentry_random.h sentry_ratelimiter.c sentry_ratelimiter.h + sentry_sampling_context.c + sentry_sampling_context.h sentry_scope.c sentry_scope.h sentry_session.c diff --git a/src/sentry_sampling_context.c b/src/sentry_sampling_context.c new file mode 100644 index 000000000..f3d555d36 --- /dev/null +++ b/src/sentry_sampling_context.c @@ -0,0 +1,21 @@ +// sentry_sampling_context.c +#include "sentry_sampling_context.h" +#include +#include + +sentry_sampling_context_t *sentry_sampling_context_new(sentry_transaction_context_t *transaction_context) { + sentry_sampling_context_t *context = SENTRY_MAKE(sentry_sampling_context_t); + if (context) { + context->transaction_context = transaction_context; // todo incref? + context->custom_sampling_context = NULL; + } + return context; +} + +sentry_sampling_context_t *sentry_sampling_context_new_with_custom(sentry_transaction_context_t *transaction_context, void *custom_sampling_context) { + sentry_sampling_context_t *context = sentry_sampling_context_new(transaction_context); + if (context) { + context->custom_sampling_context = custom_sampling_context; + } + return context; +} \ No newline at end of file diff --git a/src/sentry_sampling_context.h b/src/sentry_sampling_context.h new file mode 100644 index 000000000..008fb51f7 --- /dev/null +++ b/src/sentry_sampling_context.h @@ -0,0 +1,16 @@ +// sentry_sampling_context.h +#ifndef SENTRY_SAMPLING_CONTEXT_H_INCLUDED +#define SENTRY_SAMPLING_CONTEXT_H_INCLUDED + +#include "sentry_tracing.h" + +typedef struct sentry_sampling_context_s { + sentry_transaction_context_t *transaction_context; + void *custom_sampling_context; // TODO what type should this be? +} sentry_sampling_context_t; + +// TODO add refcounting for this; users might want to reuse this +sentry_sampling_context_t *sentry_sampling_context_new(sentry_transaction_context_t *transaction_context); +sentry_sampling_context_t *sentry_sampling_context_new_with_custom(sentry_transaction_context_t *transaction_context, void *custom_sampling_context); + +#endif // SENTRY_SAMPLING_CONTEXT_H_INCLUDED \ No newline at end of file