Skip to content

Commit a4fe416

Browse files
authored
php: Document how to attach data attributes to a transaction and all its spans (#12442)
1 parent 61dc018 commit a4fe416

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,34 @@ if ($span !== null) {
6161
]);
6262
}
6363
```
64+
65+
To update an existing data attribute, you can combine `setData()` with `getData()`:
66+
67+
```php
68+
$span->setData([
69+
'data_attribute_1' => $span->getData('data_attribute_1', 0) + 1,
70+
]);
71+
72+
$transaction->setData([
73+
'data_attribute_1' => $transaction->getData('data_attribute_1', 0) + 1,
74+
]);
75+
```
76+
77+
To attach data attributes to the transaction and all its spans, you can use <PlatformLink to="/configuration/filtering/#using-before-send-transaction">`before_send_transaction`</PlatformLink>:
78+
79+
```php
80+
\Sentry\init([
81+
'dsn' => '___PUBLIC_DSN___',
82+
'before_send_transaction' => function(Event $event) {
83+
$spans = $event->getSpans();
84+
foreach ($spans as $span) {
85+
$span->setData([
86+
'data_attribute_1' => 42,
87+
'data_attribute_2' => true,
88+
]);
89+
}
90+
91+
$event->contexts['trace']['data']['foo'] = 42;
92+
},
93+
]);
94+
```

docs/platforms/php/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ To capture all errors, even the one during the startup of your application, you
5353

5454
```php {"onboardingOptions": {"performance": "3-4", "profiling": "5-6"}}
5555
\Sentry\init([
56-
'dsn' => '___PUBLIC_DSN___' ,
56+
'dsn' => '___PUBLIC_DSN___',
5757
// Specify a fixed sample rate
5858
'traces_sample_rate' => 1.0,
5959
// Set a sampling rate for profiling - this is relative to traces_sample_rate

0 commit comments

Comments
 (0)