[feat] Adds Django Version as a Metric - #510
Open
ethanthopkins wants to merge 11 commits into
Open
Conversation
… is static and does not fit with the other custom metrics. This will allow a home for other relevant, static metrics in the future.
OscarVanL
reviewed
Jun 2, 2026
…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.
asherf
reviewed
Jun 3, 2026
Contributor
There was a problem hiding this comment.
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
infomodule fromdjango_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
ethanthopkins
marked this pull request as draft
June 3, 2026 19:06
ethanthopkins
marked this pull request as ready for review
June 3, 2026 19:18
OscarVanL
approved these changes
Jun 4, 2026
mgstabrani
reviewed
Jul 24, 2026
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(), | ||
| } |
Member
There was a problem hiding this comment.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All unit tests pass and Django Version displays on test Django Project.
Closes #503