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