Skip to content

Commit

Permalink
feat(apple): Attach data onto a span/transaction (#12520)
Browse files Browse the repository at this point in the history
Add docs for how to attach data onto span/transaction.

Fixes GH-12521
  • Loading branch information
philipphofmann authored Jan 31, 2025
1 parent 2066d45 commit 52fe1bc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ To capture transactions and spans customized to your organization's needs, you m
<PlatformContent includePath="performance/create-transaction-bound-to-scope" />

<PlatformContent includePath="performance/connect-errors-spans" />

<PlatformContent includePath="performance/improving-data" />
51 changes: 51 additions & 0 deletions platform-includes/performance/improving-data/apple.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## Improving Data on Transactions and Spans

### Adding Data Attributes to Transactions

You can add data attributes to your transactions. This data is visible in the trace explorer in Sentry. Data attributes can be of type `String`, `Number` or `Boolean`, as well as (non-mixed) arrays of these types:

```swift {tabTitle:Swift}
let transaction = SentrySDK.startTransaction(name: "processOrderBatch", operation: "task")
transaction.setData(value: "value1", key: "my-data-attribute-1")
transaction.setData(value: 42, key: "my-data-attribute-2")
transaction.setData(value: true, key: "my-data-attribute-3")

transaction.setData(value: ["value1", "value2", "value3"], key: "my-data-attribute-4")
transaction.setData(value: [42, 43, 44], key: "my-data-attribute-5")
transaction.setData(value: [true, false, true], key: "my-data-attribute-6")
```
```objc {tabTitle:Objective-C}
id<SentrySpan> transaction = [SentrySDK startTransactionWithName:@"processOrderBatch" operation:@"task"];
[transaction setDataValue:@"value1" forKey:@"my-data-attribute-1"];
[transaction setDataValue:@(42) forKey:@"my-data-attribute-2"];
[transaction setDataValue:@(YES) forKey:@"my-data-attribute-3"];

[transaction setDataValue:@[@"value1", @"value2", @"value3"] forKey:@"my-data-attribute-4"];
[transaction setDataValue:@[@(42), @(43), @(44)] forKey:@"my-data-attribute-5"];
[transaction setDataValue:@[@(YES), @(NO), @(YES)] forKey:@"my-data-attribute-6"];
```
### Adding Data Attributes to Spans
You can add data attributes to your spans. This data is visible in the trace explorer in Sentry. Data attributes can be of type `String`, `Number` or `Boolean`, as well as (non-mixed) arrays of these types:
```swift {tabTitle:Swift}
let span = parent.startChild(operation: "operation")
span.setData(value: "value1", key: "my-data-attribute-1")
span.setData(value: 42, key: "my-data-attribute-2")
span.setData(value: true, key: "my-data-attribute-3")
span.setData(value: ["value1", "value2", "value3"], key: "my-data-attribute-4")
span.setData(value: [42, 43, 44], key: "my-data-attribute-5")
span.setData(value: [true, false, true], key: "my-data-attribute-6")
```
```objc {tabTitle:Objective-C}
id<SentrySpan> span = [transaction startChildWithOperation:@"task"];
[span setDataValue:@"value1" forKey:@"my-data-attribute-1"];
[span setDataValue:@(42) forKey:@"my-data-attribute-2"];
[span setDataValue:@(YES) forKey:@"my-data-attribute-3"];

[span setDataValue:@[@"value1", @"value2", @"value3"] forKey:@"my-data-attribute-4"];
[span setDataValue:@[@(42), @(43), @(44)] forKey:@"my-data-attribute-5"];
[span setDataValue:@[@(YES), @(NO), @(YES)] forKey:@"my-data-attribute-6"];
```

0 comments on commit 52fe1bc

Please sign in to comment.