Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Scope._transaction not cleared when span is set to None

未关闭 适合新手
#7,774 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

从 Scope.span setter 开始,跟踪 Transaction 和 None 的赋值如何更新 _transaction;然后检查附近的 Scope 测试,了解此处所述的上下文复制和事务退出行为。添加一个回归测试,展示将 span 设置为 None 会清除事务,而分配一个子 span 不会清除事务,并运行相关的 Scope 测试套件。

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

描述

Bug Python
How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.68.1

Steps to Reproduce

Start a top-level transaction via OpenAIIntegration (or any path that sets scope.span to a Transaction).
Nest work that restores scope.span to None when the transaction finishes (normal with / start_transaction exit).
Later, on the same Scope (same thread, or a worker that got the Scope via copy_context()), capture an unrelated error with no active transaction.

Expected Result

After scope.span = None, scope._transaction is cleared so later errors are not attributed to the finished transaction (culprit / transaction name should not stick).

sentry-sdk 2.68.1 (deps: certifi, urllib3>=1.26.11)

Actual Result

Scope.span’s setter sets _transaction when given a Transaction, but does not clear _transaction when span is None. Stale _transaction remains; unrelated errors inherit the old transaction name (e.g. responses gpt-5.6-luna) as culprit even when the stack has nothing to do with that LLM call.

Clearing on every non-Transaction would be wrong: child spans set scope.span = self while a transaction is still live. The fix clears _transaction only when span is None.

主要语言
Python
星标
2.2k
派生
680
平均合并
1 天 1 小时
30 天内合并 PR
267

环境准备

从这里开始

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

getsentry/sentry-python 的其他 Issue

查看 getsentry/sentry-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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