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

fix: metrics did not include 4xx #4756

Merged
merged 2 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
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
25 changes: 13 additions & 12 deletions src/_bentoml_impl/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,19 @@ def middlewares(self) -> list[Middleware]:

from bentoml._internal.container import BentoMLContainer

middlewares = super().middlewares + [
Middleware(ContextMiddleware, context=self.service.context)
]
middlewares: list[Middleware] = []
# TrafficMetrics middleware should be the first middleware
if self.enable_metrics:
from bentoml._internal.server.http.instruments import (
RunnerTrafficMetricsMiddleware,
)

middlewares.append(
Middleware(RunnerTrafficMetricsMiddleware, namespace="bentoml_service")
)

middlewares.extend(super().middlewares)
middlewares.append(Middleware(ContextMiddleware, context=self.service.context))

for middleware_cls, options in self.service.middlewares:
middlewares.append(Middleware(middleware_cls, **options))
Expand Down Expand Up @@ -238,15 +248,6 @@ def server_request_hook(span: Span | None, _scope: dict[str, t.Any]) -> None:
)
)

if self.enable_metrics:
from bentoml._internal.server.http.instruments import (
RunnerTrafficMetricsMiddleware,
)

middlewares.append(
Middleware(RunnerTrafficMetricsMiddleware, namespace="bentoml_service")
)

access_log_config = BentoMLContainer.api_server_config.logging.access
if access_log_config.enabled.get():
from bentoml._internal.server.http.access import AccessLogMiddleware
Expand Down
Loading