From 8f682bf9565d30c637aea5cf3926da2420644d9d Mon Sep 17 00:00:00 2001 From: Jiew Peng Lim Date: Wed, 3 Aug 2022 13:18:40 +0800 Subject: [PATCH] feat: add support for specifying urls to exclude from tracing as a list (#2851) Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- bentoml/_internal/configuration/containers.py | 12 +++++++++--- docs/source/guides/tracing.rst | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bentoml/_internal/configuration/containers.py b/bentoml/_internal/configuration/containers.py index 092861db7c2..8afd1a2e593 100644 --- a/bentoml/_internal/configuration/containers.py +++ b/bentoml/_internal/configuration/containers.py @@ -120,7 +120,7 @@ def _is_ip_address(addr: str) -> bool: "tracing": { "type": Or(And(str, Use(str.lower), _check_tracing_type), None), "sample_rate": Or(And(float, lambda i: i >= 0 and i <= 1), None), - "excluded_urls": Or(str, None), + "excluded_urls": Or([str], str, None), Optional("zipkin"): {"url": Or(str, None)}, Optional("jaeger"): {"address": Or(str, None), "port": Or(int, None)}, }, @@ -417,11 +417,17 @@ def tracer_provider( @providers.SingletonFactory @staticmethod def tracing_excluded_urls( - excluded_urls: t.Optional[str] = Provide[config.tracing.excluded_urls], + excluded_urls: t.Optional[t.Union[str, t.List[str]]] = Provide[ + config.tracing.excluded_urls + ], ): + from opentelemetry.util.http import ExcludeList from opentelemetry.util.http import parse_excluded_urls - return parse_excluded_urls(excluded_urls) + if isinstance(excluded_urls, list): + return ExcludeList(excluded_urls) + else: + return parse_excluded_urls(excluded_urls) # Mapping from runner name to RunnerApp file descriptor remote_runner_mapping = providers.Static[t.Dict[str, str]]({}) diff --git a/docs/source/guides/tracing.rst b/docs/source/guides/tracing.rst index 7cf29cd1439..bd89a82fb85 100644 --- a/docs/source/guides/tracing.rst +++ b/docs/source/guides/tracing.rst @@ -39,6 +39,19 @@ Here is another example config file for tracing with Jaeger and opentracing: address: localhost port: 6831 +If you would like to exclude some routes from tracing, you can specify them using +the :code:`excluded_urls` parameter. This parameter can be either a comma-separated +string of routes, or a list of strings. + +.. code-block:: yaml + + tracing: + type: jaeger + jaeger: + address: localhost + port: 6831 + excluded_urls: readyz,livez,healthz,static_content,docs,metrics + When starting a BentoML API model server, provide the path to this config file via the CLI argument `--config`: