diff --git a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx index 50f48be8f767f..8a88f40899afe 100644 --- a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx +++ b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx @@ -19,3 +19,31 @@ To capture transactions and spans customized to your organization's needs, you m + +## 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()); +} +```