Skip to content

Commit

Permalink
added sampling context
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMoelans committed Dec 23, 2024
1 parent 9dc332f commit 26ff58a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/sentry_sampling_context.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// sentry_sampling_context.c
#include "sentry_sampling_context.h"
#include <sentry_alloc.h>
#include <stdlib.h>

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;
}
16 changes: 16 additions & 0 deletions src/sentry_sampling_context.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 26ff58a

Please sign in to comment.