1use std::hash::Hasher;
5
6use crate::data::metrics;
7
8use serde::{Deserialize, Serialize};
9
10#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone, Default)]
11pub struct Dependency {
12 pub name: String,
13 pub version: Option<String>,
14}
15
16#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone, Default)]
17pub struct Integration {
18 pub name: String,
19 pub enabled: bool,
20 pub version: Option<String>,
21 pub compatible: Option<bool>,
22 pub auto_enabled: Option<bool>,
23}
24
25#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone)]
26pub struct Configuration {
27 pub name: String,
28 pub value: String,
29 pub origin: ConfigurationOrigin,
30 pub config_id: Option<String>,
31 pub seq_id: Option<u64>,
32}
33
34#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone)]
35#[repr(C)]
36#[serde(rename_all = "snake_case")]
37pub enum ConfigurationOrigin {
38 EnvVar,
39 Code,
40 DdConfig,
41 RemoteConfig,
42 Default,
43 LocalStableConfig,
44 FleetStableConfig,
45 Calculated,
46}
47
48#[derive(Serialize, Debug)]
49pub struct AppStarted {
50 pub configuration: Vec<Configuration>,
51 pub dependencies: Vec<Dependency>,
52 pub integrations: Vec<Integration>,
53}
54
55#[derive(Serialize, Debug)]
56pub struct AppDependenciesLoaded {
57 pub dependencies: Vec<Dependency>,
58}
59
60#[derive(Serialize, Debug)]
61pub struct AppIntegrationsChange {
62 pub integrations: Vec<Integration>,
63}
64
65#[derive(Debug, Serialize)]
66pub struct AppClientConfigurationChange {
67 pub configuration: Vec<Configuration>,
68}
69
70#[derive(Debug, Serialize)]
71pub struct AppEndpoints {
72 pub is_first: bool,
73 pub endpoints: Vec<serde_json::Value>,
74}
75
76#[derive(Serialize, Debug)]
77pub struct GenerateMetrics {
78 pub series: Vec<metrics::Serie>,
79}
80
81#[derive(Serialize, Debug)]
82pub struct Distributions {
83 pub series: Vec<metrics::Distribution>,
84}
85
86#[derive(Serialize, Deserialize, Debug, Clone)]
87pub struct Log {
88 pub message: String,
89 pub level: LogLevel,
90 pub count: u32,
91
92 #[serde(default)]
93 pub stack_trace: Option<String>,
94 #[serde(default)]
95 pub tags: String,
96 #[serde(default)]
97 pub is_sensitive: bool,
98 #[serde(default)]
99 pub is_crash: bool,
100}
101
102#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
103#[serde(rename_all = "UPPERCASE")]
104#[repr(C)]
105pub enum LogLevel {
106 Error,
107 Warn,
108 Debug,
109}
110
111#[derive(Serialize, Debug)]
112pub struct Logs {
113 pub logs: Vec<Log>,
114}
115
116#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
117#[serde(rename_all = "UPPERCASE")]
118#[repr(C)]
119pub enum Method {
120 Get = 0,
121 Post = 1,
122 Put = 2,
123 Delete = 3,
124 Patch = 4,
125 Head = 5,
126 Options = 6,
127 Trace = 7,
128 Connect = 8,
129 #[serde(rename = "*")]
133 Other = 9,
134}
135
136#[derive(Serialize, Deserialize, Debug, Clone, Default)]
137pub struct Endpoint {
138 #[serde(default)]
139 pub method: Option<Method>,
140 #[serde(default)]
141 pub path: Option<String>,
142 pub operation_name: String,
143 pub resource_name: String,
144}
145
146impl PartialEq for Endpoint {
147 fn eq(&self, other: &Self) -> bool {
148 self.resource_name == other.resource_name
149 }
150}
151
152impl Eq for Endpoint {}
153
154impl std::hash::Hash for Endpoint {
155 fn hash<H: Hasher>(&self, state: &mut H) {
156 self.resource_name.hash(state);
157 }
158}
159
160impl Endpoint {
161 pub fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
162 serde_json::to_value(self)
163 }
164}