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

オープン
#3,206 コメント 1 件 リアクション 0 件 担当者 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時間
マージ済み PR(30日)
29

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

getsentry/sentry-ruby のほかの issue

getsentry/sentry-ruby の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。