vector/internal_events/
log_to_metric.rs1use std::num::ParseFloatError;
2
3use vector_lib::{
4 NamedInternalEvent, counter,
5 internal_event::{
6 ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type,
7 },
8};
9
10#[derive(NamedInternalEvent)]
11pub struct LogToMetricFieldNullError<'a> {
12 pub field: &'a str,
13}
14
15impl InternalEvent for LogToMetricFieldNullError<'_> {
16 fn emit(self) {
17 let reason = "Unable to convert null field.";
18 error!(
19 message = reason,
20 error_code = "field_null",
21 error_type = error_type::CONDITION_FAILED,
22 stage = error_stage::PROCESSING,
23 null_field = %self.field
24 );
25 counter!(
26 CounterName::ComponentErrorsTotal,
27 "error_code" => "field_null",
28 "error_type" => error_type::CONDITION_FAILED,
29 "stage" => error_stage::PROCESSING,
30 "null_field" => self.field.to_string(),
31 )
32 .increment(1);
33
34 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
35 }
36}
37
38#[derive(NamedInternalEvent)]
39pub struct LogToMetricParseFloatError<'a> {
40 pub field: &'a str,
41 pub error: ParseFloatError,
42}
43
44impl InternalEvent for LogToMetricParseFloatError<'_> {
45 fn emit(self) {
46 let reason = "Failed to parse field as float.";
47 error!(
48 message = reason,
49 error = ?self.error,
50 field = %self.field,
51 error_code = "failed_parsing_float",
52 error_type = error_type::PARSER_FAILED,
53 stage = error_stage::PROCESSING
54 );
55 counter!(
56 CounterName::ComponentErrorsTotal,
57 "error_code" => "failed_parsing_float",
58 "error_type" => error_type::PARSER_FAILED,
59 "stage" => error_stage::PROCESSING,
60 "field" => self.field.to_string(),
61 )
62 .increment(1);
63
64 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
65 }
66}
67
68#[derive(NamedInternalEvent)]
70pub struct MetricMetadataInvalidFieldValueError<'a> {
71 pub field: &'a str,
72 pub field_value: &'a str,
73}
74
75impl InternalEvent for MetricMetadataInvalidFieldValueError<'_> {
76 fn emit(self) {
77 let reason = "Field contained unsupported value.";
78 error!(
79 message = reason,
80 field = %self.field,
81 field_value = %self.field_value,
82 error_code = "failed_parsing_float",
83 error_type = error_type::PARSER_FAILED,
84 stage = error_stage::PROCESSING
85 );
86 counter!(
87 CounterName::ComponentErrorsTotal,
88 "error_code" => "invalid_field_value",
89 "error_type" => error_type::PARSER_FAILED,
90 "stage" => error_stage::PROCESSING,
91 "field" => self.field.to_string(),
92 )
93 .increment(1);
94
95 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
96 }
97}
98
99#[derive(NamedInternalEvent)]
100pub struct MetricMetadataParseError<'a> {
101 pub field: &'a str,
102 pub kind: &'a str,
103}
104
105impl InternalEvent for MetricMetadataParseError<'_> {
106 fn emit(self) {
107 let reason = "Failed to parse field as float.";
108 error!(
109 message = reason,
110 field = %self.field,
111 error_code = format!("failed_parsing_{}", self.kind),
112 error_type = error_type::PARSER_FAILED,
113 stage = error_stage::PROCESSING
114 );
115 counter!(
116 CounterName::ComponentErrorsTotal,
117 "error_code" => format!("failed_parsing_{}", self.kind),
118 "error_type" => error_type::PARSER_FAILED,
119 "stage" => error_stage::PROCESSING,
120 "field" => self.field.to_string(),
121 )
122 .increment(1);
123
124 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
125 }
126}
127
128#[derive(NamedInternalEvent)]
129pub struct MetricMetadataMetricDetailsNotFoundError {}
130
131impl InternalEvent for MetricMetadataMetricDetailsNotFoundError {
132 fn emit(self) {
133 let reason = "Missing required metric details. Required one of gauge, distribution, aggregated_histogram, aggregated_summary, counter";
134 error!(
135 message = reason,
136 error_code = "missing_metric_details",
137 error_type = error_type::PARSER_FAILED,
138 stage = error_stage::PROCESSING
139 );
140 counter!(
141 CounterName::ComponentErrorsTotal,
142 "error_code" => "missing_metric_details",
143 "error_type" => error_type::PARSER_FAILED,
144 "stage" => error_stage::PROCESSING,
145 )
146 .increment(1);
147
148 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
149 }
150}