vector/internal_events/
sematext_metrics.rs

1use metrics::counter;
2use vector_lib::internal_event::{
3    ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type,
4};
5
6use crate::event::metric::Metric;
7
8#[derive(Debug)]
9pub struct SematextMetricsInvalidMetricError<'a> {
10    pub metric: &'a Metric,
11}
12
13impl InternalEvent for SematextMetricsInvalidMetricError<'_> {
14    fn emit(self) {
15        let reason = "Invalid metric received.";
16        error!(
17            message = reason,
18            error_code = "invalid_metric",
19            error_type =  error_type::ENCODER_FAILED,
20            stage = error_stage::PROCESSING,
21            value = ?self.metric.value(),
22            kind = ?self.metric.kind(),
23            internal_log_rate_limit = true,
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)]
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            internal_log_rate_limit = true,
51        );
52        counter!(
53            "component_errors_total",
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}