Metrics#
ragbits.core.audit.metrics.set_metric_handlers
#
Set the global metric handlers.
PARAMETER | DESCRIPTION |
---|---|
handlers |
List of metric handlers to be used.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If handler is not found. |
TypeError
|
If handler type is invalid. |
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/__init__.py
ragbits.core.audit.metrics.clear_metric_handlers
#
ragbits.core.audit.metrics.register_metric
#
register_metric(key: str | Enum, metric: Metric) -> None
Register a new metric in the global registry by type.
PARAMETER | DESCRIPTION |
---|---|
key |
The metric key (enum value or string)
TYPE:
|
metric |
The metric configuration
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/base.py
ragbits.core.audit.metrics.record_metric
#
record_metric(metric: str | Enum, value: int | float, metric_type: MetricType, **attributes: Any) -> None
Record a metric of any type using the global metric handlers.
PARAMETER | DESCRIPTION |
---|---|
metric |
The metric key (name or enum value) to record
TYPE:
|
value |
The value to record
TYPE:
|
metric_type |
The type of metric (histogram, counter, gauge)
TYPE:
|
**attributes |
Additional metadata for the metric
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/__init__.py
ragbits.core.audit.metrics.base.MetricType
#
ragbits.core.audit.metrics.base.Metric
dataclass
#
Metric(name: str, description: str, unit: str, type: MetricType)
Represents the metric configuration data.
ragbits.core.audit.metrics.base.LLMMetric
#
Bases: Enum
LLM-related metrics that can be recorded. Each metric has a predefined type and is registered in the global registry.
ragbits.core.audit.metrics.base.MetricHandler
#
Bases: ABC
Base class for all metric handlers.
Initialize the MetricHandler instance.
PARAMETER | DESCRIPTION |
---|---|
metric_prefix |
Prefix for all metric names.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/base.py
create_metric
abstractmethod
#
create_metric(name: str, unit: str = '', description: str = '', metric_type: MetricType = MetricType.HISTOGRAM) -> Any
Create a metric of the given type.
PARAMETER | DESCRIPTION |
---|---|
name |
The metric name.
TYPE:
|
unit |
The metric unit.
TYPE:
|
description |
The metric description.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The initialized metric. |
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/base.py
register_metric_instance
#
register_metric_instance(name: str, unit: str = '', description: str = '', metric_type: MetricType = MetricType.HISTOGRAM) -> None
Register a metric instance.
PARAMETER | DESCRIPTION |
---|---|
name |
The metric name.
TYPE:
|
unit |
The metric unit.
TYPE:
|
description |
The metric description.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/base.py
record_metric
#
record_metric(metric_key: str | Enum, value: int | float, attributes: dict | None = None, metric_type: MetricType = MetricType.HISTOGRAM) -> None
Record the value for a specified metric.
PARAMETER | DESCRIPTION |
---|---|
metric_key |
The metric key (name or enum value) to record.
TYPE:
|
value |
The value to record for the metric.
TYPE:
|
attributes |
Additional metadata for the metric.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/base.py
ragbits.core.audit.metrics.otel.OtelMetricHandler
#
Bases: MetricHandler
OpenTelemetry metric handler.
Initialize the OtelMetricHandler instance.
PARAMETER | DESCRIPTION |
---|---|
provider |
The meter provider to use.
TYPE:
|
metric_prefix |
Prefix for all metric names.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/otel.py
register_metric_instance
#
register_metric_instance(name: str, unit: str = '', description: str = '', metric_type: MetricType = MetricType.HISTOGRAM) -> None
Register a metric instance.
PARAMETER | DESCRIPTION |
---|---|
name |
The metric name.
TYPE:
|
unit |
The metric unit.
TYPE:
|
description |
The metric description.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/base.py
record_metric
#
record_metric(metric_key: str | Enum, value: int | float, attributes: dict | None = None, metric_type: MetricType = MetricType.HISTOGRAM) -> None
Record the value for a specified metric.
PARAMETER | DESCRIPTION |
---|---|
metric_key |
The metric key (name or enum value) to record.
TYPE:
|
value |
The value to record for the metric.
TYPE:
|
attributes |
Additional metadata for the metric.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/base.py
create_metric
#
create_metric(name: str, unit: str = '', description: str = '', metric_type: MetricType = MetricType.HISTOGRAM) -> Any
Create a metric of the specified type.
PARAMETER | DESCRIPTION |
---|---|
name |
The metric name.
TYPE:
|
unit |
The metric unit.
TYPE:
|
description |
The metric description.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The initialized metric. |
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/otel.py
ragbits.core.audit.metrics.logfire.LogfireMetricHandler
#
Bases: OtelMetricHandler
Logfire metric handler.
Initialize the LogfireMetricHandler instance.
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/logfire.py
create_metric
#
create_metric(name: str, unit: str = '', description: str = '', metric_type: MetricType = MetricType.HISTOGRAM) -> Any
Create a metric of the specified type.
PARAMETER | DESCRIPTION |
---|---|
name |
The metric name.
TYPE:
|
unit |
The metric unit.
TYPE:
|
description |
The metric description.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Any
|
The initialized metric. |
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/otel.py
register_metric_instance
#
register_metric_instance(name: str, unit: str = '', description: str = '', metric_type: MetricType = MetricType.HISTOGRAM) -> None
Register a metric instance.
PARAMETER | DESCRIPTION |
---|---|
name |
The metric name.
TYPE:
|
unit |
The metric unit.
TYPE:
|
description |
The metric description.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/audit/metrics/base.py
record_metric
#
record_metric(metric_key: str | Enum, value: int | float, attributes: dict | None = None, metric_type: MetricType = MetricType.HISTOGRAM) -> None
Record the value for a specified metric.
PARAMETER | DESCRIPTION |
---|---|
metric_key |
The metric key (name or enum value) to record.
TYPE:
|
value |
The value to record for the metric.
TYPE:
|
attributes |
Additional metadata for the metric.
TYPE:
|
metric_type |
The type of the metric (histogram, counter, gauge).
TYPE:
|