Skip to main content

libdd_telemetry/data/
payloads.rs

1// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4use 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}
52
53#[derive(Serialize, Debug)]
54pub struct AppDependenciesLoaded {
55    pub dependencies: Vec<Dependency>,
56}
57
58#[derive(Serialize, Debug)]
59pub struct AppIntegrationsChange {
60    pub integrations: Vec<Integration>,
61}
62
63#[derive(Debug, Serialize)]
64pub struct AppClientConfigurationChange {
65    pub configuration: Vec<Configuration>,
66}
67
68#[derive(Debug, Serialize)]
69pub struct AppEndpoints {
70    pub is_first: bool,
71    pub endpoints: Vec<serde_json::Value>,
72}
73
74#[derive(Serialize, Debug)]
75pub struct GenerateMetrics {
76    pub series: Vec<metrics::Serie>,
77}
78
79#[derive(Serialize, Debug)]
80pub struct Distributions {
81    pub series: Vec<metrics::Distribution>,
82}
83
84#[derive(Serialize, Deserialize, Debug, Clone)]
85pub struct Log {
86    pub message: String,
87    pub level: LogLevel,
88    pub count: u32,
89
90    #[serde(default)]
91    pub stack_trace: Option<String>,
92    #[serde(default)]
93    pub tags: String,
94    #[serde(default)]
95    pub is_sensitive: bool,
96    #[serde(default)]
97    pub is_crash: bool,
98}
99
100#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
101#[serde(rename_all = "UPPERCASE")]
102#[repr(C)]
103pub enum LogLevel {
104    Error,
105    Warn,
106    Debug,
107}
108
109#[derive(Serialize, Debug)]
110pub struct Logs {
111    pub logs: Vec<Log>,
112}
113
114#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone)]
115#[serde(rename_all = "UPPERCASE")]
116#[repr(C)]
117pub enum Method {
118    Get = 0,
119    Post = 1,
120    Put = 2,
121    Delete = 3,
122    Patch = 4,
123    Head = 5,
124    Options = 6,
125    Trace = 7,
126    Connect = 8,
127    Other = 9, //This is specified as "*" in the OpenAPI spec
128}
129
130#[derive(Serialize, Deserialize, Debug, Clone, Default)]
131pub struct Endpoint {
132    #[serde(default)]
133    pub method: Option<Method>,
134    #[serde(default)]
135    pub path: Option<String>,
136    pub operation_name: String,
137    pub resource_name: String,
138}
139
140impl PartialEq for Endpoint {
141    fn eq(&self, other: &Self) -> bool {
142        self.resource_name == other.resource_name
143    }
144}
145
146impl Eq for Endpoint {}
147
148impl std::hash::Hash for Endpoint {
149    fn hash<H: Hasher>(&self, state: &mut H) {
150        self.resource_name.hash(state);
151    }
152}
153
154impl Endpoint {
155    pub fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
156        serde_json::to_value(self)
157    }
158}