with_child_span drops spans when blocks exit via break, return, or throw

未关闭
#3,206 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@itsrayeedscodespace 已经在做这个了。

开始于 2026年11月14日。

  • #3207 来自 @itsrayeedscodespace —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
ruby
领域
observability

调研方向

Start in the SDK's Span#with_child_span, where finish runs after yield and in the rescue branch, and in the public wrapper on the Sentry module that delegates to it. Read the existing specs around span finishing and the transaction event's span filtering to confirm an unfinished span is dropped. The fix is to finish the child span in an ensure while keeping the StandardError handling and the direct return value, then run the span specs plus the four reproduction cases (break, nonlocal return, catch/throw, custom Exception).

由索引模型根据 Issue 内容生成。

描述

Bug Ruby Traces Waiting for: Product Owner
Issue Description

Sentry.with_child_span silently loses its child span when the block exits via break, a nonlocal return, or throw. The same happens when the block raises an exception outside StandardError.

The underlying Span#with_child_span calls finish after yield and in its rescue branch. None of those paths run for nonlocal control flow. The hub restores the parent scope in ensure, but the child still has a nil timestamp, so TransactionEvent filters it out of the captured transaction.

Reproduction Steps

On current master (314eacad), with Ruby 3.4.12:

require "sentry-ruby"

Sentry.init do |config|
  config.dsn = "http://public@localhost/1"
  config.transport.transport_class = Sentry::DummyTransport
  config.background_worker_threads = 0
  config.traces_sample_rate = 1.0
end

transaction = Sentry.start_transaction(name: "repro", sampled: true)
Sentry.get_current_scope.set_span(transaction)
result = Sentry.with_child_span(op: "work") { break :done }
transaction.finish

p result # :done
p Sentry.get_current_client.transport.events.last.spans # []

A method returning from inside the span block, catch/throw, and a raised custom Exception subclass all produce the same missing span. Four public-API regression specs reproduce this on unchanged master.

Expected Behavior

The child span is finished and included in the transaction regardless of how control leaves the block. Return values and exception propagation remain unchanged.

Actual Behavior

The child span is unfinished and silently excluded from the captured transaction.

Proposed Fix

Finish the child span in an ensure block around the yield. Keep the existing StandardError handling and direct Span#with_child_span return value.

主要语言
Ruby
星标
990
派生
552
平均合并
2 天 16 小时
30 天内合并 PR
29

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

getsentry/sentry-ruby 的其他 Issue

查看 getsentry/sentry-ruby 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。