Skip to content

Comments

fix(logs): avoid modifying custom per-log attributes#1500

Merged
jpnurmi merged 2 commits intomasterfrom
jpnurmi/fix/log-attributes
Feb 2, 2026
Merged

fix(logs): avoid modifying custom per-log attributes#1500
jpnurmi merged 2 commits intomasterfrom
jpnurmi/fix/log-attributes

Conversation

@jpnurmi
Copy link
Collaborator

@jpnurmi jpnurmi commented Jan 30, 2026

Summary

Clone custom attributes instead of modifying them when merging with scope attributes. This allows reusing attribute objects across multiple log calls as documented, without side-effects:

sentry-native/include/sentry.h

Lines 2096 to 2097 in c80e793

* To re-use the same attributes, call `sentry_value_incref` on it
* before passing the attributes to the log function.

sentry_value_t custom_attrs = sentry_value_new_object();
sentry_value_set_by_key(custom_attrs, "foo", sentry_value_new_attribute(sentry_value_new_string("bar"), NULL));

sentry_value_incref(custom_attrs);
sentry_log_info("Hello", custom_attrs);

// should not contain `os.xxx`, `sentry.xxx` etc.
// {"foo":{...},"os.name":{...},"os.version":{...},"sentry.environment":{...},...}
fprintf(stderr, "%s\n", sentry_value_to_json(custom_attrs));

Changes

  • Clone custom attributes instead of merging into them directly
  • Move scope attributes merging to sentry__scope_apply_attributes() for consistency

Test plan

  • Add unit test logs_custom_attributes_not_modified
  • All existing tests pass

jpnurmi and others added 2 commits January 30, 2026 16:04
Allow reusing attribute objects across multiple log calls, as documented.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
jpnurmi added a commit that referenced this pull request Jan 30, 2026
Allow reusing attribute objects across multiple log calls, as documented.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@jpnurmi jpnurmi requested a review from JoshuaMoelans January 30, 2026 15:48
Copy link
Member

@JoshuaMoelans JoshuaMoelans left a comment

Choose a reason for hiding this comment

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

nice, LGTM. Thanks for catching this 🙏

@jpnurmi jpnurmi merged commit 2bd34fb into master Feb 2, 2026
45 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/fix/log-attributes branch February 2, 2026 13:02
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.

3 participants