bentoml / BentoML

The easiest way to serve AI apps and models - Build reliable Inference APIs, LLM apps, Multi-model chains, RAG service, and much more!
https://bentoml.com
Apache License 2.0
7.03k stars 781 forks source link

bug: Traces are not fully suppressed when using a runner with excluded_urls #4309

Open vivienrobert-wefox opened 10 months ago

vivienrobert-wefox commented 10 months ago

Describe the bug

When using a runner in a service, the service outputs opentelemetry traces even for requests to urls included in excluded_urls in the config. This is most notably problematic for readyz,livez and healthz.

To reproduce

  1. Launch the jaeger all in one docker image as per https://docs.bentoml.com/en/latest/guides/tracing.html#running-a-bentoservice
  2. Make the following files: service.py:

class CustomRunnable(bentoml.Runnable): SUPPORTED_RESOURCES = ("cpu",) SUPPORTS_CPU_MULTI_THREADING = False

@bentoml.Runnable.method(batchable=False)
def my_runner_call(self, x: str):
    return x

runner = bentoml.Runner(CustomRunnable, name="custom_runnable") svc = bentoml.Service(name="service", runners=[runner])

@svc.api(input=bentoml.io.Text(), output=bentoml.io.Text()) def my_svc_call(x: str): return runner.my_runner_call.run(x)


bento_configuration.yaml:

tracing: exporter_type: otlp sample_rate: 1.0 excluded_urls: ["/healthz", "/livez","/readyz"] otlp: protocol: http endpoint: http://localhost:4318/v1/traces


3. run `BENTOML_CONFIG=bento_configuration.yaml bentoml serve service.py`
4. run `curl http://localhost:3000/readyz` 

5. Check jaeger's interface for traces, there should not be any but there will be one.

### Expected behavior

No traces should be outputted when receiving a request on an `excluded_url`.

### Environment

#### Environment variable

```bash
BENTOML_DEBUG=''
BENTOML_QUIET=''
BENTOML_BUNDLE_LOCAL_BUILD=''
BENTOML_DO_NOT_TRACK=''
BENTOML_CONFIG=''
BENTOML_CONFIG_OPTIONS=''
BENTOML_PORT=''
BENTOML_HOST=''
BENTOML_API_WORKERS=''

System information

bentoml: 1.1.10 python: 3.9.17 platform: macOS-12.7.1-x86_64-i386-64bit uid_gid: 498497983:961394333

pip_packages
``` aiohttp==3.9.1 aiosignal==1.3.1 anyio==4.1.0 appdirs==1.4.4 asgiref==3.7.2 async-timeout==4.0.3 attrs==23.1.0 backoff==2.2.1 bentoml==1.1.10 build==1.0.3 cattrs==23.1.2 certifi==2023.11.17 charset-normalizer==3.3.2 circus==0.18.0 click==8.1.7 click-option-group==0.5.6 cloudpickle==3.0.0 contextlib2==21.6.0 deepmerge==1.1.0 Deprecated==1.2.14 exceptiongroup==1.2.0 frozenlist==1.4.0 fs==2.4.16 googleapis-common-protos==1.61.0 grpcio==1.59.3 h11==0.14.0 httpcore==1.0.2 httpx==0.25.2 idna==3.6 importlib-metadata==6.8.0 inflection==0.5.1 Jinja2==3.1.2 markdown-it-py==3.0.0 MarkupSafe==2.1.3 mdurl==0.1.2 multidict==6.0.4 numpy==1.26.2 nvidia-ml-py==11.525.150 opentelemetry-api==1.20.0 opentelemetry-exporter-otlp==1.20.0 opentelemetry-exporter-otlp-proto-common==1.20.0 opentelemetry-exporter-otlp-proto-grpc==1.20.0 opentelemetry-exporter-otlp-proto-http==1.20.0 opentelemetry-instrumentation==0.41b0 opentelemetry-instrumentation-aiohttp-client==0.41b0 opentelemetry-instrumentation-asgi==0.41b0 opentelemetry-proto==1.20.0 opentelemetry-sdk==1.20.0 opentelemetry-semantic-conventions==0.41b0 opentelemetry-util-http==0.41b0 packaging==23.2 pathspec==0.11.2 pip-requirements-parser==32.0.1 pip-tools==7.3.0 prometheus-client==0.19.0 protobuf==4.25.1 psutil==5.9.6 Pygments==2.17.2 pyparsing==3.1.1 pyproject_hooks==1.0.0 python-dateutil==2.8.2 python-json-logger==2.0.7 python-multipart==0.0.6 PyYAML==6.0.1 pyzmq==25.1.1 requests==2.31.0 rich==13.7.0 schema==0.7.5 simple-di==0.1.5 six==1.16.0 sniffio==1.3.0 starlette==0.32.0.post1 tomli==2.0.1 tornado==6.4 typing_extensions==4.8.0 urllib3==2.1.0 uvicorn==0.24.0.post1 watchfiles==0.21.0 wrapt==1.16.0 yarl==1.9.3 zipp==3.17.0 ```
vivienrobert-wefox commented 10 months ago

Extra info: When not using the excluded_urls option, many more spans appear in the trace, most of them instrumented by opentelemetry.instrumentation.asgi, these ones are indeed suppressed when the option is on. The ones that are left are instead instrumented by opentelemetry.instrumentation.aiohttp_client .