Skip to content

Commit a430f7e

Browse files
authored
feat(rust): add instructions on how to add data to a span/transaction (#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
1 parent e01412b commit a430f7e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx

+28
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,31 @@ To capture transactions and spans customized to your organization's needs, you m
1919
<PlatformContent includePath="performance/concurrency" />
2020

2121
<PlatformContent includePath="performance/connect-errors-spans" />
22+
23+
## Adding Span & Transaction Data Attributes
24+
25+
You can capture data attributes along with your spans and transactions. You can set data attributes when starting a span or transaction:
26+
27+
```rust
28+
use serde_json::json;
29+
30+
// Create a transaction and assign data attributes...
31+
let tx_ctx = sentry::TransactionContext::new("Example Transaction", "http.server");
32+
let transaction = sentry::start_transaction(tx_ctx);
33+
transaction.set_data("attribute_1", "hello".into());
34+
transaction.set_data("attribute_2", 42.into());
35+
36+
// ... or create a span and assign data attributes
37+
let span = transaction.start_child("http.client", "Example span");
38+
span.set_data("is_ok", true.into());
39+
span.set_data("other_data", json!({ "an": "object" }));
40+
```
41+
42+
Or you can add data attributes to an existing span:
43+
44+
```rust
45+
let span = Hub::current().configure_scope(|scope| scope.get_span());
46+
if let Some(span) = span {
47+
span.set_data("hello", "world".into());
48+
}
49+
```

0 commit comments

Comments
 (0)