Skip to content

Commit ccc6278

Browse files
authored
fix(ruby): Make custom instrumentation samples nil safe (#16554)
## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
1 parent 4cbbac2 commit ccc6278

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

platform-includes/performance/add-spans-example/ruby.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class OrdersController < ApplicationController
88
order = Order.new
99

1010
Sentry.with_child_span(op: :process_items, description: 'processing items') do |span|
11-
span.set_data(:key, 'value')
11+
span&.set_data(:key, 'value')
1212

1313
order.process_items(params)
1414
end
@@ -28,12 +28,14 @@ class OrdersController < ApplicationController
2828
order = Order.new
2929
transaction = Sentry.get_current_scope.get_transaction
3030

31-
transaction.with_child_span(op: :process_items, description: 'processing items') do |span|
32-
span.set_data(:key, 'value')
31+
if transaction
32+
transaction.with_child_span(op: :process_items, description: 'processing items') do |span|
33+
span&.set_data(:key, 'value')
34+
order.process_items(params)
35+
end # the child span ends with the block
36+
else
3337
order.process_items(params)
34-
end # the child span ends with the block
38+
end
3539
end
3640
end
3741
```
38-
39-
Keep in mind that there may not be an active transaction, in which case `get_transaction` returns `nil`. This case needs to be handled manually and is missing from this example.

platform-includes/performance/improving-data/ruby.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ You can add data attributes to your spans the same way, with the same type restr
2222

2323
```ruby
2424
Sentry.with_child_span(op: "my-span") do |span|
25+
next unless span
26+
2527
span.set_data("my-data-attribute-1", "value1")
2628
span.set_data("my-data-attribute-2", 42)
2729
span.set_data("my-data-attribute-3", true)

platform-includes/performance/retrieve-transaction/ruby.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ transaction = Sentry.get_current_scope.get_transaction || Sentry.start_transacti
77

88
span = transaction.start_child(op: 'operation')
99
# perform the operation
10-
span.finish
10+
span.finish if span
1111
```
1212

1313
## Retrieve the Current Span

0 commit comments

Comments
 (0)