diff --git a/docs/platforms/php/common/tracing/instrumentation/custom-instrumentation.mdx b/docs/platforms/php/common/tracing/instrumentation/custom-instrumentation.mdx index 2d6ccdb2d2e70..c7ebdbc37073f 100644 --- a/docs/platforms/php/common/tracing/instrumentation/custom-instrumentation.mdx +++ b/docs/platforms/php/common/tracing/instrumentation/custom-instrumentation.mdx @@ -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 `before_send_transaction`: + +```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; + }, +]); +``` diff --git a/docs/platforms/php/index.mdx b/docs/platforms/php/index.mdx index a9b8895cb2129..973fe6f94a3da 100644 --- a/docs/platforms/php/index.mdx +++ b/docs/platforms/php/index.mdx @@ -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