Skip to content

[feat] Adds Django Version as a Metric - #510

Open
ethanthopkins wants to merge 11 commits into
django-commons:masterfrom
ethanthopkins:iss-503
Open

[feat] Adds Django Version as a Metric#510
ethanthopkins wants to merge 11 commits into
django-commons:masterfrom
ethanthopkins:iss-503

Conversation

@ethanthopkins

@ethanthopkins ethanthopkins commented Jun 1, 2026

Copy link
Copy Markdown
  • Adds new module (info) for static metrics such as Django Version. New module was justified as to not mix concerns with existing modules that represent dynamic variables.
  • Django version includes Major, Minor, and Patch in addition to the full version number.
  • Adds unit test for the metric added.
  • Imports module at Init.

All unit tests pass and Django Version displays on test Django Project.

Closes #503

Comment thread django_prometheus/tests/test_info.py Outdated
…ame to "Django" because "_info" is appended already in the metrics endpoint and for consistency with the Python_info metric. Updates unit test to reflect changes.
@ethanthopkins
ethanthopkins requested a review from OscarVanL June 3, 2026 17:39
@asherf
asherf requested review from Copilot and removed request for OscarVanL June 3, 2026 17:53
Comment thread django_prometheus/tests/test_info.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new Prometheus Info metric to expose the running Django version (django_info{...} 1.0), aligning with the feature request in #503 and similar ecosystem “*_info” metrics.

Changes:

  • Adds django_info (prometheus_client.Info) populated with Django version labels (major/minor/patchlevel/version).
  • Adds a unit test for the new metric.
  • Imports the new info module from django_prometheus.__init__ so the metric is registered on package import.
Show a summary per file
File Description
django_prometheus/info.py Introduces the django_info static Info metric and sets its label values at import time.
django_prometheus/tests/test_info.py Adds a test validating the django_info metric.
django_prometheus/__init__.py Ensures the new metrics module is imported/registered when importing django_prometheus.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Comment thread django_prometheus/info.py Outdated
Comment thread django_prometheus/tests/test_info.py Outdated
Comment thread django_prometheus/__init__.py Outdated
@ethanthopkins
ethanthopkins marked this pull request as draft June 3, 2026 19:06
@ethanthopkins
ethanthopkins marked this pull request as ready for review June 3, 2026 19:18
@ethanthopkins
ethanthopkins requested review from OscarVanL and asherf June 3, 2026 19:18
Comment on lines +1 to +12
from django import VERSION, get_version
from django_prometheus.info import django_info

def test_info_metric():
major, minor, patch = VERSION[:3]
assert django_info._name == "django"
assert django_info._documentation == "Django version information"
assert django_info._value == {"major": str(major),
"minor": str(minor),
"patchlevel": str(patch),
"version": get_version(),
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asserting on private attributes (_name, _value, …) is brittle. Testing through the public registry would be better. It verifies the metric is actually exported and stays namespace-safe:

Suggested change
from django import VERSION, get_version
from django_prometheus.info import django_info
def test_info_metric():
major, minor, patch = VERSION[:3]
assert django_info._name == "django"
assert django_info._documentation == "Django version information"
assert django_info._value == {"major": str(major),
"minor": str(minor),
"patchlevel": str(patch),
"version": get_version(),
}
from django import VERSION, get_version
from prometheus_client import REGISTRY
from django_prometheus.conf import NAMESPACE
def test_info_metric():
major, minor, patch = VERSION[:3]
name = f"{NAMESPACE}_django_info" if NAMESPACE else "django_info"
labels = {
"major": str(major),
"minor": str(minor),
"patchlevel": str(patch),
"version": get_version(),
}
assert REGISTRY.get_sample_value(name, labels) == 1.0

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.

[Feature Request]: Expose Django Version as metric

5 participants