Skip to content

feat: add contextmanager-based management command observability filter - #400

Open
rahulkanneri-2u wants to merge 1 commit into
openedx:mainfrom
rahulkanneri-2u:rahul/mgmt-command-observability-filter
Open

rahulkanneri-2u wants to merge 1 commit into
openedx:mainfrom
rahulkanneri-2u:rahul/mgmt-command-observability-filter

Conversation

@rahulkanneri-2u

@rahulkanneri-2u rahulkanneri-2u commented Sep 29, 2026 •

Copy link
Copy Markdown

Summary

Adds the ManagementCommandContextmanagerRequested filter under openedx_filters.management. The filter is triggered in manage.py before a Django management command executes, and lets pipeline steps wrap the command's execution in a context manager (for example, to add observability such as Datadog tracing, custom attributes, or structured logging).

Management commands don't go through Django's normal request middleware, so this gives pipeline authors one shared instrumentation point instead of having to modify every command individually.

Why this PR (supersedes #344)

This supersedes #344 — that PR's branch lives on a fork that can no longer be updated, so this PR continues the same work on a new branch. All outstanding review feedback from #344 is carried over here: the output tuple now matches the input signature (command_contextmanager, command_name, service_variant); the trigger repository is corrected to openedx/openedx-platform; the docstring is expanded to explain why the filter exists (management commands skip middleware) and includes a usage example, addressing the request for "a more detailed docstring about the expected use case"; tests use pytest-style assert statements; the version is bumped 3.14.0 to 3.15.0 with a changelog fragment added via scriv; commits are squashed into one; and the branch is rebased onto current main.

Original implementation credit is preserved via the commit author.

Testing instructions

Ran pytest openedx_filters/management/ (1 test, passes) and the full suite pytest (116 passed). Also ran pycodestyle --max-line-length=120 openedx_filters/management/filters.py with no violations.

Other information

Supersedes #344, which will be closed with a link to this PR. Downstream, edx-platform PR 200, edx-filters-pipelines PR 16, and edx-internal PR 14130 depend on this being released to bump their openedx-filters pin. CI (Python CI / Lint Commit Messages) is queued behind maintainer approval since this is a first PR from this fork account, so it hasn't run yet.

Merge checklist status

Done: changelog entry added via scriv, docstring/documentation updated, no new dependencies, commits squashed into one, unit tests added. Not yet: reviewer approval, CI build (queued on maintainer approval to run). Post-merge steps (release workflow, PyPI check, branch deletion, bumping the package in downstream Open edX platform requirements) are not started.

Adds the ManagementCommandContextmanagerRequested filter under the
openedx_filters.management package. The filter is invoked in
manage.py before a Django management command is executed, allowing
pipeline steps to wrap the command's execution in a context manager
(for example, to add observability such as Datadog tracing and
structured logging) without changing each command individually,
since management commands don't go through Django's normal request
middleware.

Supersedes openedx#344, rebased onto main to resolve conflicts, with the
version bump and changelog entry requested in review.
@rahulkanneri-2u

Copy link
Copy Markdown
Author

@pwnage101 @feanil I took over openedx/openedx-filters#344 and brought the changes over to this PR, along with a rebase and fixes for the outstanding review comments. Could you review this so we can take it forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants