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

Enable passing explicit urls to exclude in instrumentation in FastAPI #486

Merged
merged 19 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f728abb
feat: Enable passing explicit urls to exclude from instrumentation in…
cdvv7788 May 2, 2021
8c4eee0
docs: Update changelog (fastapi #486)
cdvv7788 May 2, 2021
17a0269
refactor: Rename _excluded_urls to _excluded_urls_from_env in fastapi…
cdvv7788 May 2, 2021
f047153
refactor: Move excluded urls logic to the _instrument function
cdvv7788 May 2, 2021
58c20cc
Merge branch 'main' into fastapi-excluded_urls
lzchen May 4, 2021
b81dbf5
refactor: Use ExcludeList only internally in the instrumentation(fast…
cdvv7788 May 9, 2021
eea46e4
Merge branch 'main' into fastapi-excluded_urls
cdvv7788 May 9, 2021
4ce59f2
Merge branch 'main' into fastapi-excluded_urls
lzchen May 11, 2021
178643d
Merge branch 'main' into fastapi-excluded_urls
lzchen May 12, 2021
314d329
Merge branch 'main' into fastapi-excluded_urls
ocelotl May 26, 2021
a335531
refactor: Move utils method into http-utils package
cdvv7788 May 30, 2021
34fa727
test: Remove unneeded variable in explicit excluded_urls test
cdvv7788 May 30, 2021
b659f08
fix: Resolve docs generation issue
cdvv7788 May 30, 2021
180031e
fix: Remove unneeded import
cdvv7788 May 31, 2021
7bce354
Merge branch 'main' into fastapi-excluded_urls
cdvv7788 Jun 2, 2021
59a504c
Merge branch 'main' into fastapi-excluded_urls
Jun 3, 2021
02fa810
fix: wrong variable name in fastapi instrumentation
cdvv7788 Jun 13, 2021
b495dfe
Merge branch 'main' into fastapi-excluded_urls
lzchen Jun 14, 2021
fbaa815
Merge branch 'main' into fastapi-excluded_urls
ocelotl Jun 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.util.http import get_excluded_urls, ExcludeList
from opentelemetry.util.http import get_excluded_urls, parse_excluded_urls

_excluded_urls_from_env = get_excluded_urls("FASTAPI")


def parse_urls(urls_str):
"""
Small helper to put the urls inside of ExcludeList
"""
return ExcludeList(url.strip() for url in urls_str.split(","))


class FastAPIInstrumentor(BaseInstrumentor):
"""An instrumentor for FastAPI

Expand All @@ -47,7 +40,7 @@ def instrument_app(
if excluded_urls is None:
excluded_urls = _excluded_urls_from_env
else:
excluded_urls = parse_urls(excluded_urls)
excluded_urls = parse_excluded_urls(excluded_urls)

app.add_middleware(
OpenTelemetryMiddleware,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from os import environ
from re import compile as re_compile
from re import I, compile as re_compile
from re import search


Expand Down Expand Up @@ -51,6 +51,13 @@ def get_excluded_urls(instrumentation):
_root.format("{}_EXCLUDED_URLS".format(instrumentation)), []
)

return parse_excluded_urls(excluded_urls)


def parse_excluded_urls(excluded_urls):
"""
Small helper to put an arbitrary url list inside of ExcludeList
"""
if excluded_urls:
excluded_urls = [
excluded_url.strip() for excluded_url in excluded_urls.split(",")
Expand Down