inferadb 0.1.5

Official Rust SDK for InferaDB
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
//! Trace context for distributed tracing.

use std::fmt;

/// A distributed trace context following W3C Trace Context specification.
///
/// This type carries trace information across service boundaries,
/// enabling correlation of requests in distributed systems.
///
/// ## Example
///
/// ```rust,ignore
/// use inferadb::tracing_support::TraceContext;
///
/// // Create from incoming headers
/// let ctx = TraceContext::from_traceparent("00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01")?;
///
/// // Generate a new root trace
/// let ctx = TraceContext::new_root();
///
/// // Create a child span context
/// let child = ctx.child();
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TraceContext {
    /// The trace ID (16 bytes).
    trace_id: TraceId,
    /// The span ID (8 bytes).
    span_id: SpanId,
    /// The parent span ID (if any).
    parent_span_id: Option<SpanId>,
    /// Trace flags.
    flags: TraceFlags,
    /// Tracestate for vendor-specific data.
    tracestate: Option<String>,
}

impl TraceContext {
    /// Creates a new root trace context with random IDs.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use inferadb::tracing_support::TraceContext;
    ///
    /// let ctx = TraceContext::new_root();
    /// assert!(ctx.is_sampled());
    /// ```
    pub fn new_root() -> Self {
        Self {
            trace_id: TraceId::random(),
            span_id: SpanId::random(),
            parent_span_id: None,
            flags: TraceFlags::SAMPLED,
            tracestate: None,
        }
    }

    /// Creates a new trace context with the given trace and span IDs.
    pub fn new(trace_id: TraceId, span_id: SpanId) -> Self {
        Self {
            trace_id,
            span_id,
            parent_span_id: None,
            flags: TraceFlags::SAMPLED,
            tracestate: None,
        }
    }

    /// Creates a child span context from this context.
    ///
    /// The child inherits the trace ID and uses the current span ID as its parent.
    pub fn child(&self) -> Self {
        Self {
            trace_id: self.trace_id.clone(),
            span_id: SpanId::random(),
            parent_span_id: Some(self.span_id.clone()),
            flags: self.flags,
            tracestate: self.tracestate.clone(),
        }
    }

    /// Creates a trace context from a W3C traceparent header value.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use inferadb::tracing_support::TraceContext;
    ///
    /// let ctx = TraceContext::from_traceparent(
    ///     "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
    /// ).unwrap();
    ///
    /// assert_eq!(ctx.trace_id().to_string(), "4bf92f3577b34da6a3ce929d0e0e4736");
    /// assert_eq!(ctx.span_id().to_string(), "00f067aa0ba902b7");
    /// assert!(ctx.is_sampled());
    /// ```
    pub fn from_traceparent(traceparent: &str) -> Result<Self, TraceContextError> {
        let parts: Vec<&str> = traceparent.split('-').collect();
        if parts.len() != 4 {
            return Err(TraceContextError::InvalidFormat);
        }

        let version = parts[0];
        if version != "00" {
            return Err(TraceContextError::UnsupportedVersion);
        }

        let trace_id = TraceId::from_hex(parts[1])?;
        let span_id = SpanId::from_hex(parts[2])?;
        let flags = TraceFlags::from_hex(parts[3])?;

        Ok(Self {
            trace_id,
            span_id,
            parent_span_id: None,
            flags,
            tracestate: None,
        })
    }

    /// Returns the traceparent header value.
    ///
    /// ## Example
    ///
    /// ```rust
    /// use inferadb::tracing_support::TraceContext;
    ///
    /// let ctx = TraceContext::new_root();
    /// let header = ctx.to_traceparent();
    /// assert!(header.starts_with("00-"));
    /// ```
    pub fn to_traceparent(&self) -> String {
        format!("00-{}-{}-{:02x}", self.trace_id, self.span_id, self.flags.0)
    }

    /// Returns the trace ID.
    pub fn trace_id(&self) -> &TraceId {
        &self.trace_id
    }

    /// Returns the span ID.
    pub fn span_id(&self) -> &SpanId {
        &self.span_id
    }

    /// Returns the parent span ID, if any.
    pub fn parent_span_id(&self) -> Option<&SpanId> {
        self.parent_span_id.as_ref()
    }

    /// Returns the trace flags.
    pub fn flags(&self) -> TraceFlags {
        self.flags
    }

    /// Returns `true` if the trace is sampled.
    pub fn is_sampled(&self) -> bool {
        self.flags.is_sampled()
    }

    /// Sets the tracestate header value.
    pub fn with_tracestate(mut self, tracestate: impl Into<String>) -> Self {
        self.tracestate = Some(tracestate.into());
        self
    }

    /// Returns the tracestate header value, if any.
    pub fn tracestate(&self) -> Option<&str> {
        self.tracestate.as_deref()
    }

    /// Sets the sampled flag.
    pub fn with_sampled(mut self, sampled: bool) -> Self {
        if sampled {
            self.flags = self.flags | TraceFlags::SAMPLED;
        } else {
            self.flags = TraceFlags(self.flags.0 & !TraceFlags::SAMPLED.0);
        }
        self
    }
}

impl Default for TraceContext {
    fn default() -> Self {
        Self::new_root()
    }
}

impl fmt::Display for TraceContext {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.to_traceparent())
    }
}

/// A 128-bit trace identifier.
#[derive(Clone, PartialEq, Eq)]
pub struct TraceId([u8; 16]);

impl TraceId {
    /// Creates a new random trace ID.
    pub fn random() -> Self {
        let mut bytes = [0u8; 16];
        getrandom::getrandom(&mut bytes).expect("Failed to generate random bytes");
        Self(bytes)
    }

    /// Creates a trace ID from bytes.
    pub fn from_bytes(bytes: [u8; 16]) -> Self {
        Self(bytes)
    }

    /// Creates a trace ID from a hex string.
    pub fn from_hex(hex: &str) -> Result<Self, TraceContextError> {
        if hex.len() != 32 {
            return Err(TraceContextError::InvalidTraceId);
        }
        let mut bytes = [0u8; 16];
        hex::decode_to_slice(hex, &mut bytes).map_err(|_| TraceContextError::InvalidTraceId)?;

        // Check for invalid all-zero trace ID
        if bytes == [0u8; 16] {
            return Err(TraceContextError::InvalidTraceId);
        }

        Ok(Self(bytes))
    }

    /// Returns the trace ID as bytes.
    pub fn as_bytes(&self) -> &[u8; 16] {
        &self.0
    }
}

impl fmt::Debug for TraceId {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "TraceId({})", self)
    }
}

impl fmt::Display for TraceId {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", hex::encode(self.0))
    }
}

/// A 64-bit span identifier.
#[derive(Clone, PartialEq, Eq)]
pub struct SpanId([u8; 8]);

impl SpanId {
    /// Creates a new random span ID.
    pub fn random() -> Self {
        let mut bytes = [0u8; 8];
        getrandom::getrandom(&mut bytes).expect("Failed to generate random bytes");
        Self(bytes)
    }

    /// Creates a span ID from bytes.
    pub fn from_bytes(bytes: [u8; 8]) -> Self {
        Self(bytes)
    }

    /// Creates a span ID from a hex string.
    pub fn from_hex(hex: &str) -> Result<Self, TraceContextError> {
        if hex.len() != 16 {
            return Err(TraceContextError::InvalidSpanId);
        }
        let mut bytes = [0u8; 8];
        hex::decode_to_slice(hex, &mut bytes).map_err(|_| TraceContextError::InvalidSpanId)?;

        // Check for invalid all-zero span ID
        if bytes == [0u8; 8] {
            return Err(TraceContextError::InvalidSpanId);
        }

        Ok(Self(bytes))
    }

    /// Returns the span ID as bytes.
    pub fn as_bytes(&self) -> &[u8; 8] {
        &self.0
    }
}

impl fmt::Debug for SpanId {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "SpanId({})", self)
    }
}

impl fmt::Display for SpanId {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", hex::encode(self.0))
    }
}

/// Trace flags as defined by W3C Trace Context.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct TraceFlags(u8);

impl TraceFlags {
    /// No flags set.
    pub const NONE: Self = Self(0);
    /// The trace is sampled.
    pub const SAMPLED: Self = Self(0x01);

    /// Creates trace flags from a hex string.
    pub fn from_hex(hex: &str) -> Result<Self, TraceContextError> {
        if hex.len() != 2 {
            return Err(TraceContextError::InvalidFlags);
        }
        let value = u8::from_str_radix(hex, 16).map_err(|_| TraceContextError::InvalidFlags)?;
        Ok(Self(value))
    }

    /// Returns `true` if the sampled flag is set.
    pub fn is_sampled(&self) -> bool {
        self.0 & Self::SAMPLED.0 != 0
    }

    /// Returns the raw flag value.
    pub fn as_u8(&self) -> u8 {
        self.0
    }
}

impl std::ops::BitOr for TraceFlags {
    type Output = Self;

    fn bitor(self, rhs: Self) -> Self::Output {
        Self(self.0 | rhs.0)
    }
}

/// Error parsing trace context.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TraceContextError {
    /// Invalid traceparent format.
    InvalidFormat,
    /// Unsupported version.
    UnsupportedVersion,
    /// Invalid trace ID.
    InvalidTraceId,
    /// Invalid span ID.
    InvalidSpanId,
    /// Invalid flags.
    InvalidFlags,
}

impl fmt::Display for TraceContextError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            TraceContextError::InvalidFormat => write!(f, "invalid traceparent format"),
            TraceContextError::UnsupportedVersion => write!(f, "unsupported trace context version"),
            TraceContextError::InvalidTraceId => write!(f, "invalid trace ID"),
            TraceContextError::InvalidSpanId => write!(f, "invalid span ID"),
            TraceContextError::InvalidFlags => write!(f, "invalid trace flags"),
        }
    }
}

impl std::error::Error for TraceContextError {}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_trace_context_new_root() {
        let ctx = TraceContext::new_root();
        assert!(ctx.is_sampled());
        assert!(ctx.parent_span_id().is_none());
    }

    #[test]
    fn test_trace_context_child() {
        let parent = TraceContext::new_root();
        let child = parent.child();

        assert_eq!(child.trace_id(), parent.trace_id());
        assert_ne!(child.span_id(), parent.span_id());
        assert_eq!(child.parent_span_id(), Some(parent.span_id()));
    }

    #[test]
    fn test_trace_context_from_traceparent() {
        let ctx = TraceContext::from_traceparent(
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
        )
        .unwrap();

        assert_eq!(
            ctx.trace_id().to_string(),
            "4bf92f3577b34da6a3ce929d0e0e4736"
        );
        assert_eq!(ctx.span_id().to_string(), "00f067aa0ba902b7");
        assert!(ctx.is_sampled());
    }

    #[test]
    fn test_trace_context_to_traceparent() {
        let ctx = TraceContext::from_traceparent(
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
        )
        .unwrap();

        assert_eq!(
            ctx.to_traceparent(),
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
        );
    }

    #[test]
    fn test_trace_context_not_sampled() {
        let ctx = TraceContext::from_traceparent(
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00",
        )
        .unwrap();

        assert!(!ctx.is_sampled());
    }

    #[test]
    fn test_trace_context_invalid_format() {
        assert!(TraceContext::from_traceparent("invalid").is_err());
        assert!(TraceContext::from_traceparent("00-abc-def-01").is_err());
    }

    #[test]
    fn test_trace_context_with_tracestate() {
        let ctx = TraceContext::new_root().with_tracestate("vendor=value");

        assert_eq!(ctx.tracestate(), Some("vendor=value"));
    }

    #[test]
    fn test_trace_context_with_sampled() {
        let ctx = TraceContext::new_root().with_sampled(false);
        assert!(!ctx.is_sampled());

        let ctx = ctx.with_sampled(true);
        assert!(ctx.is_sampled());
    }

    #[test]
    fn test_trace_id_from_hex() {
        let id = TraceId::from_hex("4bf92f3577b34da6a3ce929d0e0e4736").unwrap();
        assert_eq!(id.to_string(), "4bf92f3577b34da6a3ce929d0e0e4736");
    }

    #[test]
    fn test_trace_id_invalid_all_zeros() {
        assert!(TraceId::from_hex("00000000000000000000000000000000").is_err());
    }

    #[test]
    fn test_span_id_from_hex() {
        let id = SpanId::from_hex("00f067aa0ba902b7").unwrap();
        assert_eq!(id.to_string(), "00f067aa0ba902b7");
    }

    #[test]
    fn test_span_id_invalid_all_zeros() {
        assert!(SpanId::from_hex("0000000000000000").is_err());
    }

    #[test]
    fn test_trace_flags() {
        assert!(!TraceFlags::NONE.is_sampled());
        assert!(TraceFlags::SAMPLED.is_sampled());
        assert!((TraceFlags::NONE | TraceFlags::SAMPLED).is_sampled());
    }

    #[test]
    fn test_trace_context_new() {
        let trace_id = TraceId::from_hex("4bf92f3577b34da6a3ce929d0e0e4736").unwrap();
        let span_id = SpanId::from_hex("00f067aa0ba902b7").unwrap();
        let ctx = TraceContext::new(trace_id.clone(), span_id.clone());

        assert_eq!(ctx.trace_id(), &trace_id);
        assert_eq!(ctx.span_id(), &span_id);
        assert!(ctx.is_sampled());
        assert!(ctx.parent_span_id().is_none());
    }

    #[test]
    fn test_trace_context_default() {
        let ctx = TraceContext::default();
        assert!(ctx.is_sampled());
        assert!(ctx.parent_span_id().is_none());
    }

    #[test]
    fn test_trace_context_display() {
        let ctx = TraceContext::from_traceparent(
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
        )
        .unwrap();
        let display = format!("{}", ctx);
        assert_eq!(
            display,
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
        );
    }

    #[test]
    fn test_trace_context_flags_accessor() {
        let ctx = TraceContext::from_traceparent(
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
        )
        .unwrap();
        assert_eq!(ctx.flags(), TraceFlags::SAMPLED);
    }

    #[test]
    fn test_trace_context_unsupported_version() {
        let err = TraceContext::from_traceparent(
            "01-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
        )
        .unwrap_err();
        assert_eq!(err, TraceContextError::UnsupportedVersion);
    }

    #[test]
    fn test_trace_id_from_bytes() {
        let bytes: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
        let id = TraceId::from_bytes(bytes);
        assert_eq!(id.as_bytes(), &bytes);
    }

    #[test]
    fn test_trace_id_random() {
        let id1 = TraceId::random();
        let id2 = TraceId::random();
        // Random IDs should be different
        assert_ne!(id1, id2);
    }

    #[test]
    fn test_trace_id_invalid_length() {
        let err = TraceId::from_hex("abc").unwrap_err();
        assert_eq!(err, TraceContextError::InvalidTraceId);
    }

    #[test]
    fn test_trace_id_invalid_hex() {
        let err = TraceId::from_hex("gggggggggggggggggggggggggggggggg").unwrap_err();
        assert_eq!(err, TraceContextError::InvalidTraceId);
    }

    #[test]
    fn test_trace_id_debug() {
        let id = TraceId::from_hex("4bf92f3577b34da6a3ce929d0e0e4736").unwrap();
        let debug = format!("{:?}", id);
        assert!(debug.contains("TraceId"));
        assert!(debug.contains("4bf92f3577b34da6a3ce929d0e0e4736"));
    }

    #[test]
    fn test_span_id_from_bytes() {
        let bytes: [u8; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
        let id = SpanId::from_bytes(bytes);
        assert_eq!(id.as_bytes(), &bytes);
    }

    #[test]
    fn test_span_id_random() {
        let id1 = SpanId::random();
        let id2 = SpanId::random();
        assert_ne!(id1, id2);
    }

    #[test]
    fn test_span_id_invalid_length() {
        let err = SpanId::from_hex("abc").unwrap_err();
        assert_eq!(err, TraceContextError::InvalidSpanId);
    }

    #[test]
    fn test_span_id_invalid_hex() {
        let err = SpanId::from_hex("gggggggggggggggg").unwrap_err();
        assert_eq!(err, TraceContextError::InvalidSpanId);
    }

    #[test]
    fn test_span_id_debug() {
        let id = SpanId::from_hex("00f067aa0ba902b7").unwrap();
        let debug = format!("{:?}", id);
        assert!(debug.contains("SpanId"));
        assert!(debug.contains("00f067aa0ba902b7"));
    }

    #[test]
    fn test_trace_flags_from_hex() {
        let flags = TraceFlags::from_hex("01").unwrap();
        assert!(flags.is_sampled());

        let flags = TraceFlags::from_hex("00").unwrap();
        assert!(!flags.is_sampled());
    }

    #[test]
    fn test_trace_flags_from_hex_invalid_length() {
        let err = TraceFlags::from_hex("0").unwrap_err();
        assert_eq!(err, TraceContextError::InvalidFlags);
    }

    #[test]
    fn test_trace_flags_from_hex_invalid() {
        let err = TraceFlags::from_hex("gg").unwrap_err();
        assert_eq!(err, TraceContextError::InvalidFlags);
    }

    #[test]
    fn test_trace_flags_as_u8() {
        assert_eq!(TraceFlags::NONE.as_u8(), 0);
        assert_eq!(TraceFlags::SAMPLED.as_u8(), 1);
    }

    #[test]
    fn test_trace_flags_default() {
        let flags = TraceFlags::default();
        assert_eq!(flags, TraceFlags::NONE);
    }

    #[test]
    fn test_trace_context_error_display() {
        assert_eq!(
            TraceContextError::InvalidFormat.to_string(),
            "invalid traceparent format"
        );
        assert_eq!(
            TraceContextError::UnsupportedVersion.to_string(),
            "unsupported trace context version"
        );
        assert_eq!(
            TraceContextError::InvalidTraceId.to_string(),
            "invalid trace ID"
        );
        assert_eq!(
            TraceContextError::InvalidSpanId.to_string(),
            "invalid span ID"
        );
        assert_eq!(
            TraceContextError::InvalidFlags.to_string(),
            "invalid trace flags"
        );
    }

    #[test]
    fn test_trace_context_error_is_error() {
        let err: &dyn std::error::Error = &TraceContextError::InvalidFormat;
        assert!(err.source().is_none());
    }

    #[test]
    fn test_trace_context_child_inherits_tracestate() {
        let parent = TraceContext::new_root().with_tracestate("vendor=value");
        let child = parent.child();
        assert_eq!(child.tracestate(), Some("vendor=value"));
    }

    #[test]
    fn test_trace_context_child_inherits_flags() {
        let parent = TraceContext::new_root().with_sampled(false);
        let child = parent.child();
        assert!(!child.is_sampled());
    }

    #[test]
    fn test_trace_context_eq() {
        let ctx1 = TraceContext::from_traceparent(
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
        )
        .unwrap();
        let ctx2 = TraceContext::from_traceparent(
            "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
        )
        .unwrap();
        assert_eq!(ctx1, ctx2);
    }

    #[test]
    fn test_trace_context_clone() {
        let ctx = TraceContext::new_root().with_tracestate("test=value");
        let cloned = ctx.clone();
        assert_eq!(ctx.trace_id(), cloned.trace_id());
        assert_eq!(ctx.tracestate(), cloned.tracestate());
    }
}