-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding metric collection as part of instrumentations - Django #1230
Conversation
.../opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
Show resolved
Hide resolved
.../opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
Show resolved
Hide resolved
.../opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at the comments, if you consider the current state of the code to be ok, let me know and I'll approve. 👍
.../opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
Outdated
Show resolved
Hide resolved
def _get_metric_labels_from_attributes(attributes): | ||
labels = {} | ||
labels["http.method"] = attributes.get("http.method", "") | ||
for attrs in _ATTRIBUTES_BY_PREFERENCE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just declare the _ATTRIBUTES_BY_PREFERENCE
here since it is only used once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defined once on module level so it doesn't have to be defined everytime a request is called.
.../opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
Outdated
Show resolved
Hide resolved
.../opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
Outdated
Show resolved
Hide resolved
if all(labels_from_attributes.values()): | ||
labels.update(labels_from_attributes) | ||
break | ||
if attributes.get("http.flavor"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may have the same problem.
if attributes.get("http.flavor"): | |
if attributes.get("http.flavor") is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe we want to set the label if value is an empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevertheless, we may end up setting the label when the value is an empty string here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think http.method
should always be populated. That was just for sanity.
.../opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved since most of my comments have been marked as resolved, only leaving a question for @lzchen just in case.
if all(labels_from_attributes.values()): | ||
labels.update(labels_from_attributes) | ||
break | ||
if attributes.get("http.flavor"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevertheless, we may end up setting the label when the value is an empty string here?
…#1230) Co-authored-by: Mayur Kale <mayurkale@google.com>
Similar to #1116.
Adding the ability to collect duration metrics from
Django
instrumentation.Semantic conventions for metrics can be found here
Currently
django
only supports SERVER type (since we don't have database tracking yet). TheHTTPMetricRecorder
is also being passed viasettings
from theDjangoInstrumentor
to themiddleware
.Also included in this PR:
MetricMixin
in the instrumentation package: Support bothSERVER
andCLIENT
types, add a function to calculate duration without the use of context manager