From b4d4cc01d996d2347693347ab14fc489d1526dbc Mon Sep 17 00:00:00 2001 From: lcian Date: Wed, 5 Feb 2025 15:02:20 +0100 Subject: [PATCH 1/5] feat(rust): add instructions on how to add data to a span/transaction --- .../custom-instrumentation.mdx | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx index 50f48be8f767f9..e4550b0f328502 100644 --- a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx +++ b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx @@ -19,3 +19,40 @@ 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 or transaction: + +```rust +Hub::current().configure_scope(|scope| { + if let Some(span) = scope.get_span() { + span.set_data("hello", "world".into()); + } +}); + +Hub::current().configure_scope(|scope| { + if let Some(transaction) = scope.get_transaction() { + transaction.set_data("hello", "world".into()); + } +}); +``` From f8f40b29026bccd180204f736c526b6a0ff9a87a Mon Sep 17 00:00:00 2001 From: lcian Date: Wed, 5 Feb 2025 15:15:05 +0100 Subject: [PATCH 2/5] improve --- .../custom-instrumentation.mdx | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx index e4550b0f328502..b27fec863ccbf6 100644 --- a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx +++ b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx @@ -44,15 +44,13 @@ span.set_data("other_data", json!({ "an": "object" })); Or you can add data attributes to an existing span or transaction: ```rust -Hub::current().configure_scope(|scope| { - if let Some(span) = scope.get_span() { - span.set_data("hello", "world".into()); - } -}); - -Hub::current().configure_scope(|scope| { - if let Some(transaction) = scope.get_transaction() { - transaction.set_data("hello", "world".into()); - } -}); +let span = Hub::current().configure_scope(|scope| scope.get_span()); +if let Some(span) = span { + span.set_data("hello", "world".into()); +} + +let transaction = Hub::current().configure_scope(|scope| scope.get_transaction()); +if let Some(transaction) = transaction { + transaction.set_data("hello", "world".into()); +} ``` From 6fc943599ba98aa8ac9631c401ddf7b57a99efc0 Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Wed, 5 Feb 2025 23:43:01 +0100 Subject: [PATCH 3/5] Update custom-instrumentation.mdx --- .../common/tracing/instrumentation/custom-instrumentation.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx index b27fec863ccbf6..fae4904d590179 100644 --- a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx +++ b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx @@ -26,7 +26,6 @@ You can capture data attributes along with your spans and transactions. You can ```rust use serde_json::json; -// ... // Create a transaction and assign data attributes... let tx_ctx = sentry::TransactionContext::new("Example Transaction", "http.server"); From 8eecfd7f68cf5b92b6ed135c7365719e15eae864 Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Thu, 6 Feb 2025 00:13:06 +0100 Subject: [PATCH 4/5] Update custom-instrumentation.mdx --- .../common/tracing/instrumentation/custom-instrumentation.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx index fae4904d590179..0b6e123c373ecc 100644 --- a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx +++ b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx @@ -37,7 +37,6 @@ transaction.set_data("attribute_2", 42.into()); 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 or transaction: From 917b791ec07544a8c4a2299dd38b44600a3b8e1d Mon Sep 17 00:00:00 2001 From: Lorenzo Cian Date: Thu, 6 Feb 2025 19:23:14 +0100 Subject: [PATCH 5/5] Update custom-instrumentation.mdx --- .../tracing/instrumentation/custom-instrumentation.mdx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx index 0b6e123c373ecc..8a88f40899afe2 100644 --- a/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx +++ b/docs/platforms/rust/common/tracing/instrumentation/custom-instrumentation.mdx @@ -39,16 +39,11 @@ 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 or transaction: +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()); } - -let transaction = Hub::current().configure_scope(|scope| scope.get_transaction()); -if let Some(transaction) = transaction { - transaction.set_data("hello", "world".into()); -} ```