vector/api/schema/events/
trace.rs1use async_graphql::Object;
2use vector_lib::encode_logfmt;
3use vector_lib::event;
4use vector_lib::tap::topology::TapOutput;
5use vrl::event_path;
6
7use super::EventEncodingType;
8
9#[derive(Debug, Clone)]
10pub struct Trace {
11 output: TapOutput,
12 event: event::TraceEvent,
13}
14
15impl Trace {
16 pub const fn new(output: TapOutput, event: event::TraceEvent) -> Self {
17 Self { output, event }
18 }
19}
20
21#[Object]
22impl Trace {
24 async fn component_id(&self) -> &str {
26 self.output.output_id.component.id()
27 }
28
29 async fn component_type(&self) -> &str {
31 self.output.component_type.as_ref()
32 }
33
34 async fn component_kind(&self) -> &str {
36 self.output.component_kind
37 }
38
39 async fn string(&self, encoding: EventEncodingType) -> String {
41 match encoding {
42 EventEncodingType::Json => serde_json::to_string(&self.event)
43 .expect("JSON serialization of log event failed. Please report."),
44 EventEncodingType::Yaml => serde_yaml::to_string(&self.event)
45 .expect("YAML serialization of log event failed. Please report."),
46 EventEncodingType::Logfmt => encode_logfmt::encode_map(self.event.as_map())
47 .expect("logfmt serialization of log event failed. Please report."),
48 }
49 }
50
51 async fn json(&self, field: String) -> Option<String> {
53 self.event.get(event_path!(field.as_str())).map(|field| {
54 serde_json::to_string(field)
55 .expect("JSON serialization of log event field failed. Please report.")
56 })
57 }
58}