Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
24f305d
add sentry log API + send first logs
JoshuaMoelans Jun 12, 2025
a895bb8
fix log_level_as_string
JoshuaMoelans Jun 12, 2025
168e51e
attach attributes to logs
JoshuaMoelans Jun 17, 2025
07b1dee
attach formatted message + args
JoshuaMoelans Jun 17, 2025
cdd2ab3
add to example
JoshuaMoelans Jun 17, 2025
d4834d0
add more attributes
JoshuaMoelans Jun 18, 2025
d1444e0
cleanup
JoshuaMoelans Jun 18, 2025
8a3ae2a
windows warning-as-error
JoshuaMoelans Jun 18, 2025
8b869d7
windows warning-as-error v2
JoshuaMoelans Jun 20, 2025
74a823d
windows warning-as-error v2 (final)
JoshuaMoelans Jun 20, 2025
ebc5ae3
add unit tests for initial logs
JoshuaMoelans Jun 23, 2025
9b42629
memleak attempted fix
JoshuaMoelans Jun 24, 2025
be24e76
memleak attempted fix 2
JoshuaMoelans Jun 24, 2025
ca75198
cleanup
JoshuaMoelans Jun 24, 2025
d57fcf3
use `sentry_level_t` instead of new log level enum
JoshuaMoelans Jun 24, 2025
37ece60
add SENTRY_LEVEL_TRACE to sentry_logger
JoshuaMoelans Jun 24, 2025
e75f60c
quick anti-brownout fix
JoshuaMoelans Jun 24, 2025
b37ea8d
fix missing SENTRY_LEVEL_INFO string return
JoshuaMoelans Jun 25, 2025
08e8472
fix logger level check + add test
JoshuaMoelans Jun 26, 2025
8a1fc26
cleanup logs parameter extraction
JoshuaMoelans Jun 27, 2025
17c3a96
warn-as-error fix
JoshuaMoelans Jun 27, 2025
044e0bf
const char* fix
JoshuaMoelans Jun 27, 2025
0dcc172
static function
JoshuaMoelans Jun 27, 2025
940bd6a
feat(logs): add (u)int64 sentry_value_t type (#1301)
JoshuaMoelans Jul 14, 2025
4e7d794
update logs param conversion
JoshuaMoelans Jul 14, 2025
6da5184
own uint64 string
JoshuaMoelans Jul 15, 2025
e6ea228
apply suggestions from code review
JoshuaMoelans Jul 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# undef NDEBUG
#endif

#include "../src/sentry_options.h"

#include <assert.h>

#ifdef SENTRY_PLATFORM_WINDOWS
Expand Down Expand Up @@ -359,6 +361,30 @@ main(int argc, char **argv)

sentry_init(options);

// TODO incorporate into test
if (options->enable_logs) {
sentry_logger_trace(
"We log it up %i percent, %s style\n", 100, "trace");
// sentry_logger_debug(
// "We log it up %i percent, %s style\n", 100, "debug");
// sentry_logger_info("We log it up %i percent, %s style\n", 100,
// "info"); sentry_logger_warn("We log it up %i percent, %s style\n",
// 100, "warn"); sentry_logger_error(
// "We log it up %i percent, %s style\n", 100, "error");
// sentry_logger_fatal(
// "We log it up %i percent, %s style\n", 100, "fatal");

// Test the logger with various parameter types
sentry_logger_info(
"API call to %s completed in %d ms with %f success rate",
"/api/products", 2500, 0.95);

sentry_logger_warn("Processing %d items, found %u errors, pointer: %p",
100, 5u, (void *)0x12345678);

sentry_logger_error("Character '%c' is invalid", 'X');
}

if (!has_arg(argc, argv, "no-setup")) {
sentry_set_transaction("test-transaction");
sentry_set_level(SENTRY_LEVEL_WARNING);
Expand Down Expand Up @@ -566,6 +592,9 @@ main(int argc, char **argv)
SENTRY_LEVEL_INFO, "my-logger", "Hello World!");
sentry_capture_event(event);
}
if (options->enable_logs) {
sentry_logger_debug("logging after scoped transaction event");
}

sentry_transaction_finish(tx);
}
Expand Down
8 changes: 8 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,14 @@ SENTRY_EXPERIMENTAL_API void sentry_options_set_enable_logs(
SENTRY_EXPERIMENTAL_API int sentry_options_get_enable_logs(
const sentry_options_t *opts);

// TODO think about API; functions or MACROs?
SENTRY_EXPERIMENTAL_API void sentry_logger_trace(const char *message, ...);
SENTRY_EXPERIMENTAL_API void sentry_logger_debug(const char *message, ...);
SENTRY_EXPERIMENTAL_API void sentry_logger_info(const char *message, ...);
SENTRY_EXPERIMENTAL_API void sentry_logger_warn(const char *message, ...);
SENTRY_EXPERIMENTAL_API void sentry_logger_error(const char *message, ...);
SENTRY_EXPERIMENTAL_API void sentry_logger_fatal(const char *message, ...);

#ifdef SENTRY_PLATFORM_LINUX

/**
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ sentry_target_sources_cwd(sentry
transports/sentry_disk_transport.h
transports/sentry_function_transport.c
unwinder/sentry_unwinder.c
sentry_logs.c
sentry_logs.h
)

# generic platform / path / symbolizer
Expand Down
26 changes: 26 additions & 0 deletions src/sentry_envelope.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,32 @@ sentry__envelope_add_transaction(
return item;
}

sentry_envelope_item_t *
sentry__envelope_add_logs(sentry_envelope_t *envelope, sentry_value_t logs)
{
sentry_envelope_item_t *item = envelope_add_item(envelope);
if (!item) {
return NULL;
}

sentry_jsonwriter_t *jw = sentry__jsonwriter_new_sb(NULL);
if (!jw) {
return NULL;
}

sentry__jsonwriter_write_value(jw, logs);
item->payload = sentry__jsonwriter_into_string(jw, &item->payload_len);

sentry__envelope_item_set_header(
item, "type", sentry_value_new_string("log"));
sentry__envelope_item_set_header(item, "item_count",
sentry_value_new_int32(sentry_value_get_length(logs)));
sentry__envelope_item_set_header(item, "content_type",
sentry_value_new_string("application/vnd.sentry.items.log+json"));

return item;
}

sentry_envelope_item_t *
sentry__envelope_add_user_feedback(
sentry_envelope_t *envelope, sentry_value_t user_feedback)
Expand Down
6 changes: 6 additions & 0 deletions src/sentry_envelope.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ sentry_envelope_item_t *sentry__envelope_add_event(
sentry_envelope_item_t *sentry__envelope_add_transaction(
sentry_envelope_t *envelope, sentry_value_t transaction);

/**
* Add a list of logs to this envelope.
*/
sentry_envelope_item_t *sentry__envelope_add_logs(
sentry_envelope_t *envelope, sentry_value_t logs);

/**
* Add a user feedback to this envelope.
*/
Expand Down
Loading
Loading