vector/internal_events/
sematext_metrics.rs1use vector_lib::{
2 NamedInternalEvent, counter,
3 internal_event::{
4 ComponentEventsDropped, CounterName, InternalEvent, UNINTENTIONAL, error_stage, error_type,
5 },
6};
7
8use crate::event::metric::Metric;
9
10#[derive(Debug, NamedInternalEvent)]
11pub struct SematextMetricsInvalidMetricError<'a> {
12 pub metric: &'a Metric,
13}
14
15impl InternalEvent for SematextMetricsInvalidMetricError<'_> {
16 fn emit(self) {
17 let reason = "Invalid metric received.";
18 error!(
19 message = reason,
20 error_code = "invalid_metric",
21 error_type = error_type::ENCODER_FAILED,
22 stage = error_stage::PROCESSING,
23 value = ?self.metric.value(),
24 kind = ?self.metric.kind(),
25 );
26 counter!(
27 CounterName::ComponentErrorsTotal,
28 "error_code" => "invalid_metric",
29 "error_type" => error_type::ENCODER_FAILED,
30 "stage" => error_stage::PROCESSING,
31 )
32 .increment(1);
33
34 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
35 }
36}
37
38#[derive(Debug, NamedInternalEvent)]
39pub struct SematextMetricsEncodeEventError<E> {
40 pub error: E,
41}
42
43impl<E: std::fmt::Display> InternalEvent for SematextMetricsEncodeEventError<E> {
44 fn emit(self) {
45 let reason = "Failed to encode event.";
46 error!(
47 message = reason,
48 error = %self.error,
49 error_type = error_type::ENCODER_FAILED,
50 stage = error_stage::PROCESSING,
51 );
52 counter!(
53 CounterName::ComponentErrorsTotal,
54 "error_type" => error_type::ENCODER_FAILED,
55 "stage" => error_stage::PROCESSING,
56 )
57 .increment(1);
58
59 emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason });
60 }
61}