tracing-cloudchamber 0.1.0

Extend tracing with an ffi via cxx to emit events and create spans in C++
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
692
693
#![allow(clippy::needless_lifetimes)]

#[cxx::bridge(namespace = "cloudchamber")]
pub mod ffi {

    pub struct Metadata<'a> {
        name: &'static str,
        target: &'a str,
        level: Level,
        file: &'static str,
        line: u32,
        fields: &'static [&'static str],
        callsite: &'static Callsite,
        kind: Kind,
    }

    #[namespace = "cloudchamber::detail"]
    pub enum LevelValue {
        ERROR,
        WARN,
        INFO,
        DEBUG,
        TRACE,
    }

    pub struct Level {
        value: LevelValue,
    }

    #[namespace = "cloudchamber::detail"]
    pub enum KindValue {
        EVENT,
        SPAN,
        HINT,
    }

    pub struct Kind {
        value: KindValue,
    }

    #[namespace = "cloudchamber::detail"]
    pub enum InterestKind {
        NEVER,
        SOMERTIMES,
        ALWAYS,
    }

    pub struct Interest {
        value: InterestKind,
    }

    #[namespace = "cloudchamber::detail"]
    pub enum FieldValueKind {
        U8,
        U16,
        U32,
        U64,
        I8,
        I16,
        I32,
        I64,
        F32,
        F64,
        STRING,
        STR,
        BOOL,
        DEBUG,
        EMPTY,
    }

    unsafe extern "C++" {
        include!("tracing-cloudchamber/src/lib.h");

        type Callsite;

        #[rust_name = "register"]
        pub fn register_site(self: &Callsite) -> Interest;
        pub fn store_interest(self: &Callsite, value: &Interest);
        pub fn get_meta<'a>(self: &Callsite) -> &Box<RustMetadata<'a>>;

    }

    extern "C++" {
        include!("tracing-cloudchamber/src/lib.h");

        #[namespace = "cloudchamber::detail"]
        type FieldValueKind;
    }

    unsafe extern "C++" {
        include!("tracing-cloudchamber/src/lib.h");

        type FieldValue;

        fn get_u8(&self) -> &u8;
        fn get_u16(&self) -> &u16;
        fn get_u32(&self) -> &u32;
        fn get_u64(&self) -> &u64;
        fn get_i8(&self) -> &i8;
        fn get_i16(&self) -> &i16;
        fn get_i32(&self) -> &i32;
        fn get_i64(&self) -> &i64;
        fn get_f32(&self) -> &f32;
        fn get_f64(&self) -> &f64;
        fn get_bool(&self) -> &bool;
        fn get_string(&self) -> &String;
        fn get_str(&self) -> &String;
        fn get_debug(&self) -> Result<&Box<DisplayValue>>;

        fn get_type(&self) -> FieldValueKind;
    }

    unsafe extern "C++" {
        type ScopeLambda;
        fn call(&self);
    }

    extern "Rust" {
        type DisplayValue;
        pub fn string_to_display_value(value: String) -> Box<DisplayValue>;
    }

    extern "Rust" {
        fn as_str(self: &Level) -> &'static str;

        type RustMetadata<'a>;
        unsafe fn new_rust_metadata<'a>(meta: &'static Metadata<'a>) -> Box<RustMetadata<'a>>;

        /// Returns `true` if this level is enabled by the current subscriber
        fn is_enabled(self: &Level) -> bool;

        fn default_enabled_for_meta(interest: &Interest, meta: &Box<RustMetadata>) -> bool;
        fn dispatch_tracing_event(meta: &'static Box<RustMetadata>);
        fn dispatch_tracing_event1(meta: &'static Box<RustMetadata>, f1: &FieldValue);
        fn dispatch_tracing_event2(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
        );
        fn dispatch_tracing_event3(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
        );
        fn dispatch_tracing_event4(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
        );
        fn dispatch_tracing_event5(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
        );
        fn dispatch_tracing_event6(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
        );
        #[allow(clippy::too_many_arguments)]
        fn dispatch_tracing_event7(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
            f7: &FieldValue,
        );
        #[allow(clippy::too_many_arguments)]
        fn dispatch_tracing_event8(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
            f7: &FieldValue,
            f8: &FieldValue,
        );
        #[allow(clippy::too_many_arguments)]
        fn dispatch_tracing_event9(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
            f7: &FieldValue,
            f8: &FieldValue,
            f9: &FieldValue,
        );
        #[allow(clippy::too_many_arguments)]
        fn dispatch_tracing_event10(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
            f7: &FieldValue,
            f8: &FieldValue,
            f9: &FieldValue,
            f10: &FieldValue,
        );
    }

    extern "Rust" {

        type Span;
        type Entered<'a>;

        /// genter a span and return a guard that will exit the span when droped
        unsafe fn enter<'a>(self: &'a Span) -> Box<Entered<'a>>;
        /// Returns `true` if this `Span` has a field for the given field name
        ///
        /// * `field`: field name
        pub fn has_field(self: &Span, field: &str) -> bool;
        /// Record that the fied described by `field` has the value `value`
        ///
        /// This may be used with `::cloudchamber::FieldEmpty` from the cpp side
        ///
        /// * `field`: field name
        /// * `value`: field value
        pub unsafe fn record<'a>(self: &'a Span, field: &'a str, value: &'a FieldValue)
            -> &'a Span;
        /// Returns `true` if this span was constructed by `Span::none`
        pub fn is_none(self: &Span) -> bool;
        /// Returns `true` if this span was disabled by the subscriber and does not exist
        pub fn is_disabeld(self: &Span) -> bool;
        /// Execute the given function in the context of this span.
        ///
        /// * `f`: function to execute
        fn in_scope(self: &Span, f: &ScopeLambda);

        fn new_disabled_span(meta: &'static Box<RustMetadata>) -> Box<Span>;
        fn current_span() -> Box<Span>;

        fn new_span(meta: &'static Box<RustMetadata>) -> Box<Span>;
        fn new_span1(meta: &'static Box<RustMetadata>, f1: &FieldValue) -> Box<Span>;
        fn new_span2(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
        ) -> Box<Span>;
        fn new_span3(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
        ) -> Box<Span>;
        fn new_span4(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
        ) -> Box<Span>;
        fn new_span5(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
        ) -> Box<Span>;
        fn new_span6(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
        ) -> Box<Span>;
        #[allow(clippy::too_many_arguments)]
        fn new_span7(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
            f7: &FieldValue,
        ) -> Box<Span>;
        #[allow(clippy::too_many_arguments)]
        fn new_span8(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
            f7: &FieldValue,
            f8: &FieldValue,
        ) -> Box<Span>;
        #[allow(clippy::too_many_arguments)]
        fn new_span9(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
            f7: &FieldValue,
            f8: &FieldValue,
            f9: &FieldValue,
        ) -> Box<Span>;
        #[allow(clippy::too_many_arguments)]
        fn new_span10(
            meta: &'static Box<RustMetadata>,
            f1: &FieldValue,
            f2: &FieldValue,
            f3: &FieldValue,
            f4: &FieldValue,
            f5: &FieldValue,
            f6: &FieldValue,
            f7: &FieldValue,
            f8: &FieldValue,
            f9: &FieldValue,
            f10: &FieldValue,
        ) -> Box<Span>;
    }
}

unsafe impl Sync for ffi::Callsite {}
unsafe impl Send for ffi::Callsite {}

impl ffi::Level {
    #[allow(dead_code)]
    const ERROR: Self = Self {
        value: ffi::LevelValue::ERROR,
    };
    #[allow(dead_code)]
    const WARN: Self = Self {
        value: ffi::LevelValue::WARN,
    };
    #[allow(dead_code)]
    const INFO: Self = Self {
        value: ffi::LevelValue::INFO,
    };
    #[allow(dead_code)]
    const DEBUG: Self = Self {
        value: ffi::LevelValue::DEBUG,
    };
    #[allow(dead_code)]
    const TRACE: Self = Self {
        value: ffi::LevelValue::TRACE,
    };

    pub fn as_str(&self) -> &'static str {
        match self.value {
            ffi::LevelValue::ERROR => tracing::Level::ERROR.as_str(),
            ffi::LevelValue::WARN => tracing::Level::WARN.as_str(),
            ffi::LevelValue::INFO => tracing::Level::INFO.as_str(),
            ffi::LevelValue::DEBUG => tracing::Level::DEBUG.as_str(),
            ffi::LevelValue::TRACE => tracing::Level::TRACE.as_str(),
            _ => "unknown",
        }
    }

    pub fn is_enabled(&self) -> bool {
        let tlevel: tracing::Level = self.into();
        tlevel <= tracing::level_filters::STATIC_MAX_LEVEL
            && tlevel <= tracing::level_filters::LevelFilter::current()
    }
}

impl From<&ffi::Level> for tracing::Level {
    fn from(value: &ffi::Level) -> Self {
        match value.value {
            ffi::LevelValue::ERROR => tracing::Level::ERROR,
            ffi::LevelValue::WARN => tracing::Level::WARN,
            ffi::LevelValue::INFO => tracing::Level::INFO,
            ffi::LevelValue::DEBUG => tracing::Level::DEBUG,
            ffi::LevelValue::TRACE => tracing::Level::TRACE,
            _ => tracing::Level::TRACE,
        }
    }
}

impl ffi::Kind {
    #[allow(dead_code)]
    const EVENT: Self = Self {
        value: ffi::KindValue::EVENT,
    };
    #[allow(dead_code)]
    const SPAN: Self = Self {
        value: ffi::KindValue::SPAN,
    };
    #[allow(dead_code)]
    const HINT: Self = Self {
        value: ffi::KindValue::HINT,
    };

    pub fn is_span(&self) -> bool {
        matches!(self.value, ffi::KindValue::SPAN)
    }
    pub fn is_event(&self) -> bool {
        matches!(self.value, ffi::KindValue::EVENT)
    }
    pub fn is_hint(&self) -> bool {
        !matches!(self.value, ffi::KindValue::SPAN) && !matches!(self.value, ffi::KindValue::EVENT)
    }
}

impl From<&ffi::Kind> for tracing::metadata::Kind {
    fn from(value: &ffi::Kind) -> Self {
        match value.value {
            ffi::KindValue::EVENT => tracing::metadata::Kind::EVENT,
            ffi::KindValue::SPAN => tracing::metadata::Kind::SPAN,
            ffi::KindValue::HINT => tracing::metadata::Kind::HINT,
            _ => tracing::metadata::Kind::HINT,
        }
    }
}

impl From<&ffi::Interest> for tracing_core::Interest {
    fn from(value: &ffi::Interest) -> Self {
        match value.value {
            ffi::InterestKind::NEVER => tracing_core::Interest::never(),
            ffi::InterestKind::SOMERTIMES => tracing_core::Interest::sometimes(),
            ffi::InterestKind::ALWAYS => tracing_core::Interest::always(),
            _ => tracing_core::Interest::sometimes(),
        }
    }
}
impl From<&tracing_core::Interest> for ffi::Interest {
    fn from(value: &tracing_core::Interest) -> Self {
        if value.is_never() {
            ffi::Interest {
                value: ffi::InterestKind::NEVER,
            }
        } else if value.is_always() {
            ffi::Interest {
                value: ffi::InterestKind::ALWAYS,
            }
        } else {
            ffi::Interest {
                value: ffi::InterestKind::SOMERTIMES,
            }
        }
    }
}

impl<'a> From<&ffi::Metadata<'a>> for tracing::Metadata<'a> {
    fn from(value: &ffi::Metadata<'a>) -> Self {
        tracing::Metadata::new(
            value.name,
            value.target,
            (&value.level).into(),
            Some(value.file),
            Some(value.line),
            None,
            tracing::field::FieldSet::new(
                value.fields,
                tracing::callsite::Identifier(value.callsite),
            ),
            (&value.kind).into(),
        )
    }
}

pub struct RustMetadata<'a>(pub tracing::Metadata<'a>);

impl<'a> RustMetadata<'a> {
    pub fn new(meta: &'static ffi::Metadata<'a>) -> Box<Self> {
        Box::new(Self(meta.into()))
    }
}

fn new_rust_metadata<'a>(meta: &'static ffi::Metadata<'a>) -> Box<RustMetadata<'a>> {
    RustMetadata::new(meta)
}

impl ffi::Callsite {
    #[allow(dead_code)]
    const UNREGISTERED: u8 = 0;
    #[allow(dead_code)]
    const REGISTERING: u8 = 1;
    #[allow(dead_code)]
    const REGISTERED: u8 = 2;

    #[allow(dead_code)]
    const INTEREST_NEVER: u8 = 0;
    #[allow(dead_code)]
    const INTEREST_SOMETIMES: u8 = 1;
    #[allow(dead_code)]
    const INTEREST_ALWAYS: u8 = 2;
    #[allow(dead_code)]
    const INTEREST_EMPTY: u8 = 0xFF;
}

impl tracing::Callsite for ffi::Callsite {
    #[inline(always)]
    fn metadata(&self) -> &tracing::Metadata<'_> {
        &self.get_meta().as_ref().0
    }
    fn set_interest(&self, interest: tracing_core::Interest) {
        self.store_interest(&(&interest).into());
    }
}

#[allow(clippy::borrowed_box)]
fn default_enabled_for_meta(interest: &ffi::Interest, meta: &Box<RustMetadata>) -> bool {
    let interest: tracing_core::Interest = interest.into();
    let meta = &meta.as_ref().0;
    interest.is_always() || tracing::dispatcher::get_default(|default| default.enabled(meta))
}

#[allow(clippy::borrowed_box)]
fn dispatch_tracing_event(meta: &'static Box<RustMetadata>) {
    tracing::Event::dispatch(&meta.0, &meta.0.fields().value_set(&[]));
}

macro_rules! dispatch_tracing_eventN {
    ($name:ident, ($($fN:ident),*)) => {
        #[allow(clippy::borrowed_box)]
        #[allow(clippy::too_many_arguments)]
        fn $name (meta: &'static Box<RustMetadata> $(, $fN : &ffi::FieldValue )*) {
            let mut iter = meta.0.fields().iter();
            let pairs = [
                $(
                    (
                        &::core::iter::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                        $fN.as_value(),
                    )
                ),*
            ];
            let val_set = meta.0.fields().value_set(&pairs);
            tracing::Event::dispatch(&meta.0, &val_set);
        }
    };
}

dispatch_tracing_eventN! {dispatch_tracing_event1, (f1)}
dispatch_tracing_eventN! {dispatch_tracing_event2, (f1, f2)}
dispatch_tracing_eventN! {dispatch_tracing_event3, (f1, f2, f3)}
dispatch_tracing_eventN! {dispatch_tracing_event4, (f1, f2, f3, f4)}
dispatch_tracing_eventN! {dispatch_tracing_event5, (f1, f2, f3, f4, f5)}
dispatch_tracing_eventN! {dispatch_tracing_event6, (f1, f2, f3, f4, f5, f6)}
dispatch_tracing_eventN! {dispatch_tracing_event7, (f1, f2, f3, f4, f5, f6, f7)}
dispatch_tracing_eventN! {dispatch_tracing_event8, (f1, f2, f3, f4, f5, f6, f7, f8)}
dispatch_tracing_eventN! {dispatch_tracing_event9, (f1, f2, f3, f4, f5, f6, f7, f8, f9)}
dispatch_tracing_eventN! {dispatch_tracing_event10, (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10)}

pub struct DisplayValue(Box<dyn tracing::Value>);
pub fn string_to_display_value(value: String) -> Box<DisplayValue> {
    Box::new(DisplayValue(Box::new(tracing::field::display(value))))
}

impl DisplayValue {
    pub fn as_value(&self) -> &dyn tracing::Value {
        &self.0
    }
}

impl ffi::FieldValue {
    fn as_value(&self) -> Option<&dyn tracing::field::Value> {
        match self.get_type() {
            ffi::FieldValueKind::U8 => Some(self.get_u8() as &dyn tracing::field::Value),
            ffi::FieldValueKind::U16 => Some(self.get_u16() as &dyn tracing::field::Value),
            ffi::FieldValueKind::U32 => Some(self.get_u32() as &dyn tracing::field::Value),
            ffi::FieldValueKind::U64 => Some(self.get_u64() as &dyn tracing::field::Value),
            ffi::FieldValueKind::I8 => Some(self.get_i8() as &dyn tracing::field::Value),
            ffi::FieldValueKind::I16 => Some(self.get_i16() as &dyn tracing::field::Value),
            ffi::FieldValueKind::I32 => Some(self.get_i32() as &dyn tracing::field::Value),
            ffi::FieldValueKind::I64 => Some(self.get_i64() as &dyn tracing::field::Value),
            ffi::FieldValueKind::F32 => Some(self.get_f32() as &dyn tracing::field::Value),
            ffi::FieldValueKind::F64 => Some(self.get_f64() as &dyn tracing::field::Value),
            ffi::FieldValueKind::STRING => Some(self.get_string() as &dyn tracing::field::Value),
            ffi::FieldValueKind::STR => Some(self.get_str() as &dyn tracing::field::Value),
            ffi::FieldValueKind::BOOL => Some(self.get_bool() as &dyn tracing::field::Value),
            ffi::FieldValueKind::DEBUG => match self.get_debug() {
                Ok(s) => Some(s.as_value()),
                Err(_) => None,
            },
            ffi::FieldValueKind::EMPTY => None, // no printing emptys
            _ => None,
        }
    }
}

pub struct Span(tracing::Span);

#[allow(clippy::borrowed_box)]
fn new_span(meta: &'static Box<RustMetadata>) -> Box<Span> {
    Box::new(Span(tracing::Span::new(
        &meta.0,
        &meta.0.fields().value_set(&[]),
    )))
}
#[allow(clippy::borrowed_box)]
fn new_disabled_span(meta: &'static Box<RustMetadata>) -> Box<Span> {
    Box::new(Span(tracing::Span::new_disabled(&meta.0)))
}

fn current_span() -> Box<Span> {
    Box::new(Span(tracing::Span::current()))
}

macro_rules! new_spanN {
    ($name:ident, ($($fN:ident),*)) => {
        #[allow(clippy::borrowed_box)]
        #[allow(clippy::too_many_arguments)]
        fn $name (meta: &'static Box<RustMetadata> $(, $fN : &ffi::FieldValue )*) -> Box<Span> {
            let mut iter = meta.0.fields().iter();
            let pairs = [
                $(
                    (
                        &::core::iter::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                        $fN.as_value(),
                    )
                ),*
            ];
            let val_set = meta.0.fields().value_set(&pairs);
            Box::new(Span(tracing::Span::new(
                &meta.0,
                &val_set,
            )))
        }
    };
}

new_spanN! {new_span1, (f1)}
new_spanN! {new_span2, (f1, f2)}
new_spanN! {new_span3, (f1, f2, f3)}
new_spanN! {new_span4, (f1, f2, f3, f4)}
new_spanN! {new_span5, (f1, f2, f3, f4, f5)}
new_spanN! {new_span6, (f1, f2, f3, f4, f5, f6)}
new_spanN! {new_span7, (f1, f2, f3, f4, f5, f6, f7)}
new_spanN! {new_span8, (f1, f2, f3, f4, f5, f6, f7, f8)}
new_spanN! {new_span9, (f1, f2, f3, f4, f5, f6, f7, f8, f9)}
new_spanN! {new_span10, (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10)}

pub struct Entered<'a>(#[allow(dead_code)] tracing::span::Entered<'a>);

impl Span {
    pub fn enter(&self) -> Box<Entered> {
        Box::new(Entered(self.0.enter()))
    }

    pub fn has_field(&self, field: &str) -> bool {
        self.0.has_field(field)
    }

    pub fn record(&self, field: &str, value: &ffi::FieldValue) -> &Self {
        self.0.record(field, value.as_value());
        self
    }
    pub fn is_none(&self) -> bool {
        self.0.is_none()
    }

    pub fn is_disabeld(&self) -> bool {
        self.0.is_disabled()
    }

    fn in_scope(&self, f: &ffi::ScopeLambda) {
        let _guard = self.0.enter();
        f.call();
    }
}

/// for cargo expand inspection only
mod unused {
    #[allow(dead_code)]
    fn test_tracing_event() {
        tracing::event!(tracing::Level::INFO, test = 5, "messge in event");
    }
    #[allow(dead_code)]
    fn test_tracing_span() {
        let v = 5;
        let _span = tracing::span!(tracing::Level::TRACE, "name of span", v);
    }
}