Skip to content

Conversation

@jpnurmi
Copy link
Collaborator

@jpnurmi jpnurmi commented Jan 28, 2026

Summary

  • Extracts the batching infrastructure from sentry_logs.c into a reusable sentry_batcher module
  • Prepares for metrics support by making the batcher telemetry-type agnostic

Changes

New files:

  • src/sentry_batcher.h - Batcher types and API declarations
  • src/sentry_batcher.c - Batcher implementation

Key features of the batcher:

  • Lock-free double-buffer pattern for high-throughput producer threads
  • Configurable batch_func callback for telemetry-specific envelope creation
  • Thread lifecycle management (STOPPED → STARTING → RUNNING)
  • Crash-safe flush mode for signal handler contexts
  • Test helper sentry__batcher_wait_for_thread_startup() for avoiding race conditions

API:

void sentry__batcher_startup(sentry_batcher_t *batcher, sentry_batch_func_t batch_func);
bool sentry__batcher_enqueue(sentry_batcher_t *batcher, sentry_value_t item);
void sentry__batcher_shutdown(sentry_batcher_t *batcher, uint64_t timeout);
void sentry__batcher_flush(sentry_batcher_t *batcher, bool crash_safe);
void sentry__batcher_force_flush(sentry_batcher_t *batcher);
void sentry__batcher_flush_crash_safe(sentry_batcher_t *batcher);

Usage example (from sentry_logs.c):

static sentry_batcher_t g_batcher = { ... };

void sentry__logs_startup(void) {
    sentry__batcher_startup(&g_batcher, sentry__envelope_add_logs);
}

Test plan

  • Existing logs tests continue to pass
  • Build succeeds on all platforms

Relates to #1453

Copy link
Member

@JoshuaMoelans JoshuaMoelans left a comment

Choose a reason for hiding this comment

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

Nice, LGTM!

@jpnurmi jpnurmi mentioned this pull request Jan 29, 2026
4 tasks
@jpnurmi jpnurmi merged commit d7a71c6 into getsentry:master Jan 29, 2026
46 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/ref/batcher branch January 29, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants