3232 ENV_SERVER ,
3333 ENV_SERVER_URL ,
3434)
35- from dreadnode .metric import Metric , Scorer , ScorerCallable , T
35+ from dreadnode .metric import Metric , MetricMode , Scorer , ScorerCallable , T
3636from dreadnode .task import P , R , Task
3737from dreadnode .tracing .exporters import (
3838 FileExportConfig ,
@@ -757,6 +757,7 @@ def log_metric(
757757 step : int = 0 ,
758758 origin : t .Any | None = None ,
759759 timestamp : datetime | None = None ,
760+ mode : MetricMode = "direct" ,
760761 to : ToObject = "task-or-run" ,
761762 ) -> None :
762763 """
@@ -778,6 +779,14 @@ def log_metric(
778779 origin: The origin of the metric - can be provided any object which was logged
779780 as an input or output anywhere in the run.
780781 timestamp: The timestamp of the metric - defaults to the current time.
782+ mode: The aggregation mode to use for the metric. Helpful when you want to let
783+ the library take care of translating your raw values into better representations.
784+ - direct: do not modify the value at all (default)
785+ - min: the lowest observed value reported for this metric
786+ - max: the highest observed value reported for this metric
787+ - avg: the average of all reported values for this metric
788+ - sum: the cumulative sum of all reported values for this metric
789+ - count: increment every time this metric is logged - disregard value
781790 to: The target object to log the metric to. Can be "task-or-run" or "run".
782791 Defaults to "task-or-run". If "task-or-run", the metric will be logged
783792 to the current task or run, whichever is the nearest ancestor.
@@ -790,6 +799,7 @@ def log_metric(
790799 value : Metric ,
791800 * ,
792801 origin : t .Any | None = None ,
802+ mode : MetricMode = "direct" ,
793803 to : ToObject = "task-or-run" ,
794804 ) -> None :
795805 """
@@ -809,11 +819,18 @@ def log_metric(
809819 value: The metric object.
810820 origin: The origin of the metric - can be provided any object which was logged
811821 as an input or output anywhere in the run.
822+ mode: The aggregation mode to use for the metric. Helpful when you want to let
823+ the library take care of translating your raw values into better representations.
824+ - direct: do not modify the value at all (default)
825+ - min: always report the lowest ovbserved value for this metric
826+ - max: always report the highest observed value for this metric
827+ - avg: report the average of all values for this metric
828+ - sum: report a rolling sum of all values for this metric
829+ - count: report the number of times this metric has been logged
812830 to: The target object to log the metric to. Can be "task-or-run" or "run".
813831 Defaults to "task-or-run". If "task-or-run", the metric will be logged
814832 to the current task or run, whichever is the nearest ancestor.
815833 """
816- ... # noqa: PIE790
817834
818835 @handle_internal_errors ()
819836 def log_metric (
@@ -824,6 +841,7 @@ def log_metric(
824841 step : int = 0 ,
825842 origin : t .Any | None = None ,
826843 timestamp : datetime | None = None ,
844+ mode : MetricMode = "direct" ,
827845 to : ToObject = "task-or-run" ,
828846 ) -> None :
829847 task = current_task_span .get ()
@@ -838,7 +856,7 @@ def log_metric(
838856 if isinstance (value , Metric )
839857 else Metric (float (value ), step , timestamp or datetime .now (timezone .utc ))
840858 )
841- target .log_metric (key , metric , origin = origin )
859+ target .log_metric (key , metric , origin = origin , mode = mode )
842860
843861 @handle_internal_errors ()
844862 def log_artifact (
0 commit comments