vector/internal_events/
codecs.rs

1use metrics::counter;
2use vector_lib::internal_event::InternalEvent;
3use vector_lib::internal_event::{error_stage, error_type, ComponentEventsDropped, UNINTENTIONAL};
4
5#[derive(Debug)]
6pub struct DecoderFramingError<E> {
7    pub error: E,
8}
9
10impl<E: std::fmt::Display> InternalEvent for DecoderFramingError<E> {
11    fn emit(self) {
12        error!(
13            message = "Failed framing bytes.",
14            error = %self.error,
15            error_code = "decoder_frame",
16            error_type = error_type::PARSER_FAILED,
17            stage = error_stage::PROCESSING,
18            internal_log_rate_limit = true,
19        );
20        counter!(
21            "component_errors_total",
22            "error_code" => "decoder_frame",
23            "error_type" => error_type::PARSER_FAILED,
24            "stage" => error_stage::PROCESSING,
25        )
26        .increment(1);
27    }
28}
29
30#[derive(Debug)]
31pub struct DecoderDeserializeError<'a> {
32    pub error: &'a crate::Error,
33}
34
35impl InternalEvent for DecoderDeserializeError<'_> {
36    fn emit(self) {
37        error!(
38            message = "Failed deserializing frame.",
39            error = %self.error,
40            error_code = "decoder_deserialize",
41            error_type = error_type::PARSER_FAILED,
42            stage = error_stage::PROCESSING,
43            internal_log_rate_limit = true,
44        );
45        counter!(
46            "component_errors_total",
47            "error_code" => "decoder_deserialize",
48            "error_type" => error_type::PARSER_FAILED,
49            "stage" => error_stage::PROCESSING,
50        )
51        .increment(1);
52    }
53}
54
55#[derive(Debug)]
56pub struct EncoderFramingError<'a> {
57    pub error: &'a vector_lib::codecs::encoding::BoxedFramingError,
58}
59
60impl InternalEvent for EncoderFramingError<'_> {
61    fn emit(self) {
62        let reason = "Failed framing bytes.";
63        error!(
64            message = reason,
65            error = %self.error,
66            error_code = "encoder_frame",
67            error_type = error_type::ENCODER_FAILED,
68            stage = error_stage::SENDING,
69            internal_log_rate_limit = true,
70        );
71        counter!(
72            "component_errors_total",
73            "error_code" => "encoder_frame",
74            "error_type" => error_type::ENCODER_FAILED,
75            "stage" => error_stage::SENDING,
76        )
77        .increment(1);
78        emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
79    }
80}
81
82#[derive(Debug)]
83pub struct EncoderSerializeError<'a> {
84    pub error: &'a crate::Error,
85}
86
87impl InternalEvent for EncoderSerializeError<'_> {
88    fn emit(self) {
89        let reason = "Failed serializing frame.";
90        error!(
91            message = reason,
92            error = %self.error,
93            error_code = "encoder_serialize",
94            error_type = error_type::ENCODER_FAILED,
95            stage = error_stage::SENDING,
96            internal_log_rate_limit = true,
97        );
98        counter!(
99            "component_errors_total",
100            "error_code" => "encoder_serialize",
101            "error_type" => error_type::ENCODER_FAILED,
102            "stage" => error_stage::SENDING,
103        )
104        .increment(1);
105        emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
106    }
107}
108
109#[derive(Debug)]
110pub struct EncoderWriteError<'a, E> {
111    pub error: &'a E,
112    pub count: usize,
113}
114
115impl<E: std::fmt::Display> InternalEvent for EncoderWriteError<'_, E> {
116    fn emit(self) {
117        let reason = "Failed writing bytes.";
118        error!(
119            message = reason,
120            error = %self.error,
121            error_type = error_type::IO_FAILED,
122            stage = error_stage::SENDING,
123            internal_log_rate_limit = true,
124        );
125        counter!(
126            "component_errors_total",
127            "error_type" => error_type::ENCODER_FAILED,
128            "stage" => error_stage::SENDING,
129        )
130        .increment(1);
131        if self.count > 0 {
132            emit!(ComponentEventsDropped::<UNINTENTIONAL> {
133                count: self.count,
134                reason,
135            });
136        }
137    }
138}