vector/internal_events/
datadog_traces.rs

1use metrics::counter;
2use vector_lib::NamedInternalEvent;
3use vector_lib::internal_event::{
4    ComponentEventsDropped, InternalEvent, UNINTENTIONAL, error_stage, error_type,
5};
6
7#[derive(Debug, NamedInternalEvent)]
8pub struct DatadogTracesEncodingError {
9    pub error_message: &'static str,
10    pub error_reason: String,
11    pub dropped_events: usize,
12}
13
14impl InternalEvent for DatadogTracesEncodingError {
15    fn emit(self) {
16        let reason = "Failed to encode Datadog traces.";
17        error!(
18            message = reason,
19            error = %self.error_message,
20            error_reason = %self.error_reason,
21            error_type = error_type::ENCODER_FAILED,
22            stage = error_stage::PROCESSING,
23        );
24        counter!(
25            "component_errors_total",
26            "error_type" => error_type::ENCODER_FAILED,
27            "stage" => error_stage::PROCESSING,
28        )
29        .increment(1);
30
31        if self.dropped_events > 0 {
32            emit!(ComponentEventsDropped::<UNINTENTIONAL> {
33                count: self.dropped_events,
34                reason,
35            });
36        }
37    }
38}
39
40#[derive(Debug, NamedInternalEvent)]
41pub struct DatadogTracesAPMStatsError<E> {
42    pub error: E,
43}
44
45impl<E: std::fmt::Display> InternalEvent for DatadogTracesAPMStatsError<E> {
46    fn emit(self) {
47        error!(
48            message = "Failed sending APM stats payload.",
49            error = %self.error,
50            error_type = error_type::WRITER_FAILED,
51            stage = error_stage::SENDING,
52        );
53        counter!(
54            "component_errors_total",
55            "error_type" => error_type::WRITER_FAILED,
56            "stage" => error_stage::SENDING,
57        )
58        .increment(1);
59
60        // No dropped events because APM stats payloads are not considered events.
61    }
62}