saluki_core/data_model/event/trace_stats/
mod.rs1use stringtheory::MetaString;
4
5#[derive(Clone, Debug, PartialEq, Default)]
11pub struct TraceStats {
12 stats: Vec<ClientStatsPayload>,
14}
15
16impl TraceStats {
17 pub fn new(stats: Vec<ClientStatsPayload>) -> Self {
19 Self { stats }
20 }
21
22 pub fn stats(&self) -> &[ClientStatsPayload] {
24 &self.stats
25 }
26
27 pub fn stats_mut(&mut self) -> &mut Vec<ClientStatsPayload> {
29 &mut self.stats
30 }
31}
32
33#[derive(Clone, Debug, PartialEq, Default)]
37pub struct ClientStatsPayload {
38 hostname: MetaString,
39 env: MetaString,
40 version: MetaString,
41 stats: Vec<ClientStatsBucket>,
42 lang: MetaString,
43 tracer_version: MetaString,
44 runtime_id: MetaString,
45 sequence: u64,
46 agent_aggregation: MetaString,
47 service: MetaString,
48 container_id: MetaString,
49 tags: Vec<MetaString>,
50 git_commit_sha: MetaString,
51 image_tag: MetaString,
52 process_tags_hash: u64,
53 process_tags: MetaString,
54}
55
56impl ClientStatsPayload {
57 pub fn new(hostname: impl Into<MetaString>, env: impl Into<MetaString>, version: impl Into<MetaString>) -> Self {
59 Self {
60 hostname: hostname.into(),
61 env: env.into(),
62 version: version.into(),
63 ..Self::default()
64 }
65 }
66
67 pub fn with_stats(mut self, stats: Vec<ClientStatsBucket>) -> Self {
69 self.stats = stats;
70 self
71 }
72
73 pub fn with_lang(mut self, lang: impl Into<MetaString>) -> Self {
75 self.lang = lang.into();
76 self
77 }
78
79 pub fn with_tracer_version(mut self, tracer_version: impl Into<MetaString>) -> Self {
81 self.tracer_version = tracer_version.into();
82 self
83 }
84
85 pub fn with_runtime_id(mut self, runtime_id: impl Into<MetaString>) -> Self {
87 self.runtime_id = runtime_id.into();
88 self
89 }
90
91 pub fn with_sequence(mut self, sequence: u64) -> Self {
93 self.sequence = sequence;
94 self
95 }
96
97 pub fn with_agent_aggregation(mut self, agent_aggregation: impl Into<MetaString>) -> Self {
99 self.agent_aggregation = agent_aggregation.into();
100 self
101 }
102
103 pub fn with_service(mut self, service: impl Into<MetaString>) -> Self {
105 self.service = service.into();
106 self
107 }
108
109 pub fn with_container_id(mut self, container_id: impl Into<MetaString>) -> Self {
111 self.container_id = container_id.into();
112 self
113 }
114
115 pub fn with_tags(mut self, tags: Vec<MetaString>) -> Self {
117 self.tags = tags;
118 self
119 }
120
121 pub fn with_git_commit_sha(mut self, git_commit_sha: impl Into<MetaString>) -> Self {
123 self.git_commit_sha = git_commit_sha.into();
124 self
125 }
126
127 pub fn with_image_tag(mut self, image_tag: impl Into<MetaString>) -> Self {
129 self.image_tag = image_tag.into();
130 self
131 }
132
133 pub fn with_process_tags_hash(mut self, process_tags_hash: u64) -> Self {
135 self.process_tags_hash = process_tags_hash;
136 self
137 }
138
139 pub fn with_process_tags(mut self, process_tags: impl Into<MetaString>) -> Self {
141 self.process_tags = process_tags.into();
142 self
143 }
144
145 pub fn hostname(&self) -> &str {
147 &self.hostname
148 }
149
150 pub fn env(&self) -> &str {
152 &self.env
153 }
154
155 pub fn version(&self) -> &str {
157 &self.version
158 }
159
160 pub fn stats(&self) -> &[ClientStatsBucket] {
162 &self.stats
163 }
164
165 pub fn lang(&self) -> &str {
167 &self.lang
168 }
169
170 pub fn tracer_version(&self) -> &str {
172 &self.tracer_version
173 }
174
175 pub fn runtime_id(&self) -> &str {
177 &self.runtime_id
178 }
179
180 pub fn sequence(&self) -> u64 {
182 self.sequence
183 }
184
185 pub fn agent_aggregation(&self) -> &str {
187 &self.agent_aggregation
188 }
189
190 pub fn service(&self) -> &str {
192 &self.service
193 }
194
195 pub fn container_id(&self) -> &str {
197 &self.container_id
198 }
199
200 pub fn tags(&self) -> &[MetaString] {
202 &self.tags
203 }
204
205 pub fn git_commit_sha(&self) -> &str {
207 &self.git_commit_sha
208 }
209
210 pub fn image_tag(&self) -> &str {
212 &self.image_tag
213 }
214
215 pub fn process_tags_hash(&self) -> u64 {
217 self.process_tags_hash
218 }
219
220 pub fn process_tags(&self) -> &str {
222 &self.process_tags
223 }
224}
225
226#[derive(Clone, Debug, PartialEq, Default)]
230pub struct ClientStatsBucket {
231 start: u64,
233 duration: u64,
235 stats: Vec<ClientGroupedStats>,
237 agent_time_shift: i64,
239}
240
241impl ClientStatsBucket {
242 pub fn new(start: u64, duration: u64, stats: Vec<ClientGroupedStats>) -> Self {
244 Self {
245 start,
246 duration,
247 stats,
248 agent_time_shift: 0,
249 }
250 }
251
252 pub fn with_agent_time_shift(mut self, agent_time_shift: i64) -> Self {
254 self.agent_time_shift = agent_time_shift;
255 self
256 }
257
258 pub fn start(&self) -> u64 {
260 self.start
261 }
262
263 pub fn duration(&self) -> u64 {
265 self.duration
266 }
267
268 pub fn stats(&self) -> &[ClientGroupedStats] {
270 &self.stats
271 }
272
273 pub fn stats_mut(&mut self) -> &mut Vec<ClientGroupedStats> {
275 &mut self.stats
276 }
277
278 pub fn agent_time_shift(&self) -> i64 {
280 self.agent_time_shift
281 }
282}
283
284#[derive(Clone, Debug, PartialEq, Default)]
289pub struct ClientGroupedStats {
290 service: MetaString,
292 name: MetaString,
293 resource: MetaString,
294 http_status_code: u32,
295 span_type: MetaString,
296 db_type: MetaString,
297 span_kind: MetaString,
298 peer_tags: Vec<MetaString>,
299 is_trace_root: Option<bool>,
300 grpc_status_code: MetaString,
301 http_method: MetaString,
302 http_endpoint: MetaString,
303
304 hits: u64,
306 errors: u64,
307 duration: u64,
308 ok_summary: Vec<u8>,
309 error_summary: Vec<u8>,
310 synthetics: bool,
311 top_level_hits: u64,
312}
313
314impl ClientGroupedStats {
315 pub fn new(service: impl Into<MetaString>, name: impl Into<MetaString>, resource: impl Into<MetaString>) -> Self {
317 Self {
318 service: service.into(),
319 name: name.into(),
320 resource: resource.into(),
321 ..Self::default()
322 }
323 }
324
325 pub fn with_http_status_code(mut self, http_status_code: u32) -> Self {
329 self.http_status_code = http_status_code;
330 self
331 }
332
333 pub fn with_span_type(mut self, span_type: impl Into<MetaString>) -> Self {
335 self.span_type = span_type.into();
336 self
337 }
338
339 pub fn with_db_type(mut self, db_type: impl Into<MetaString>) -> Self {
341 self.db_type = db_type.into();
342 self
343 }
344
345 pub fn with_span_kind(mut self, span_kind: impl Into<MetaString>) -> Self {
347 self.span_kind = span_kind.into();
348 self
349 }
350
351 pub fn with_peer_tags(mut self, peer_tags: Vec<MetaString>) -> Self {
353 self.peer_tags = peer_tags;
354 self
355 }
356
357 pub fn with_is_trace_root(mut self, is_trace_root: Option<bool>) -> Self {
359 self.is_trace_root = is_trace_root;
360 self
361 }
362
363 pub fn with_grpc_status_code(mut self, grpc_status_code: impl Into<MetaString>) -> Self {
365 self.grpc_status_code = grpc_status_code.into();
366 self
367 }
368
369 pub fn with_http_method(mut self, http_method: impl Into<MetaString>) -> Self {
371 self.http_method = http_method.into();
372 self
373 }
374
375 pub fn with_http_endpoint(mut self, http_endpoint: impl Into<MetaString>) -> Self {
377 self.http_endpoint = http_endpoint.into();
378 self
379 }
380
381 pub fn with_hits(mut self, hits: u64) -> Self {
385 self.hits = hits;
386 self
387 }
388
389 pub fn with_errors(mut self, errors: u64) -> Self {
391 self.errors = errors;
392 self
393 }
394
395 pub fn with_duration(mut self, duration: u64) -> Self {
397 self.duration = duration;
398 self
399 }
400
401 pub fn with_ok_summary(mut self, ok_summary: Vec<u8>) -> Self {
403 self.ok_summary = ok_summary;
404 self
405 }
406
407 pub fn with_error_summary(mut self, error_summary: Vec<u8>) -> Self {
409 self.error_summary = error_summary;
410 self
411 }
412
413 pub fn with_synthetics(mut self, synthetics: bool) -> Self {
415 self.synthetics = synthetics;
416 self
417 }
418
419 pub fn with_top_level_hits(mut self, top_level_hits: u64) -> Self {
421 self.top_level_hits = top_level_hits;
422 self
423 }
424
425 pub fn service(&self) -> &str {
429 &self.service
430 }
431
432 pub fn name(&self) -> &str {
434 &self.name
435 }
436
437 pub fn resource(&self) -> &str {
439 &self.resource
440 }
441
442 pub fn http_status_code(&self) -> u32 {
444 self.http_status_code
445 }
446
447 pub fn span_type(&self) -> &str {
449 &self.span_type
450 }
451
452 pub fn db_type(&self) -> &str {
454 &self.db_type
455 }
456
457 pub fn span_kind(&self) -> &str {
459 &self.span_kind
460 }
461
462 pub fn peer_tags(&self) -> &[MetaString] {
464 &self.peer_tags
465 }
466
467 pub fn is_trace_root(&self) -> Option<bool> {
469 self.is_trace_root
470 }
471
472 pub fn grpc_status_code(&self) -> &str {
474 &self.grpc_status_code
475 }
476
477 pub fn http_method(&self) -> &str {
479 &self.http_method
480 }
481
482 pub fn http_endpoint(&self) -> &str {
484 &self.http_endpoint
485 }
486
487 pub fn hits(&self) -> u64 {
491 self.hits
492 }
493
494 pub fn errors(&self) -> u64 {
496 self.errors
497 }
498
499 pub fn duration(&self) -> u64 {
501 self.duration
502 }
503
504 pub fn ok_summary(&self) -> &[u8] {
506 &self.ok_summary
507 }
508
509 pub fn error_summary(&self) -> &[u8] {
511 &self.error_summary
512 }
513
514 pub fn synthetics(&self) -> bool {
516 self.synthetics
517 }
518
519 pub fn top_level_hits(&self) -> u64 {
521 self.top_level_hits
522 }
523}