Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to attach data attributes onto a span/transaction in PHP #12268

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
@@ -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,
]);
}
```