Skip to content
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

Restoring metrics in requests #1110

Merged
merged 23 commits into from
Jun 25, 2022

Conversation

ashu658
Copy link
Member

@ashu658 ashu658 commented May 31, 2022

Description

Restoring production of metrics for requests library.

Fixes #1039

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Tested by sending metrics to collector and added unit test.

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

@ashu658 ashu658 requested a review from a team as a code owner May 31, 2022 11:47
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 31, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ashu658 / name: Ashutosh Goel (784bb02)

@ashu658 ashu658 changed the title Restoring metrics in requests [WIP] Restoring metrics in requests May 31, 2022
@ashu658 ashu658 marked this pull request as draft May 31, 2022 13:03
@ashu658 ashu658 marked this pull request as ready for review June 6, 2022 07:11
@ashu658 ashu658 changed the title [WIP] Restoring metrics in requests Restoring metrics in requests Jun 6, 2022
CHANGELOG.md Outdated Show resolved Hide resolved
@@ -167,6 +175,18 @@ def _instrumented_requests_call(
SpanAttributes.HTTP_URL: url,
}

metric_labels = {
"http.method": method,
"http.url": url,
Copy link
Member

Choose a reason for hiding this comment

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

Is this url parametrized or plain raw url? Otherwise, this can lead very to high cardinality.

Copy link
Member Author

@ashu658 ashu658 Jun 14, 2022

Choose a reason for hiding this comment

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

This is the same url we add in span attributes. I think its not parameterised. (i.e. when added in metric it would look something like this http.url: STRING(https://www.example.com/123/?key1=value1)
I cannot think of a way to find encoded parameters from url to remove them. (e.g. in the above example remove 123 from path).
Open for suggestions :)

Copy link
Member

Choose a reason for hiding this comment

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

That's not a problem with tracing but here each url creates a new time series which should be avoided. If there is no way to get the parametrized url I would suggest remove this tag entirely.

Copy link
Member Author

@ashu658 ashu658 Jun 21, 2022

Choose a reason for hiding this comment

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

Removed url tag. But there could be 2 different urls in a single time series (as there might be no differentiating tag). I am not sure if this is okay. Any suggestions?

}

try:
parsed_url = urlparse(url)
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine that the call to urlparse is what can cause the ValueError exception to be raised. If that happens, does it make sense to continue the instrumentation with a metrics_labels dictionary that will not have "http.host" and "http.scheme" keys?

Copy link
Member Author

@ashu658 ashu658 Jun 14, 2022

Choose a reason for hiding this comment

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

In traces we add the url even if the url is invalid (e.g. url = random123 is also added as span attribute). So, I added it here for consistency.
I think its okay to go without http.host and http.scheme keys as http.url attribute alone is one of the recommended set of attributes for client metrics (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attribute-alternatives)

"http.host": "httpbin.org",
"http.method": "GET",
"http.flavor": "1.1",
"http.scheme": "http",
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we missing a few? net.*, http.target?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added net.* attributes.
I have not added http.target as the target is not parameterised and adding raw target can lead to high cardinality.
Its similar for http.url as discussed here

ashu658 and others added 6 commits June 23, 2022 00:17
…est_requests_integration.py

Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
1) Using default_timer
2) Refactoring varibale names
3) Removing metric usage docstring
@ashu658 ashu658 self-assigned this Jun 23, 2022
@srikanthccv
Copy link
Member

@ashu658 add _supports_metrics = True for requests similiar to this.

Copy link
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks.

@srikanthccv srikanthccv merged commit f7fd1e0 into open-telemetry:main Jun 25, 2022
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.

[instrumentation-requests] Restore metrics
4 participants