Skip to content

Commit 52fe1bc

Browse files
feat(apple): Attach data onto a span/transaction (#12520)
Add docs for how to attach data onto span/transaction. Fixes GH-12521
1 parent 2066d45 commit 52fe1bc

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

docs/platforms/apple/common/tracing/instrumentation/custom-instrumentation.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ To capture transactions and spans customized to your organization's needs, you m
1717
<PlatformContent includePath="performance/create-transaction-bound-to-scope" />
1818

1919
<PlatformContent includePath="performance/connect-errors-spans" />
20+
21+
<PlatformContent includePath="performance/improving-data" />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Improving Data on Transactions and Spans
2+
3+
### Adding Data Attributes to Transactions
4+
5+
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:
6+
7+
```swift {tabTitle:Swift}
8+
let transaction = SentrySDK.startTransaction(name: "processOrderBatch", operation: "task")
9+
transaction.setData(value: "value1", key: "my-data-attribute-1")
10+
transaction.setData(value: 42, key: "my-data-attribute-2")
11+
transaction.setData(value: true, key: "my-data-attribute-3")
12+
13+
transaction.setData(value: ["value1", "value2", "value3"], key: "my-data-attribute-4")
14+
transaction.setData(value: [42, 43, 44], key: "my-data-attribute-5")
15+
transaction.setData(value: [true, false, true], key: "my-data-attribute-6")
16+
```
17+
```objc {tabTitle:Objective-C}
18+
id<SentrySpan> transaction = [SentrySDK startTransactionWithName:@"processOrderBatch" operation:@"task"];
19+
[transaction setDataValue:@"value1" forKey:@"my-data-attribute-1"];
20+
[transaction setDataValue:@(42) forKey:@"my-data-attribute-2"];
21+
[transaction setDataValue:@(YES) forKey:@"my-data-attribute-3"];
22+
23+
[transaction setDataValue:@[@"value1", @"value2", @"value3"] forKey:@"my-data-attribute-4"];
24+
[transaction setDataValue:@[@(42), @(43), @(44)] forKey:@"my-data-attribute-5"];
25+
[transaction setDataValue:@[@(YES), @(NO), @(YES)] forKey:@"my-data-attribute-6"];
26+
```
27+
28+
### Adding Data Attributes to Spans
29+
30+
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:
31+
32+
```swift {tabTitle:Swift}
33+
let span = parent.startChild(operation: "operation")
34+
span.setData(value: "value1", key: "my-data-attribute-1")
35+
span.setData(value: 42, key: "my-data-attribute-2")
36+
span.setData(value: true, key: "my-data-attribute-3")
37+
38+
span.setData(value: ["value1", "value2", "value3"], key: "my-data-attribute-4")
39+
span.setData(value: [42, 43, 44], key: "my-data-attribute-5")
40+
span.setData(value: [true, false, true], key: "my-data-attribute-6")
41+
```
42+
```objc {tabTitle:Objective-C}
43+
id<SentrySpan> span = [transaction startChildWithOperation:@"task"];
44+
[span setDataValue:@"value1" forKey:@"my-data-attribute-1"];
45+
[span setDataValue:@(42) forKey:@"my-data-attribute-2"];
46+
[span setDataValue:@(YES) forKey:@"my-data-attribute-3"];
47+
48+
[span setDataValue:@[@"value1", @"value2", @"value3"] forKey:@"my-data-attribute-4"];
49+
[span setDataValue:@[@(42), @(43), @(44)] forKey:@"my-data-attribute-5"];
50+
[span setDataValue:@[@(YES), @(NO), @(YES)] forKey:@"my-data-attribute-6"];
51+
```

0 commit comments

Comments
 (0)