saluki_core/data_model/event/trace_stats/
mod.rs1use stringtheory::MetaString;
4
5use crate::data_model::tags::TagSet;
6
7#[derive(Clone, Debug, PartialEq, Default)]
14pub struct TraceStats {
15 stats: Vec<ClientStatsPayload>,
17 split_payload: bool,
19}
20
21impl TraceStats {
22 pub fn new(stats: Vec<ClientStatsPayload>) -> Self {
24 Self {
25 stats,
26 split_payload: false,
27 }
28 }
29
30 pub fn with_split_payload(mut self, split_payload: bool) -> Self {
32 self.split_payload = split_payload;
33 self
34 }
35
36 pub fn is_split_payload(&self) -> bool {
38 self.split_payload
39 }
40
41 pub fn stats(&self) -> &[ClientStatsPayload] {
43 &self.stats
44 }
45
46 pub fn stats_mut(&mut self) -> &mut Vec<ClientStatsPayload> {
48 &mut self.stats
49 }
50}
51
52#[derive(Clone, Debug, PartialEq, Default)]
56pub struct ClientStatsPayload {
57 hostname: MetaString,
58 env: MetaString,
59 version: MetaString,
60 stats: Vec<ClientStatsBucket>,
61 lang: MetaString,
62 tracer_version: MetaString,
63 runtime_id: MetaString,
64 sequence: u64,
65 agent_aggregation: MetaString,
66 service: MetaString,
67 container_id: MetaString,
68 tags: TagSet,
69 git_commit_sha: MetaString,
70 image_tag: MetaString,
71 process_tags_hash: u64,
72 process_tags: MetaString,
73}
74
75impl ClientStatsPayload {
76 pub fn new(hostname: impl Into<MetaString>, env: impl Into<MetaString>, version: impl Into<MetaString>) -> Self {
78 Self {
79 hostname: hostname.into(),
80 env: env.into(),
81 version: version.into(),
82 ..Self::default()
83 }
84 }
85
86 pub fn with_stats(mut self, stats: Vec<ClientStatsBucket>) -> Self {
88 self.stats = stats;
89 self
90 }
91
92 pub fn with_lang(mut self, lang: impl Into<MetaString>) -> Self {
94 self.lang = lang.into();
95 self
96 }
97
98 pub fn with_tracer_version(mut self, tracer_version: impl Into<MetaString>) -> Self {
100 self.tracer_version = tracer_version.into();
101 self
102 }
103
104 pub fn with_runtime_id(mut self, runtime_id: impl Into<MetaString>) -> Self {
106 self.runtime_id = runtime_id.into();
107 self
108 }
109
110 pub fn with_sequence(mut self, sequence: u64) -> Self {
112 self.sequence = sequence;
113 self
114 }
115
116 pub fn with_agent_aggregation(mut self, agent_aggregation: impl Into<MetaString>) -> Self {
118 self.agent_aggregation = agent_aggregation.into();
119 self
120 }
121
122 pub fn with_service(mut self, service: impl Into<MetaString>) -> Self {
124 self.service = service.into();
125 self
126 }
127
128 pub fn with_container_id(mut self, container_id: impl Into<MetaString>) -> Self {
130 self.container_id = container_id.into();
131 self
132 }
133
134 pub fn with_tags(mut self, tags: impl Into<TagSet>) -> Self {
136 self.tags = tags.into();
137 self
138 }
139
140 pub fn with_git_commit_sha(mut self, git_commit_sha: impl Into<MetaString>) -> Self {
142 self.git_commit_sha = git_commit_sha.into();
143 self
144 }
145
146 pub fn with_image_tag(mut self, image_tag: impl Into<MetaString>) -> Self {
148 self.image_tag = image_tag.into();
149 self
150 }
151
152 pub fn with_process_tags_hash(mut self, process_tags_hash: u64) -> Self {
154 self.process_tags_hash = process_tags_hash;
155 self
156 }
157
158 pub fn with_process_tags(mut self, process_tags: impl Into<MetaString>) -> Self {
160 self.process_tags = process_tags.into();
161 self
162 }
163
164 pub fn hostname(&self) -> &str {
166 &self.hostname
167 }
168
169 pub fn env(&self) -> &str {
171 &self.env
172 }
173
174 pub fn version(&self) -> &str {
176 &self.version
177 }
178
179 pub fn stats(&self) -> &[ClientStatsBucket] {
181 &self.stats
182 }
183
184 pub fn lang(&self) -> &str {
186 &self.lang
187 }
188
189 pub fn tracer_version(&self) -> &str {
191 &self.tracer_version
192 }
193
194 pub fn runtime_id(&self) -> &str {
196 &self.runtime_id
197 }
198
199 pub fn sequence(&self) -> u64 {
201 self.sequence
202 }
203
204 pub fn agent_aggregation(&self) -> &str {
206 &self.agent_aggregation
207 }
208
209 pub fn service(&self) -> &str {
211 &self.service
212 }
213
214 pub fn container_id(&self) -> &str {
216 &self.container_id
217 }
218
219 pub fn tags(&self) -> &TagSet {
221 &self.tags
222 }
223
224 pub fn git_commit_sha(&self) -> &str {
226 &self.git_commit_sha
227 }
228
229 pub fn image_tag(&self) -> &str {
231 &self.image_tag
232 }
233
234 pub fn process_tags_hash(&self) -> u64 {
236 self.process_tags_hash
237 }
238
239 pub fn process_tags(&self) -> &str {
241 &self.process_tags
242 }
243
244 pub fn add_stats(&mut self, stats: ClientStatsBucket) {
246 self.stats.push(stats);
247 }
248
249 pub fn take_stats(&mut self) -> Vec<ClientStatsBucket> {
253 std::mem::take(&mut self.stats)
254 }
255}
256
257#[derive(Clone, Debug, PartialEq, Default)]
261pub struct ClientStatsBucket {
262 start: u64,
264 duration: u64,
266 stats: Vec<ClientGroupedStats>,
268 agent_time_shift: i64,
270}
271
272impl ClientStatsBucket {
273 pub fn new(start: u64, duration: u64, stats: Vec<ClientGroupedStats>) -> Self {
275 Self {
276 start,
277 duration,
278 stats,
279 agent_time_shift: 0,
280 }
281 }
282
283 pub fn with_stats(mut self, stats: Vec<ClientGroupedStats>) -> Self {
285 self.stats = stats;
286 self
287 }
288
289 pub fn with_agent_time_shift(mut self, agent_time_shift: i64) -> Self {
291 self.agent_time_shift = agent_time_shift;
292 self
293 }
294
295 pub fn start(&self) -> u64 {
297 self.start
298 }
299
300 pub fn duration(&self) -> u64 {
302 self.duration
303 }
304
305 pub fn stats(&self) -> &[ClientGroupedStats] {
307 &self.stats
308 }
309
310 pub fn stats_mut(&mut self) -> &mut Vec<ClientGroupedStats> {
312 &mut self.stats
313 }
314
315 pub fn agent_time_shift(&self) -> i64 {
317 self.agent_time_shift
318 }
319
320 pub fn take_stats(&mut self) -> Vec<ClientGroupedStats> {
324 std::mem::take(&mut self.stats)
325 }
326}
327
328#[derive(Clone, Debug, PartialEq, Default)]
333pub struct ClientGroupedStats {
334 service: MetaString,
336 name: MetaString,
337 resource: MetaString,
338 http_status_code: u32,
339 span_type: MetaString,
340 db_type: MetaString,
341 span_kind: MetaString,
342 peer_tags: Vec<MetaString>,
343 is_trace_root: Option<bool>,
344 grpc_status_code: MetaString,
345 http_method: MetaString,
346 http_endpoint: MetaString,
347
348 hits: u64,
350 errors: u64,
351 duration: u64,
352 ok_summary: Vec<u8>,
353 error_summary: Vec<u8>,
354 synthetics: bool,
355 top_level_hits: u64,
356}
357
358impl ClientGroupedStats {
359 pub fn new(service: impl Into<MetaString>, name: impl Into<MetaString>, resource: impl Into<MetaString>) -> Self {
361 Self {
362 service: service.into(),
363 name: name.into(),
364 resource: resource.into(),
365 ..Self::default()
366 }
367 }
368
369 pub fn with_http_status_code(mut self, http_status_code: u32) -> Self {
373 self.http_status_code = http_status_code;
374 self
375 }
376
377 pub fn with_span_type(mut self, span_type: impl Into<MetaString>) -> Self {
379 self.span_type = span_type.into();
380 self
381 }
382
383 pub fn with_db_type(mut self, db_type: impl Into<MetaString>) -> Self {
385 self.db_type = db_type.into();
386 self
387 }
388
389 pub fn with_span_kind(mut self, span_kind: impl Into<MetaString>) -> Self {
391 self.span_kind = span_kind.into();
392 self
393 }
394
395 pub fn with_peer_tags(mut self, peer_tags: Vec<MetaString>) -> Self {
397 self.peer_tags = peer_tags;
398 self
399 }
400
401 pub fn with_is_trace_root(mut self, is_trace_root: Option<bool>) -> Self {
403 self.is_trace_root = is_trace_root;
404 self
405 }
406
407 pub fn with_grpc_status_code(mut self, grpc_status_code: impl Into<MetaString>) -> Self {
409 self.grpc_status_code = grpc_status_code.into();
410 self
411 }
412
413 pub fn with_http_method(mut self, http_method: impl Into<MetaString>) -> Self {
415 self.http_method = http_method.into();
416 self
417 }
418
419 pub fn with_http_endpoint(mut self, http_endpoint: impl Into<MetaString>) -> Self {
421 self.http_endpoint = http_endpoint.into();
422 self
423 }
424
425 pub fn with_hits(mut self, hits: u64) -> Self {
429 self.hits = hits;
430 self
431 }
432
433 pub fn with_errors(mut self, errors: u64) -> Self {
435 self.errors = errors;
436 self
437 }
438
439 pub fn with_duration(mut self, duration: u64) -> Self {
441 self.duration = duration;
442 self
443 }
444
445 pub fn with_ok_summary(mut self, ok_summary: Vec<u8>) -> Self {
447 self.ok_summary = ok_summary;
448 self
449 }
450
451 pub fn with_error_summary(mut self, error_summary: Vec<u8>) -> Self {
453 self.error_summary = error_summary;
454 self
455 }
456
457 pub fn with_synthetics(mut self, synthetics: bool) -> Self {
459 self.synthetics = synthetics;
460 self
461 }
462
463 pub fn with_top_level_hits(mut self, top_level_hits: u64) -> Self {
465 self.top_level_hits = top_level_hits;
466 self
467 }
468
469 pub fn service(&self) -> &str {
473 &self.service
474 }
475
476 pub fn name(&self) -> &str {
478 &self.name
479 }
480
481 pub fn resource(&self) -> &str {
483 &self.resource
484 }
485
486 pub fn http_status_code(&self) -> u32 {
488 self.http_status_code
489 }
490
491 pub fn span_type(&self) -> &str {
493 &self.span_type
494 }
495
496 pub fn db_type(&self) -> &str {
498 &self.db_type
499 }
500
501 pub fn span_kind(&self) -> &str {
503 &self.span_kind
504 }
505
506 pub fn peer_tags(&self) -> &[MetaString] {
508 &self.peer_tags
509 }
510
511 pub fn is_trace_root(&self) -> Option<bool> {
513 self.is_trace_root
514 }
515
516 pub fn grpc_status_code(&self) -> &str {
518 &self.grpc_status_code
519 }
520
521 pub fn http_method(&self) -> &str {
523 &self.http_method
524 }
525
526 pub fn http_endpoint(&self) -> &str {
528 &self.http_endpoint
529 }
530
531 pub fn hits(&self) -> u64 {
535 self.hits
536 }
537
538 pub fn errors(&self) -> u64 {
540 self.errors
541 }
542
543 pub fn duration(&self) -> u64 {
545 self.duration
546 }
547
548 pub fn ok_summary(&self) -> &[u8] {
550 &self.ok_summary
551 }
552
553 pub fn error_summary(&self) -> &[u8] {
555 &self.error_summary
556 }
557
558 pub fn synthetics(&self) -> bool {
560 self.synthetics
561 }
562
563 pub fn top_level_hits(&self) -> u64 {
565 self.top_level_hits
566 }
567}