Skip to content

fix(pyramid): prevent double BeforeTraversal subscriber after config.commit()#4773

Closed
krrishapatel wants to merge 1 commit into
open-telemetry:mainfrom
krrishapatel:fix/pyramid-double-subscriber
Closed

fix(pyramid): prevent double BeforeTraversal subscriber after config.commit()#4773
krrishapatel wants to merge 1 commit into
open-telemetry:mainfrom
krrishapatel:fix/pyramid-double-subscriber

Conversation

@krrishapatel

Copy link
Copy Markdown

Description

Fixes #4663

When any Pyramid library calls config.commit() during its includeme (e.g. tomb_routes on every add_simple_route), the action state is cleared. A subsequent config.include() then triggers _traced_init on a child Configurator and registers the _before_traversal subscriber a second time, causing OpenTelemetry context corruption — child spans become orphaned as separate traces.

This adds a sentinel attribute on the registry to ensure _before_traversal is registered only once per application, regardless of how many times config.commit() is called during configuration.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added two regression tests in TestDoubleSubscriberRegistration:

  • test_commit_does_not_double_register_subscriber — verifies only one BeforeTraversal handler exists after config.commit() + subsequent includes
  • test_normal_operation_after_commit — verifies tracing still works correctly in this scenario

All 33 existing pyramid tests continue to pass.

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the contributing guidelines
  • Self-reviewed the changes
  • Tests added that validate the fix

Assisted-by: Claude Opus 4.6

…commit()

Guard _traced_init against re-registering the BeforeTraversal subscriber
when config.commit() clears Pyramid's action_state deduplication. Uses a
sentinel on the registry to ensure callbacks are included only once.

Fixes open-telemetry#4663

Assisted-by: Claude Opus 4.6
@xrmx

xrmx commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Duplicated of #4741, not cool to waste reviewers time with duplicated PRs.

@xrmx xrmx closed this Jul 8, 2026
@krrishapatel krrishapatel deleted the fix/pyramid-double-subscriber branch July 8, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

opentelemetry-instrumentation-pyramid double BeforeTraversal subscriber registration after config.commit()

2 participants