Skip to content

feat(apple): Transaction bound to scope #4901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Create Transaction Bound to The Current Scope


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`.

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`.


```swift {tabTitle:Swift}
import Sentry

let transaction = SentrySDK.startTransaction(
name: "processOrderBatch",
operation: "task",
bindToScope: true
)
processOrderBatch()
transaction.finish()

func processOrderBatch() {
var span = SentrySDK.span

if span == nil {
span = SentrySDK.startTransaction(name: "processOrderBatch", operation: "task")
}

var innerSpan = span.startChild(operation: "subtask")
// omitted code
innerSpan.finish()
}
```

```objc {tabTitle:Objective-C}
@import Sentry;

id<SentrySpan> transaction =
[SentrySDK startTransactionWithName:@"processOrderBatch"
operation:@"task"
bindToScope:YES];


[self processOrderBatch];
[transaction finish];

- (void)processOrderBatch {
id<SentrySpan> span = SentrySDK.span;

if (span == nil) {
span = [SentrySDK startTransactionWithName:@"processOrderBatch"
operation:@"task"];
}

id<SentrySpan> innerSpan = [span startChildWithOperation:@"subtask"];
// omitted code
[innerSpan finish];
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ To instrument certain regions of your code, you can create transactions to captu

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

<PlatformSection supported={["java"]}>
<PlatformSection supported={["java", "apple"]}>

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

</PlatformSection>

<PlatformSection notSupported={["java", "native"]}>
<PlatformSection notSupported={["java", "native", "apple"]}>

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

Expand Down