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

Provide excluded_urls argument to Flask instrumentation #604

Merged
merged 8 commits into from
Jul 29, 2021

Conversation

mattoberle
Copy link
Contributor

Description

Proposal to solve #375 for the FlaskInstrumentor, based on the FastAPIInstrumentor solution in #486.
This PR allows users to pass an explicit excluded_urls argument during instrumentation.
The explicit argument will override values set via environment variable.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A: The test_programmatic module was modified to test both environment-based and explicit exclusions.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • 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

The FastAPI instrumentation accepts an 'explicit_urls' argument on
initialization. This commit translates that concept to the Flask
instrumentation.
@mattoberle mattoberle requested review from a team, owais and lzchen and removed request for a team July 22, 2021 17:29
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 22, 2021

CLA Signed

The committers are authorized under a signed CLA.

CHANGELOG.md Outdated Show resolved Hide resolved
mattoberle and others added 2 commits July 23, 2021 16:11
Co-authored-by: Leighton Chen <lechen@microsoft.com>
@@ -209,6 +217,10 @@ def __init__(self, *args, **kwargs):
)
self._before_request = _before_request
self.before_request(_before_request)
Copy link
Contributor

@lzchen lzchen Jul 26, 2021

Choose a reason for hiding this comment

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

Does _before_request and _rewrapped_app need the excluded_urls passed in as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.
I need to extend test_automatic.py to cover this case and then I'll push up the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitHub didn't update the comment since the change is a few lines up, but this should be taken care of now on line 220 in this commit:

5996b7e

parse_excluded_urls(excluded_urls)
if excluded_urls is not None
else _excluded_urls_from_env
)
app._original_wsgi_app = app.wsgi_app
app.wsgi_app = _rewrapped_app(app.wsgi_app, response_hook)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
app.wsgi_app = _rewrapped_app(app.wsgi_app, response_hook)
app.wsgi_app = _rewrapped_app(app.wsgi_app, response_hook, excluded_urls)

mattoberle and others added 3 commits July 26, 2021 14:14
The Flask instrumentation can be applied on two levels:

* The `module` level (auto-instrumentation), which patches the `Flask` class.
* The `app` level, which patches a `Flask` instance.

This commit applies a few missing `excluded_urls` keyword arguments to
ensure the auto-instrumentation provides the same configurability as the
app-level instrumentation.
@lzchen lzchen merged commit 14b0a3f into open-telemetry:main Jul 29, 2021
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