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

Aberta
#3,206 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

@itsrayeedscodespace já está trabalhando nisso.

Desde 14/11/2026.

  • #3207 de @itsrayeedscodespace — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
38/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
ruby
Domínio
observability

Direção de pesquisa

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).

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Ruby
Estrelas
990
Forks
552
Merge médio
2d 16h
PRs com merge (30d)
29

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de getsentry/sentry-ruby

Todas as issues de getsentry/sentry-ruby

Issues semelhantes

Mais issues de Ruby

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.