-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
feat: structured logging #1271
Conversation
|
* 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
* 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]>
sentry_value_set_by_key( | ||
param_obj, "type", sentry_value_new_string("string")); | ||
break; | ||
} |
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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]>
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
which seemingly fixes the missing header: https://sourceforge.net/p/ruamel-yaml-clib/tickets/47/#de77
...so we can ignore in which module a `crashpad` test runs.
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]>
Closes #1210
Will be structured into sub-PRs that merge into this branch
enable_logs
logs
module with functions likesentry_log_debug("Log number %i : %s", 3, "I'm logged up")
feat(logs): add sentry log API + send first logs #1272sentry_value_t
objects containing{name, value}
tuples, allowing us to make use ofsentry.message.parameter.X
to the fullest extent (and not just relying on parameter index). Example API would look likesentry_log_info("some %d data %p that we substitute %s", my_list);
where we then extract objects frommy_list
(asentry_value_t
list) to construct the string & store the named parameters.logs
list (and it goes over the max)message.template
if there are no parameters (see https://github.com/getsentry/sentry-docs/pull/14759/files) part of feat(logs): addbefore_send_log
#1355before_send_log
callback feat(logs): addbefore_send_log
#1355trace_id
andspan_id
int64
(see commit) -> tracked on ref: use SIZE_MAX in sentry_envelope_deserialize #1328Also, 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)
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))#skip-changelog for now