Skip to content

Conversation

JoshuaMoelans
Copy link
Member

@JoshuaMoelans JoshuaMoelans commented Jun 12, 2025

Closes #1210

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

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
  • ensure logs get sent/cached to disk on crash
  • 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?
  • 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)

#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 16fbfde

* add sentry log API + send first logs

* fix log_level_as_string

* attach attributes to logs

* attach formatted message + args

* add to example

* add more attributes

* cleanup

* windows warning-as-error

* windows warning-as-error v2

* windows warning-as-error v2 (final)

* add unit tests for initial logs

* memleak attempted fix

* memleak attempted fix 2

* cleanup

* use `sentry_level_t` instead of new log level enum

* add SENTRY_LEVEL_TRACE to sentry_logger

* quick anti-brownout fix
- see #1274

* fix missing SENTRY_LEVEL_INFO string return

* fix logger level check + add test

* cleanup logs parameter extraction

* warn-as-error fix

* const char* fix

* static function

* feat(logs): add (u)int64 sentry_value_t type (#1301)

* add (u)int64 sentry_value_t type

* add value_to_msgpack missing switch cases

* remove undefined behavior test (C99 6.3.1.4)

* avoid Windows sized integer name collision

* cleanup & apply code review feedback

* more cleanup & remove type coercion

* update logs param conversion

* own uint64 string

* apply suggestions from code review
# Conflicts:
#	examples/example.c
#	src/sentry_envelope.c
#	src/sentry_envelope.h
#	tests/unit/tests.inc
# Conflicts:
#	include/sentry.h
#	src/sentry_json.c
#	src/sentry_value.c
#	tests/unit/test_value.c
#	tests/unit/tests.inc
JoshuaMoelans and others added 5 commits September 12, 2025 11:43
* initial queue attempt

* add timer

* prototype double buffer approach

* update logs unit tests for batching

* replace timer with bgworker

* add first integration tests

* update example.c with correct log thread amounts

* cleanup

* add wait for 'adding' logs in flush logic

* go back to single queue for performance testing

* add time checks

* add ToDos + cleanup sentry_value_t cloning

* initial attempt

* cond_wait for timer + 'adding' spinlock

* add sleep for tests

* add sleep for tests

* force flush before attempting timer_worker shutdown

* add proper cond_wait for 'adding' counter

* revert to manual flush on shutdown instead of timer thread flush

* add separate timer_stop atomic

* cleanup + replace 'adding' cond_wait by pure spinlock

* change bgworker for simpler thread implementation

* cleanup

* fix memleak

* fixes

* cleanup

* cleanup

* windows fixes

* update shutdown order

* fixes

* explicit check to stop timer task

* windows cleanup

* loosen threaded test assertion for CI
- too much variability in thread scheduling, so we can expect pretty much anything

* add continue for unexpected logs flush trigger instead of attempting flush

* Windows re-add condition variable trigger case

* feat(logs): add `before_send_log` (#1355)

* add `before_send_log` callback

* add `before_send_log` callback tests

* (temporary) add debug for calling sentry_options_free

* remove early return

* add late return

* cleanup

* fix ownership issues in single buffer batching (#1362)

* let the producer thread sleep for 1ms between logs

* fix two missing NULL checks in the json serializer

* clean up logging and early exits in `enqueue_log_single()`

* clean up ownerships in logs

* eliminate clones (we expect that everything outlives the logs being sent except local construction)
* use incref everywhere where we ref global state. this was the cause of the UAF, partially solved with the clones but a few were missing. no reason to clone if we do not want to disconnect for a particular object graph
* clarify that add_attribute expects ownership
* minimize scope_mut by moving os_context out
* raise that log output in throughput tests add to variability (stdout logging should be turned off when running a limit)

* log error in case we weren't able to start the log batching worker

* fix clang-cl warning

* ci: fix failing mingw build (#1361)

* ci: fix failing mingw build

* split `ASM_MASM_COMPILER` and `_FLAGS`

* add `ASM_MASM_FLAGS` in `mingw` install step

* specify the `CMAKE_ASM_MASM_COMPILER` as a `FILEPATH`

* clean up CMAKE_DEFINES construction so it is easier to diff in the future

* fix `LLVM_MINGW_INSTALL_PATH` to be referenced locally rather than $env

(cherry picked from commit 519554f)

* use UNREACHABLE macro to fix anal warnings

* batching double buffered (#1365)

* first attempt at double buffered

* remove the sleep from the windows thread func

* clean up thread waiting in the example

* adapt the double buffer to use retries, fix remaining issues, clean up and write inline docs

* return early in example on sentry_init error.

* fix formatting via shorter name for thread gate atomic

* improve inline docs of log_buffer_t members

* fetch os_context from scope

* move scope/options data retrieval into separate function + add expected keys to test

* update logs API to return status code

* cleanup

* add log-event trace connection test

* remove duplicate test

* specify macOS SDKROOT

---------

Co-authored-by: JoshuaMoelans <[email protected]>

* add flush retry for missed flush requests

* move flush retry into flush function

* add docs

---------

Co-authored-by: Mischan Toosarani-Hausberger <[email protected]>
@JoshuaMoelans JoshuaMoelans marked this pull request as ready for review September 12, 2025 11:44
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

sentry_value_set_by_key(
param_obj, "type", sentry_value_new_string("string"));
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The va_arg part of this message is correct at least where the ABI doesn't save us (on 64-bit ABIs, the var arg slots are already 8-byte wide), and this needs fixing. We can't ignore the length format specifier for va_arg() if we want to be portable (on most 32-bit ABIs, it would read two ints at once).

This is independent of the fact that we do not need the format specifier for whatever we store (because we decide to store every parameter in the biggest value type possible).

We need all combinations of length and number targets we can support, give each the correct va_arg() type spec, and then store it in our container for that number representation.

However, one could argue that this is not a blocker for an initial release (you could request users to use 64-bit types for parameters on 32-bit systems).

sentry_value_set_by_key(
param_obj, "type", sentry_value_new_string("string"));
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be unit tests that trigger this current scenario at least on the 32-bit builds.

Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

Minor nits, otherwise LGTM. We can also move the TODO into a follow-up issue (as described in the issue description for other open topics). But those two items (level-triggered wake + length specifier usage) are not yet in the list of open issues, so I leave this up to you.

* add vargs conversion test

* add ifdef for 32-bit systems

* Update tests/unit/test_logs.c

Co-authored-by: Mischan Toosarani-Hausberger <[email protected]>

* add comment

* fix comment

---------

Co-authored-by: Mischan Toosarani-Hausberger <[email protected]>
JoshuaMoelans and others added 3 commits September 22, 2025 21:00
Co-authored-by: Mischan Toosarani-Hausberger <[email protected]>
# Conflicts:
#	CHANGELOG.md
#	examples/example.c
#	src/sentry_logger.c
#	src/sentry_logger.h
#	tests/unit/test_logger.c
#	tests/unit/tests.inc
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@JoshuaMoelans JoshuaMoelans merged commit 1f8e4c4 into master Sep 23, 2025
40 checks passed
@JoshuaMoelans JoshuaMoelans deleted the joshua/feat/logs branch September 23, 2025 13:33
AbhiPrasad added a commit to getsentry/sentry-docs that referenced this pull request Sep 23, 2025
Vercel previews
Logs page
https://sentry-docs-oflen3xm3.sentry.dev/platforms/native/logs/
Logs options
https://sentry-docs-oflen3xm3.sentry.dev/platforms/native/configuration/options/#logs-options

<!-- Use this checklist to make sure your PR is ready for merge. You may
delete any sections you don't need. -->

## DESCRIBE YOUR PR
We've finished logs for Native, so we should let people know how to use
it getsentry/sentry-native#1271

## IS YOUR CHANGE URGENT?  

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [ ] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

---------

Co-authored-by: Abhijeet Prasad <[email protected]>
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++)
2 participants