Skip to content

Commit a51cddd

Browse files
fix: add proper sdk name to logs (#1399)
* fix: add proper sdk name to logs * update CHANGELOG.md * don't use deprecated `sentry_sdk_name()` * update CHANGELOG.md * add SENTRY_SDK_NAME fallback (fallforward?) * fix typo
1 parent 9bbbcae commit a51cddd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
**Fixes**:
6+
7+
- Use proper SDK name determination for structured logs `sdk.name` attribute. ([#1399](https://github.com/getsentry/sentry-native/pull/1399))
8+
39
## 0.11.2
410

511
**Fixes**:

src/sentry_logs.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,17 @@ static
501501
/**
502502
* This function assumes that `value` is owned, so we have to make sure that the
503503
* `value` was created or cloned by the caller or even better inc_refed.
504+
*
505+
* Replaces attributes[name] if it already exists.
504506
*/
505507
static void
506508
add_attribute(sentry_value_t attributes, sentry_value_t value, const char *type,
507509
const char *name)
508510
{
511+
if (!sentry_value_is_null(sentry_value_get_by_key(attributes, name))) {
512+
// already exists, so we remove and create a new one
513+
sentry_value_remove_by_key(attributes, name);
514+
}
509515
sentry_value_t param_obj = sentry_value_new_object();
510516
sentry_value_set_by_key(param_obj, "value", value);
511517
sentry_value_set_by_key(param_obj, "type", sentry_value_new_string(type));
@@ -598,6 +604,10 @@ add_scope_and_options_data(sentry_value_t log, sentry_value_t attributes)
598604
}
599605
}
600606

607+
// fallback in case options doesn't set it
608+
add_attribute(attributes, sentry_value_new_string(SENTRY_SDK_NAME),
609+
"string", "sentry.sdk.name");
610+
601611
SENTRY_WITH_OPTIONS (options) {
602612
if (options->environment) {
603613
add_attribute(attributes,
@@ -608,10 +618,11 @@ add_scope_and_options_data(sentry_value_t log, sentry_value_t attributes)
608618
add_attribute(attributes, sentry_value_new_string(options->release),
609619
"string", "sentry.release");
610620
}
621+
add_attribute(attributes,
622+
sentry_value_new_string(sentry_options_get_sdk_name(options)),
623+
"string", "sentry.sdk.name");
611624
}
612625

613-
add_attribute(attributes, sentry_value_new_string("sentry.native"),
614-
"string", "sentry.sdk.name");
615626
add_attribute(attributes, sentry_value_new_string(sentry_sdk_version()),
616627
"string", "sentry.sdk.version");
617628
}

0 commit comments

Comments
 (0)