jason810496 commented on code in PR #64523:
URL: https://github.com/apache/airflow/pull/64523#discussion_r3105355160


##########
airflow-core/src/airflow/api_fastapi/core_api/app.py:
##########
@@ -167,17 +166,21 @@ def init_error_handlers(app: FastAPI) -> None:
 def init_middlewares(app: FastAPI) -> None:
     from airflow.api_fastapi.auth.middlewares.refresh_token import 
JWTRefreshMiddleware
     from airflow.api_fastapi.common.http_access_log import 
HttpAccessLogMiddleware
+    from airflow.api_fastapi.common.http_metrics import HttpMetricsMiddleware
 
     app.add_middleware(JWTRefreshMiddleware)
     if conf.getboolean("core", "simple_auth_manager_all_admins"):
         from airflow.api_fastapi.auth.managers.simple.middleware import 
SimpleAllAdminMiddleware
 
         app.add_middleware(SimpleAllAdminMiddleware)
 
-    # GZipMiddleware must be inside HttpAccessLogMiddleware so that access 
logs capture
-    # the full end-to-end duration including compression time.
+    # GZipMiddleware must be inside both observability middlewares so they 
capture
+    # the full end-to-end request duration including compression time.
     # See https://github.com/apache/airflow/issues/60165
     app.add_middleware(GZipMiddleware, minimum_size=1024, compresslevel=5)
-    # HttpAccessLogMiddleware must be outermost (added last) so it times the 
full
-    # request lifecycle including all inner middleware.
+    # HttpMetricsMiddleware must wrap GZip and the inner application so emitted
+    # latency metrics include the full request lifecycle.
+    app.add_middleware(HttpMetricsMiddleware)

Review Comment:
   Would it be better to not register `HttpMetricsMiddleware` if 
`get_stats_factory` return `NoStatsLogger to avoid the overhead of emitting 
metrics that actually nop?
   
   As user might setup other o11y tooling at infra level instead of coupling 
with Airflow API server itself.
   
   
https://github.com/apache/airflow/blob/0d294caab3d494eeff6184b09e8e2dda6ffc47ed/airflow-core/src/airflow/observability/metrics/stats_utils.py#L25-L40



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to