Skip to content

Commit 9fbd290

Browse files
feat(apple): Transaction bound to scope (#4901)
Add Create transaction bound to scope as Java already has it because the Apple SDK supports the bound to scope feature. Co-authored-by: Manoel Aranda Neto <[email protected]>
1 parent d0b1592 commit 9fbd290

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Create Transaction Bound to The Current Scope
2+
3+
4+
Our SDK can bind a transaction to the scope making it accessible to every method running within this scope by calling `SentrySDK#startTransaction` method with `bindToScope` parameter to `true`.
5+
6+
In cases where you want to attach Spans to an already ongoing Transaction you can use `SentrySDK.span`. This method will return a `SpanProtocol` in case there is a running Transaction or a `Span` in case there is already a running Span, otherwise it returns `nil`.
7+
8+
9+
```swift {tabTitle:Swift}
10+
import Sentry
11+
12+
let transaction = SentrySDK.startTransaction(
13+
name: "processOrderBatch",
14+
operation: "task",
15+
bindToScope: true
16+
)
17+
processOrderBatch()
18+
transaction.finish()
19+
20+
func processOrderBatch() {
21+
var span = SentrySDK.span
22+
23+
if span == nil {
24+
span = SentrySDK.startTransaction(name: "processOrderBatch", operation: "task")
25+
}
26+
27+
var innerSpan = span.startChild(operation: "subtask")
28+
// omitted code
29+
innerSpan.finish()
30+
}
31+
```
32+
33+
```objc {tabTitle:Objective-C}
34+
@import Sentry;
35+
36+
id<SentrySpan> transaction =
37+
[SentrySDK startTransactionWithName:@"processOrderBatch"
38+
operation:@"task"
39+
bindToScope:YES];
40+
41+
42+
[self processOrderBatch];
43+
[transaction finish];
44+
45+
- (void)processOrderBatch {
46+
id<SentrySpan> span = SentrySDK.span;
47+
48+
if (span == nil) {
49+
span = [SentrySDK startTransactionWithName:@"processOrderBatch"
50+
operation:@"task"];
51+
}
52+
53+
id<SentrySpan> innerSpan = [span startChildWithOperation:@"subtask"];
54+
// omitted code
55+
[innerSpan finish];
56+
}
57+
```

src/platforms/common/performance/instrumentation/custom-instrumentation.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ To instrument certain regions of your code, you can create transactions to captu
5252

5353
<PlatformContent includePath="performance/add-spans-example" />
5454

55-
<PlatformSection supported={["java"]}>
55+
<PlatformSection supported={["java", "apple"]}>
5656

5757
<PlatformContent includePath="performance/create-transaction-bound-to-scope" />
5858

5959
</PlatformSection>
6060

61-
<PlatformSection notSupported={["java", "native"]}>
61+
<PlatformSection notSupported={["java", "native", "apple"]}>
6262

6363
<PlatformContent includePath="performance/retrieve-transaction" />
6464

0 commit comments

Comments
 (0)