Skip to content

Commit c2571b5

Browse files
authored
feat(native): local scopes (#15241)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Adds missing documentation for local scopes introduced earlier in sentry-native [0.9.0](https://github.com/getsentry/sentry-native/releases/tag/0.9.0): - getsentry/sentry-native#1248 ## 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 --> - [x] 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:* - [x] Checked Vercel preview for correctness, including links - [x] 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) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent c3aa432 commit c2571b5

File tree

2 files changed

+20
-5
lines changed
  • docs/platforms/native/common/enriching-events/scopes
  • platform-includes/enriching-events/scopes/configure-scope

2 files changed

+20
-5
lines changed

docs/platforms/native/common/enriching-events/scopes/index.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ routes or controllers.
3535
As you start using an SDK, a scope and hub are automatically created for you out
3636
of the box. It's unlikely that you'll interact with the hub directly unless you're
3737
writing an integration or you want to create or destroy scopes. Scopes, on the
38-
other hand are more user facing. You can call <PlatformIdentifier name="configure-scope" /> at any point in
38+
other hand are more user facing. You can call various setters at any point in
3939
time to modify data stored on the scope. This is useful for doing things like
4040
[modifying the context](../context/).
4141

@@ -53,7 +53,8 @@ For details on how this affects tracing, check out the [Connect Errors With Span
5353

5454
## Configuring the Scope
5555

56-
The most useful operation when working with scopes is the <PlatformIdentifier name="configure-scope" /> function. It can be used to reconfigure the current scope.
56+
The Native SDK maintains most data in a global scope, but allows creating transient
57+
local scopes for capturing individual events.
5758

5859
You can, for instance, add custom tags or inform Sentry about the currently authenticated user.
5960

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
The Native SDK maintains all data in a single global scope.
2-
3-
```c
1+
```c {tabTitle:Global Scope}
42
#include <sentry.h>
53

64
sentry_set_tag("my-tag", "my value");
@@ -9,3 +7,19 @@ sentry_set_tag("my-tag", "my value");
97
sentry_value_t user = sentry_value_new_user("42", "Jane Doe", "[email protected]", "{{auto}}");
108
sentry_set_user(user);
119
```
10+
11+
```c {tabTitle:Local Scope}
12+
#include <sentry.h>
13+
14+
sentry_scope_t *scope = sentry_local_scope_new();
15+
16+
sentry_scope_set_tag(scope, "my-tag", "my scoped value");
17+
18+
// Set a user with id, username, email, and ip_address
19+
sentry_value_t user = sentry_value_new_user("42", "Jane Doe", "[email protected]", "{{auto}}");
20+
sentry_scope_set_user(scope, user);
21+
22+
sentry_value_t event = sentry_value_new_event();
23+
/* ... */
24+
sentry_capture_event_with_scope(event, scope);
25+
```

0 commit comments

Comments
 (0)