Skip to content

Commit

Permalink
Document how to attach data attributes onto a span/transaction in PHP (
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Jan 7, 2025
1 parent 1d5c744 commit 749aae4
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,49 @@ To capture transactions and spans customized to your organization's needs, you m
<PlatformContent includePath="performance/add-spans-example" />

<PlatformContent includePath="performance/retrieve-transaction" />

## Adding Span & Transaction Data Attributes

You can capture data attributes along with your spans and transactions. You can specify data attributes when starting a span or transaction:

```php
// Create a transaction and assign data attributes...
$transactionContext = \Sentry\Tracing\TransactionContext::make()
->setName('Example Transaction')
->setOp('http.server')
->setData([
'data_attribute_1' => 42,
'data_attribute_2' => true,
]);
$transaction = \Sentry\startTransaction($transactionContext);

// ... or create a span and assign data attributes

$spanContext = \Sentry\Tracing\SpanContext::make()
->setOp('http.client')
->setData([
'data_attribute_1' => 42,
'data_attribute_2' => true,
]);
$transaction->startChild($context);
```

Or you can add data attributes to an existing span or transaction:

```php
$transaction = \Sentry\SentrySdk::getCurrentHub()->getTransaction();
if ($transaction !== null) {
$transaction->setData([
'data_attribute_1' => 42,
'data_attribute_2' => true,
]);
}

$span = \Sentry\SentrySdk::getCurrentHub()->getSpan();
if ($span !== null) {
$span->setData([
'data_attribute_1' => 42,
'data_attribute_2' => true,
]);
}
```

0 comments on commit 749aae4

Please sign in to comment.