Skip to content
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
Expand Up @@ -61,3 +61,34 @@ if ($span !== null) {
]);
}
```

To update an existing data attribute, you can combine `setData()` with `getData()`:

```php
$span->setData([
'data_attribute_1' => $span->getData('data_attribute_1', 0) + 1,
]);

$transaction->setData([
'data_attribute_1' => $transaction->getData('data_attribute_1', 0) + 1,
]);
```

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>:

```php
\Sentry\init([
'dsn' => '___PUBLIC_DSN___',
'before_send_transaction' => function(Event $event) {
$spans = $event->getSpans();
foreach ($spans as $span) {
$span->setData([
'data_attribute_1' => 42,
'data_attribute_2' => true,
]);
}

$event->contexts['trace']['data']['foo'] = 42;
},
]);
```
2 changes: 1 addition & 1 deletion docs/platforms/php/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ To capture all errors, even the one during the startup of your application, you

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