Add RequestMetricsExporter utility to export request-level metrics (#10973)

This commit is contained in:
Scott Lee
2025-11-12 16:33:37 -08:00
committed by GitHub
parent c4b74c1db2
commit c94564912e
3 changed files with 249 additions and 0 deletions
+27
View File
@@ -321,6 +321,10 @@ class ServerArgs:
enable_trace: bool = False
otlp_traces_endpoint: str = "localhost:4317"
# RequestMetricsExporter configuration
export_metrics_to_file: bool = False
export_metrics_to_file_dir: Optional[str] = None
# API related
api_key: Optional[str] = None
served_model_name: Optional[str] = None
@@ -640,6 +644,9 @@ class ServerArgs:
# Handle deterministic inference.
self._handle_deterministic_inference()
# Handle exporting request-level metrics.
self._handle_request_metrics_exporters()
# Handle any other necessary validations.
self._handle_other_validations()
@@ -1849,6 +1856,13 @@ class ServerArgs:
"NCCL_ALGO is set to 'allreduce:tree' and custom all reduce is disabled for deterministic inference when TP size > 1."
)
def _handle_request_metrics_exporters(self):
"""Handle arguments for configuring `RequestMetricsExporter` usage."""
if self.export_metrics_to_file and self.export_metrics_to_file_dir is None:
raise ValueError(
"--export-metrics-to-file-dir is required when --export-metrics-to-file is enabled"
)
def _handle_other_validations(self):
# Handle model inference tensor dump.
if self.debug_tensor_dump_output_folder is not None:
@@ -2443,6 +2457,19 @@ class ServerArgs:
help="Config opentelemetry collector endpoint if --enable-trace is set. format: <ip>:<port>",
)
# RequestMetricsExporter configuration
parser.add_argument(
"--export-metrics-to-file",
action="store_true",
help="Export performance metrics for each request to local file (e.g. for forwarding to external systems).",
)
parser.add_argument(
"--export-metrics-to-file-dir",
type=str,
default=ServerArgs.export_metrics_to_file_dir,
help="Directory path for writing performance metrics files (required when --export-metrics-to-file is enabled).",
)
# API related
parser.add_argument(
"--api-key",