-
Notifications
You must be signed in to change notification settings - Fork 621
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
Enable passing explicit urls to exclude in instrumentation in FastAPI #486
Conversation
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.
Suggest to rename the global _excluded_urls
to _excluded_urls_from_env
. It'd make the logic below a lot more readable.
… instrumentation to make implementation more readable
@@ -47,6 +53,7 @@ def instrument_app(app: fastapi.FastAPI, tracer_provider=None): | |||
def _instrument(self, **kwargs): | |||
self._original_fastapi = fastapi.FastAPI | |||
_InstrumentedFastAPI._tracer_provider = kwargs.get("tracer_provider") | |||
_InstrumentedFastAPI._excluded_urls = kwargs.get("excluded_urls") |
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.
Since _INstrumentedFastAPI is private and not supposed to be used directly, can we move env vs kwargs logic here instead?
|
||
.. code-block:: python | ||
from opentelemetry.util.http import ExcludeList | ||
FastAPIInstrumentor.instrument_app(app, ExcludeList("client/.*/info,healthcheck")) |
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.
Why not allow users to pass in a sequence of strings instead? Basically what can be passed into the env var should be replicated 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.
No real reason, I can change it to work that way.
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 it is preferred. Also users don't have to import ExcludeList
either.
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.
Done
@cdvv7788 |
@lzchen I created a new issue to track this in a more general way: #490 I updated the PR with the recommendations. I still have an issue: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/486/checks?check_run_id=2502217693 |
@owais |
_excluded_urls_from_env = get_excluded_urls("FASTAPI") | ||
|
||
|
||
def parse_urls(urls_str): |
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.
Private method
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 will move it here: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.py#L55
This will be needed for other instrumentations
instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py
Outdated
Show resolved
Hide resolved
instrumentation/opentelemetry-instrumentation-fastapi/README.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
util/opentelemetry-util-http/src/opentelemetry/util/http/__init__.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.
The PR looks good, if you could take a look at fixing the tests, would be happy to merge this as soon as that's done. Thanks for the contribution!
_InstrumentedFastAPI._excluded_urls = ( | ||
_excluded_urls_from_env | ||
if _excluded_urls is None | ||
else parse_urls(_excluded_urls) |
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.
Should this be parse_excluded_urls
?
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.
Yes, it should. My bad.
The linter should be passing now.
Description
Proposal to solve #375
Currently, only environment variables are supported to exclude URLs. With this change, the users can pass a list explicitly during the instrumentation, so other sources can be easily plugged in (hardcoded, config files, settings, etc).
Type of change
Please delete options that are not relevant.
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
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.