vector/internal_events/
metric_to_log.rs

1use metrics::counter;
2use serde_json::Error;
3use vector_lib::internal_event::{
4    ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type,
5};
6
7#[derive(Debug)]
8pub struct MetricToLogSerializeError {
9    pub error: Error,
10}
11
12impl InternalEvent for MetricToLogSerializeError {
13    fn emit(self) {
14        let reason = "Metric failed to serialize as JSON.";
15        error!(
16            message = reason,
17            error = ?self.error,
18            error_type = error_type::ENCODER_FAILED,
19            stage = error_stage::PROCESSING,
20            internal_log_rate_limit = true
21        );
22        counter!(
23            "component_errors_total",
24            "error_type" => error_type::ENCODER_FAILED,
25            "stage" => error_stage::PROCESSING,
26        )
27        .increment(1);
28
29        emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
30    }
31}