Skip to content

Commit

Permalink
feat(rust): add instructions on how to add data to a span/transaction (
Browse files Browse the repository at this point in the history
…#12591)

* feat(rust): add instructions on how to add data to a span/transaction

* improve

* Update custom-instrumentation.mdx

* Update custom-instrumentation.mdx

* Update custom-instrumentation.mdx
  • Loading branch information
lcian authored Feb 6, 2025
1 parent e01412b commit a430f7e
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,31 @@ To capture transactions and spans customized to your organization's needs, you m
<PlatformContent includePath="performance/concurrency" />

<PlatformContent includePath="performance/connect-errors-spans" />

## Adding Span & Transaction Data Attributes

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

```rust
use serde_json::json;

// Create a transaction and assign data attributes...
let tx_ctx = sentry::TransactionContext::new("Example Transaction", "http.server");
let transaction = sentry::start_transaction(tx_ctx);
transaction.set_data("attribute_1", "hello".into());
transaction.set_data("attribute_2", 42.into());

// ... or create a span and assign data attributes
let span = transaction.start_child("http.client", "Example span");
span.set_data("is_ok", true.into());
span.set_data("other_data", json!({ "an": "object" }));
```

Or you can add data attributes to an existing span:

```rust
let span = Hub::current().configure_scope(|scope| scope.get_span());
if let Some(span) = span {
span.set_data("hello", "world".into());
}
```

0 comments on commit a430f7e

Please sign in to comment.