Skip to content

Updates the Unity SDK docs with new SetData methods on spans & transa… #13457

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

Merged
merged 7 commits into from
May 13, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ To capture transactions and spans customized to your organization's needs, you m
<PlatformContent includePath="performance/add-spans-example" />

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

<PlatformContent includePath="performance/improving-data" />
18 changes: 18 additions & 0 deletions platform-includes/configuration/data-to-all-spans/unity.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```csharp
options =>
{
options.SetBeforeSendTransaction(transaction =>
{
// Set the attribute on the root span (transaction's trace context)
transaction.Contexts.Trace.SetData("myAttribute", "myValue");

// And on all child spans
foreach (var span in transaction.Spans)
{
span.SetData("myAttribute", "myValue");
}

return transaction;
});
};
```
39 changes: 39 additions & 0 deletions platform-includes/performance/improving-data/unity.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Improving Data on Transactions and Spans

### Adding Data Attributes to Transactions

You can add data attributes to your transactions. This data is visible and __queryable__ in the trace explorer in Sentry. Data attributes can be of type _string_, _number_ or _boolean_, as well as arrays of these types:

```csharp
var transaction = SentrySdk.StartTransaction("ProcessOrderBatch()", "task");
SentrySdk.ConfigureScope(scope => scope.Transaction = transaction);
transaction.SetData("my-data-attribute-1", "value1");
transaction.SetData("my-data-attribute-2", 42);
transaction.SetData("my-data-attribute-3", true);

transaction.SetData("my-data-attribute-4", new[] {"value1", "value2", "value3"});
transaction.SetData("my-data-attribute-5", new[] {42, 43, 44});
transaction.SetData("my-data-attribute-6", new[] {true, false, true});
```

### Adding Data Attributes to Spans

You can add data attributes to your transactions. This data is visible and __queryable__ in the trace explorer in Sentry. Data attributes can be of type _string_, _number_ or _boolean_, as well as arrays of these types:


```csharp
var span = parent.StartChild("task", "operation");
span.SetData("my-data-attribute-1", "value1");
span.SetData("my-data-attribute-2", 42);
span.SetData("my-data-attribute-3", true);

span.SetData("my-data-attribute-4", new[] {"value1", "value2", "value3"});
span.SetData("my-data-attribute-5", new[] {42, 43, 44});
span.SetData("my-data-attribute-6", new[] {true, false, true});
```

### Adding Attributes to all Spans and Transactions

To add an attribute to all spans and transactions, use the `SetBeforeSendTransaction` callback:

<PlatformContent includePath="configuration/data-to-all-spans" />
Loading