Skip to content

feat(internal): add scope observer#1839

Open
jpnurmi wants to merge 30 commits into
masterfrom
jpnurmi/feat/scope-observer
Open

feat(internal): add scope observer#1839
jpnurmi wants to merge 30 commits into
masterfrom
jpnurmi/feat/scope-observer

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

A callback-based observer API that fires when scope properties change:

  • attachments
  • breadcrumbs
  • contexts
  • environment
  • extras
  • fingerprint
  • level
  • release
  • tags
  • transaction
  • user

Battle-tested by the upcoming WER integration (#1837) and Crashpad IPC (#1840, abandoned).

#skip-changelog (internal)

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 5ccbbeb

Comment thread src/sentry_scope.c Outdated
Comment thread src/sentry_core.c Outdated
Comment thread src/sentry_scope.c Outdated
Comment thread src/sentry_core.c Outdated
Comment thread src/sentry_core.c Outdated
Comment thread src/sentry_core.c Outdated
Comment thread src/sentry_scope.c
Comment thread src/sentry_scope.c
Comment thread src/sentry_core.c
Comment thread src/sentry_core.c
Comment thread src/sentry_core.c
Comment thread src/sentry_scope.h Outdated
Comment thread src/sentry_scope.h
Comment thread src/sentry_scope.h
Comment thread src/sentry_scope.c Outdated
@jpnurmi
jpnurmi force-pushed the jpnurmi/feat/scope-observer branch 2 times, most recently from 8bdc687 to f015370 Compare July 6, 2026 18:38
Comment thread src/sentry_scope.c
@jpnurmi
jpnurmi force-pushed the jpnurmi/feat/scope-observer branch from 267c782 to 2ad380b Compare July 7, 2026 13:20
@jpnurmi
jpnurmi requested review from JoshuaMoelans and mujacica July 7, 2026 14:19
@jpnurmi

jpnurmi commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

I got rid of the annoying _len arguments in the scope observer API, and normalized strings where needed in the _n overloads instead.

Comment thread src/sentry_scope.c
@jpnurmi
jpnurmi requested a review from limbonaut July 20, 2026 12:48
Comment thread src/sentry_core.c Outdated
Comment thread src/sentry_core.c Outdated
Comment thread src/sentry_scope.c
Comment thread src/sentry_scope.h Outdated
Comment thread src/sentry_scope.c
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.83270% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.50%. Comparing base (742eecd) to head (5ccbbeb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1839      +/-   ##
==========================================
+ Coverage   75.18%   75.50%   +0.32%     
==========================================
  Files          91       91              
  Lines       21379    21595     +216     
  Branches     3764     3836      +72     
==========================================
+ Hits        16074    16306     +232     
+ Misses       4477     4457      -20     
- Partials      828      832       +4     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@limbonaut limbonaut left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The most complete package among all SDKs, and well-covered. Nice work!
I left some suggestions for additional tests for you to consider if they're worth adding.

Comment thread src/sentry_scope.c
Comment on lines +169 to +171
if (g_scope.is_notifying > 0) {
// defer the flush requested by a reentrant scope change
g_scope.pending_flush = flush || g_scope.pending_flush;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Smart approach, nice!

Comment thread src/sentry_scope.h
* registration; the caller must not free it after that point.
*/
typedef struct sentry_scope_observer_s {
void *data;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should it be mentioned in doc comments?

Comment thread tests/unit/test_scope.c
sentry_value_decref(d.attachments);
sentry_close();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

sentry_clear_attachments() and sentry_scope_set_fingerprints() could use some coverage.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

And also worth considering if deferred flush mechanics are worth testing against something like a fake backend.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5ccbbeb. Configure here.

Comment thread src/sentry_scope.c
= sentry__attachments_add(&scope->attachments, attachment);
if (added == attachment) {
SENTRY_SCOPE_NOTIFY(scope, add_attachment, attachment);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Freed pointer compared after add

Medium Severity

sentry__attachments_add frees the input on duplicate or oversized rejection, then added == attachment still reads that pointer. That is undefined behavior on the failure path and can be miscompiled; notify gating should not depend on a freed pointer value.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5ccbbeb. Configure here.

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