instrument_metric_view (instrument v1.0.0)
View SourceOpenTelemetry Metric Views for transformation and filtering.
Metric views allow customizing how metrics are exported by: - Renaming metrics - Changing descriptions - Filtering attributes - Changing aggregation type - Setting histogram bucket boundaries
Example Usage
%% Create a view that renames a metric
instrument_metric_view:register(#metric_view{
instrument_name = <<"http_requests">>,
name = <<"http.requests.total">>
}).
%% Create a view that filters attributes
instrument_metric_view:register(#metric_view{
instrument_name = <<"request_latency">>,
attribute_keys = [<<"method">>, <<"status">>]
}).
%% Apply views to metrics
TransformedMetrics = instrument_metric_view:apply_views(Metrics).
Summary
Functions
Applies all registered views to a list of metrics. Returns transformed metrics.
Clears all registered views.
Lists all registered views.
Checks if a view matches a metric.
Registers a metric view.
Unregisters a metric view by instrument name pattern.
Functions
Applies all registered views to a list of metrics. Returns transformed metrics.
-spec clear() -> ok.
Clears all registered views.
-spec list() -> [#metric_view{name :: binary() | undefined, description :: binary() | undefined, instrument_name :: binary() | '_', instrument_type :: atom() | '_', meter_name :: binary() | '_', attribute_keys :: [binary()] | undefined, aggregation :: atom() | undefined, boundaries :: [number()] | undefined}].
Lists all registered views.
-spec match_metric(#metric_view{name :: binary() | undefined, description :: binary() | undefined, instrument_name :: binary() | '_', instrument_type :: atom() | '_', meter_name :: binary() | '_', attribute_keys :: [binary()] | undefined, aggregation :: atom() | undefined, boundaries :: [number()] | undefined}, map()) -> boolean().
Checks if a view matches a metric.
-spec register(#metric_view{name :: binary() | undefined, description :: binary() | undefined, instrument_name :: binary() | '_', instrument_type :: atom() | '_', meter_name :: binary() | '_', attribute_keys :: [binary()] | undefined, aggregation :: atom() | undefined, boundaries :: [number()] | undefined}) -> ok.
Registers a metric view.
-spec unregister(binary() | '_') -> ok.
Unregisters a metric view by instrument name pattern.