Skip to content

feat: structured logging #1271

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

feat: structured logging #1271

wants to merge 2 commits into from

Conversation

JoshuaMoelans
Copy link
Member

@JoshuaMoelans JoshuaMoelans commented Jun 12, 2025

Closes #1210

Will be structured into sub-PRs that merge into this branch

  • add option enable_logs
  • add logger module with functions like sentry_logger_trace("Log number %i : %s", 3, "I'm logged up") feat(logs): add sentry log API + send first logs #1272
    • send log envelopes according to spec
  • provide named parameter API
    • As mentioned in this comment, we could have an alternative interface that takes in a list of sentry_value_t objects containing {name, value} tuples, allowing us to make use of sentry.message.parameter.X to the fullest extent (and not just relying on parameter index). Example API would look like sentry_log_info("some %d data %p that we substitute %s", my_list); where we then extract objects from my_list (a sentry_value_t list) to construct the string & store the named parameters.
  • add size/time-based buffering for logs
    • size-based can trigger whenever log is appended to logs list (and it goes over the max)
    • time-based should run using sentry_bgworker and flush every 5s
    • bgworker should only start when logs are enabled
  • think about prioritized sending (already brought up for Android/Cocoa)
    • In these SDKs, it's about prioritizing sending/cleaning up offline envelopes (e.g., there is a max storage after which they should ring-buffer-remove the oldest items, but then prioritizing keeping Errors around becomes a consideration)
  • add before_send_log callback
  • add tests
    • interaction with tracing (connected by trace_id and span_id
    • tests for batching
  • add to changelog
  • add to docs & update Supported SDKs
  • reach out to interested parties on the Logs Thread

Also, next to the initial implementation some future work remains. These should become their own issues after this PR is finished (and the merit to these improvements has been discussed as being worthwhile to implement)

  • use more advanced Batch Processor to buffer log sending
  • add integrations
    • sentry__logger_func() (e.g. SENTRY_WARNF()) ❗ (could be part of initial feature release, but consider cost; should people 'pay' for logs created by sdk internals? (more useful to us for debugging))
    • console logging (cout/printf)
    • others?

#skip-changelog for now

Copy link

github-actions bot commented Jun 12, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against c83b3ee

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.

Sentry Structured Logging for Native (C/C++)
1 participant