Skip to content

opentelemetry-instrumentation-pyramid: avoid duplicate traversal subscribers#4671

Closed
popsiclelmlm wants to merge 1 commit into
open-telemetry:mainfrom
popsiclelmlm:codex/otel-pyramid-before-traversal
Closed

opentelemetry-instrumentation-pyramid: avoid duplicate traversal subscribers#4671
popsiclelmlm wants to merge 1 commit into
open-telemetry:mainfrom
popsiclelmlm:codex/otel-pyramid-before-traversal

Conversation

@popsiclelmlm

Copy link
Copy Markdown

Description

Fixes #4663.

Summary

Prevent opentelemetry-instrumentation-pyramid from registering duplicate BeforeTraversal subscribers when Pyramid configuration includes run after config.commit().

Reproduction

A Pyramid include can call config.commit(), which resets Pyramid action state. A later config.include(...) creates another configurator and can run the OpenTelemetry callbacks include again. The new regression test simulates that flow and counts _before_traversal subscriber registrations.

Root cause

The instrumentation relied on Pyramid include de-duplication to avoid re-running callbacks.includeme. After config.commit() resets action state, that de-duplication can no longer prevent the callbacks include from registering _before_traversal again for the same registry.

Changes

  • Add a registry settings sentinel so callbacks.includeme only registers the BeforeTraversal subscriber once.
  • Keep SETTING_TRACE_ENABLED and tween insertion behavior on each include path.
  • Add a regression test for an include that calls config.commit() before a later include.
  • Add a changelog fragment.

Tests

  • /Users/liumin/Documents/OpenSourceContributions/opentelemetry-python-contrib-pika-consumer-wrap/.venv-tox/bin/tox -e py314-test-instrumentation-pyramid
  • /Users/liumin/Documents/OpenSourceContributions/opentelemetry-python-contrib-pika-consumer-wrap/.venv-tox/bin/tox -e lint-instrumentation-pyramid
  • .tox/lint-instrumentation-pyramid/bin/ruff check instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py instrumentation/opentelemetry-instrumentation-pyramid/tests/test_automatic.py
  • .tox/lint-instrumentation-pyramid/bin/ruff format --check instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py instrumentation/opentelemetry-instrumentation-pyramid/tests/test_automatic.py
  • git diff --check

Screenshots/Logs

N/A. This is a unit-level instrumentation fix.

Type of change

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

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@popsiclelmlm popsiclelmlm requested a review from a team as a code owner June 8, 2026 05:41
@popsiclelmlm popsiclelmlm deleted the codex/otel-pyramid-before-traversal branch June 12, 2026 14:03
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()

1 participant