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