-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathgenerated_trace.go
1215 lines (1068 loc) · 39.4 KB
/
generated_trace.go
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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by "model/internal/cmd/pdatagen/main.go". DO NOT EDIT.
// To regenerate this file run "go run model/internal/cmd/pdatagen/main.go".
package pdata
import (
"sort"
otlptrace "go.opentelemetry.io/collector/model/internal/data/protogen/trace/v1"
)
// ResourceSpansSlice logically represents a slice of ResourceSpans.
//
// This is a reference type. If passed by value and callee modifies it, the
// caller will see the modification.
//
// Must use NewResourceSpansSlice function to create new instances.
// Important: zero-initialized instance is not valid for use.
type ResourceSpansSlice struct {
// orig points to the slice otlptrace.ResourceSpans field contained somewhere else.
// We use pointer-to-slice to be able to modify it in functions like EnsureCapacity.
orig *[]*otlptrace.ResourceSpans
}
func newResourceSpansSlice(orig *[]*otlptrace.ResourceSpans) ResourceSpansSlice {
return ResourceSpansSlice{orig}
}
// NewResourceSpansSlice creates a ResourceSpansSlice with 0 elements.
// Can use "EnsureCapacity" to initialize with a given capacity.
func NewResourceSpansSlice() ResourceSpansSlice {
orig := []*otlptrace.ResourceSpans(nil)
return ResourceSpansSlice{&orig}
}
// Len returns the number of elements in the slice.
//
// Returns "0" for a newly instance created with "NewResourceSpansSlice()".
func (es ResourceSpansSlice) Len() int {
return len(*es.orig)
}
// At returns the element at the given index.
//
// This function is used mostly for iterating over all the values in the slice:
// for i := 0; i < es.Len(); i++ {
// e := es.At(i)
// ... // Do something with the element
// }
func (es ResourceSpansSlice) At(ix int) ResourceSpans {
return newResourceSpans((*es.orig)[ix])
}
// CopyTo copies all elements from the current slice to the dest.
func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) {
srcLen := es.Len()
destCap := cap(*dest.orig)
if srcLen <= destCap {
(*dest.orig) = (*dest.orig)[:srcLen:destCap]
for i := range *es.orig {
newResourceSpans((*es.orig)[i]).CopyTo(newResourceSpans((*dest.orig)[i]))
}
return
}
origs := make([]otlptrace.ResourceSpans, srcLen)
wrappers := make([]*otlptrace.ResourceSpans, srcLen)
for i := range *es.orig {
wrappers[i] = &origs[i]
newResourceSpans((*es.orig)[i]).CopyTo(newResourceSpans(wrappers[i]))
}
*dest.orig = wrappers
}
// EnsureCapacity is an operation that ensures the slice has at least the specified capacity.
// 1. If the newCap <= cap then no change in capacity.
// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap.
//
// Here is how a new ResourceSpansSlice can be initialized:
// es := NewResourceSpansSlice()
// es.EnsureCapacity(4)
// for i := 0; i < 4; i++ {
// e := es.AppendEmpty()
// // Here should set all the values for e.
// }
func (es ResourceSpansSlice) EnsureCapacity(newCap int) {
oldCap := cap(*es.orig)
if newCap <= oldCap {
return
}
newOrig := make([]*otlptrace.ResourceSpans, len(*es.orig), newCap)
copy(newOrig, *es.orig)
*es.orig = newOrig
}
// AppendEmpty will append to the end of the slice an empty ResourceSpans.
// It returns the newly added ResourceSpans.
func (es ResourceSpansSlice) AppendEmpty() ResourceSpans {
*es.orig = append(*es.orig, &otlptrace.ResourceSpans{})
return es.At(es.Len() - 1)
}
// Sort sorts the ResourceSpans elements within ResourceSpansSlice given the
// provided less function so that two instances of ResourceSpansSlice
// can be compared.
//
// Returns the same instance to allow nicer code like:
// lessFunc := func(a, b ResourceSpans) bool {
// return a.Name() < b.Name() // choose any comparison here
// }
// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc))
func (es ResourceSpansSlice) Sort(less func(a, b ResourceSpans) bool) ResourceSpansSlice {
sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) })
return es
}
// MoveAndAppendTo moves all elements from the current slice and appends them to the dest.
// The current slice will be cleared.
func (es ResourceSpansSlice) MoveAndAppendTo(dest ResourceSpansSlice) {
if *dest.orig == nil {
// We can simply move the entire vector and avoid any allocations.
*dest.orig = *es.orig
} else {
*dest.orig = append(*dest.orig, *es.orig...)
}
*es.orig = nil
}
// RemoveIf calls f sequentially for each element present in the slice.
// If f returns true, the element is removed from the slice.
func (es ResourceSpansSlice) RemoveIf(f func(ResourceSpans) bool) {
newLen := 0
for i := 0; i < len(*es.orig); i++ {
if f(es.At(i)) {
continue
}
if newLen == i {
// Nothing to move, element is at the right place.
newLen++
continue
}
(*es.orig)[newLen] = (*es.orig)[i]
newLen++
}
// TODO: Prevent memory leak by erasing truncated values.
*es.orig = (*es.orig)[:newLen]
}
// ResourceSpans is a collection of spans from a Resource.
//
// This is a reference type, if passed by value and callee modifies it the
// caller will see the modification.
//
// Must use NewResourceSpans function to create new instances.
// Important: zero-initialized instance is not valid for use.
//
type ResourceSpans struct {
orig *otlptrace.ResourceSpans
}
func newResourceSpans(orig *otlptrace.ResourceSpans) ResourceSpans {
return ResourceSpans{orig: orig}
}
// NewResourceSpans creates a new empty ResourceSpans.
//
// This must be used only in testing code since no "Set" method available.
func NewResourceSpans() ResourceSpans {
return newResourceSpans(&otlptrace.ResourceSpans{})
}
// MoveTo moves all properties from the current struct to dest
// reseting the current instance to its zero value
func (ms ResourceSpans) MoveTo(dest ResourceSpans) {
*dest.orig = *ms.orig
*ms.orig = otlptrace.ResourceSpans{}
}
// Resource returns the resource associated with this ResourceSpans.
func (ms ResourceSpans) Resource() Resource {
return newResource(&(*ms.orig).Resource)
}
// SchemaUrl returns the schemaurl associated with this ResourceSpans.
func (ms ResourceSpans) SchemaUrl() string {
return (*ms.orig).SchemaUrl
}
// SetSchemaUrl replaces the schemaurl associated with this ResourceSpans.
func (ms ResourceSpans) SetSchemaUrl(v string) {
(*ms.orig).SchemaUrl = v
}
// InstrumentationLibrarySpans returns the InstrumentationLibrarySpans associated with this ResourceSpans.
func (ms ResourceSpans) InstrumentationLibrarySpans() InstrumentationLibrarySpansSlice {
return newInstrumentationLibrarySpansSlice(&(*ms.orig).InstrumentationLibrarySpans)
}
// CopyTo copies all properties from the current struct to the dest.
func (ms ResourceSpans) CopyTo(dest ResourceSpans) {
ms.Resource().CopyTo(dest.Resource())
dest.SetSchemaUrl(ms.SchemaUrl())
ms.InstrumentationLibrarySpans().CopyTo(dest.InstrumentationLibrarySpans())
}
// InstrumentationLibrarySpansSlice logically represents a slice of InstrumentationLibrarySpans.
//
// This is a reference type. If passed by value and callee modifies it, the
// caller will see the modification.
//
// Must use NewInstrumentationLibrarySpansSlice function to create new instances.
// Important: zero-initialized instance is not valid for use.
type InstrumentationLibrarySpansSlice struct {
// orig points to the slice otlptrace.InstrumentationLibrarySpans field contained somewhere else.
// We use pointer-to-slice to be able to modify it in functions like EnsureCapacity.
orig *[]*otlptrace.InstrumentationLibrarySpans
}
func newInstrumentationLibrarySpansSlice(orig *[]*otlptrace.InstrumentationLibrarySpans) InstrumentationLibrarySpansSlice {
return InstrumentationLibrarySpansSlice{orig}
}
// NewInstrumentationLibrarySpansSlice creates a InstrumentationLibrarySpansSlice with 0 elements.
// Can use "EnsureCapacity" to initialize with a given capacity.
func NewInstrumentationLibrarySpansSlice() InstrumentationLibrarySpansSlice {
orig := []*otlptrace.InstrumentationLibrarySpans(nil)
return InstrumentationLibrarySpansSlice{&orig}
}
// Len returns the number of elements in the slice.
//
// Returns "0" for a newly instance created with "NewInstrumentationLibrarySpansSlice()".
func (es InstrumentationLibrarySpansSlice) Len() int {
return len(*es.orig)
}
// At returns the element at the given index.
//
// This function is used mostly for iterating over all the values in the slice:
// for i := 0; i < es.Len(); i++ {
// e := es.At(i)
// ... // Do something with the element
// }
func (es InstrumentationLibrarySpansSlice) At(ix int) InstrumentationLibrarySpans {
return newInstrumentationLibrarySpans((*es.orig)[ix])
}
// CopyTo copies all elements from the current slice to the dest.
func (es InstrumentationLibrarySpansSlice) CopyTo(dest InstrumentationLibrarySpansSlice) {
srcLen := es.Len()
destCap := cap(*dest.orig)
if srcLen <= destCap {
(*dest.orig) = (*dest.orig)[:srcLen:destCap]
for i := range *es.orig {
newInstrumentationLibrarySpans((*es.orig)[i]).CopyTo(newInstrumentationLibrarySpans((*dest.orig)[i]))
}
return
}
origs := make([]otlptrace.InstrumentationLibrarySpans, srcLen)
wrappers := make([]*otlptrace.InstrumentationLibrarySpans, srcLen)
for i := range *es.orig {
wrappers[i] = &origs[i]
newInstrumentationLibrarySpans((*es.orig)[i]).CopyTo(newInstrumentationLibrarySpans(wrappers[i]))
}
*dest.orig = wrappers
}
// EnsureCapacity is an operation that ensures the slice has at least the specified capacity.
// 1. If the newCap <= cap then no change in capacity.
// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap.
//
// Here is how a new InstrumentationLibrarySpansSlice can be initialized:
// es := NewInstrumentationLibrarySpansSlice()
// es.EnsureCapacity(4)
// for i := 0; i < 4; i++ {
// e := es.AppendEmpty()
// // Here should set all the values for e.
// }
func (es InstrumentationLibrarySpansSlice) EnsureCapacity(newCap int) {
oldCap := cap(*es.orig)
if newCap <= oldCap {
return
}
newOrig := make([]*otlptrace.InstrumentationLibrarySpans, len(*es.orig), newCap)
copy(newOrig, *es.orig)
*es.orig = newOrig
}
// AppendEmpty will append to the end of the slice an empty InstrumentationLibrarySpans.
// It returns the newly added InstrumentationLibrarySpans.
func (es InstrumentationLibrarySpansSlice) AppendEmpty() InstrumentationLibrarySpans {
*es.orig = append(*es.orig, &otlptrace.InstrumentationLibrarySpans{})
return es.At(es.Len() - 1)
}
// Sort sorts the InstrumentationLibrarySpans elements within InstrumentationLibrarySpansSlice given the
// provided less function so that two instances of InstrumentationLibrarySpansSlice
// can be compared.
//
// Returns the same instance to allow nicer code like:
// lessFunc := func(a, b InstrumentationLibrarySpans) bool {
// return a.Name() < b.Name() // choose any comparison here
// }
// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc))
func (es InstrumentationLibrarySpansSlice) Sort(less func(a, b InstrumentationLibrarySpans) bool) InstrumentationLibrarySpansSlice {
sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) })
return es
}
// MoveAndAppendTo moves all elements from the current slice and appends them to the dest.
// The current slice will be cleared.
func (es InstrumentationLibrarySpansSlice) MoveAndAppendTo(dest InstrumentationLibrarySpansSlice) {
if *dest.orig == nil {
// We can simply move the entire vector and avoid any allocations.
*dest.orig = *es.orig
} else {
*dest.orig = append(*dest.orig, *es.orig...)
}
*es.orig = nil
}
// RemoveIf calls f sequentially for each element present in the slice.
// If f returns true, the element is removed from the slice.
func (es InstrumentationLibrarySpansSlice) RemoveIf(f func(InstrumentationLibrarySpans) bool) {
newLen := 0
for i := 0; i < len(*es.orig); i++ {
if f(es.At(i)) {
continue
}
if newLen == i {
// Nothing to move, element is at the right place.
newLen++
continue
}
(*es.orig)[newLen] = (*es.orig)[i]
newLen++
}
// TODO: Prevent memory leak by erasing truncated values.
*es.orig = (*es.orig)[:newLen]
}
// InstrumentationLibrarySpans is a collection of spans from a LibraryInstrumentation.
//
// This is a reference type, if passed by value and callee modifies it the
// caller will see the modification.
//
// Must use NewInstrumentationLibrarySpans function to create new instances.
// Important: zero-initialized instance is not valid for use.
//
type InstrumentationLibrarySpans struct {
orig *otlptrace.InstrumentationLibrarySpans
}
func newInstrumentationLibrarySpans(orig *otlptrace.InstrumentationLibrarySpans) InstrumentationLibrarySpans {
return InstrumentationLibrarySpans{orig: orig}
}
// NewInstrumentationLibrarySpans creates a new empty InstrumentationLibrarySpans.
//
// This must be used only in testing code since no "Set" method available.
func NewInstrumentationLibrarySpans() InstrumentationLibrarySpans {
return newInstrumentationLibrarySpans(&otlptrace.InstrumentationLibrarySpans{})
}
// MoveTo moves all properties from the current struct to dest
// reseting the current instance to its zero value
func (ms InstrumentationLibrarySpans) MoveTo(dest InstrumentationLibrarySpans) {
*dest.orig = *ms.orig
*ms.orig = otlptrace.InstrumentationLibrarySpans{}
}
// InstrumentationLibrary returns the instrumentationlibrary associated with this InstrumentationLibrarySpans.
func (ms InstrumentationLibrarySpans) InstrumentationLibrary() InstrumentationLibrary {
return newInstrumentationLibrary(&(*ms.orig).InstrumentationLibrary)
}
// SchemaUrl returns the schemaurl associated with this InstrumentationLibrarySpans.
func (ms InstrumentationLibrarySpans) SchemaUrl() string {
return (*ms.orig).SchemaUrl
}
// SetSchemaUrl replaces the schemaurl associated with this InstrumentationLibrarySpans.
func (ms InstrumentationLibrarySpans) SetSchemaUrl(v string) {
(*ms.orig).SchemaUrl = v
}
// Spans returns the Spans associated with this InstrumentationLibrarySpans.
func (ms InstrumentationLibrarySpans) Spans() SpanSlice {
return newSpanSlice(&(*ms.orig).Spans)
}
// CopyTo copies all properties from the current struct to the dest.
func (ms InstrumentationLibrarySpans) CopyTo(dest InstrumentationLibrarySpans) {
ms.InstrumentationLibrary().CopyTo(dest.InstrumentationLibrary())
dest.SetSchemaUrl(ms.SchemaUrl())
ms.Spans().CopyTo(dest.Spans())
}
// SpanSlice logically represents a slice of Span.
//
// This is a reference type. If passed by value and callee modifies it, the
// caller will see the modification.
//
// Must use NewSpanSlice function to create new instances.
// Important: zero-initialized instance is not valid for use.
type SpanSlice struct {
// orig points to the slice otlptrace.Span field contained somewhere else.
// We use pointer-to-slice to be able to modify it in functions like EnsureCapacity.
orig *[]*otlptrace.Span
}
func newSpanSlice(orig *[]*otlptrace.Span) SpanSlice {
return SpanSlice{orig}
}
// NewSpanSlice creates a SpanSlice with 0 elements.
// Can use "EnsureCapacity" to initialize with a given capacity.
func NewSpanSlice() SpanSlice {
orig := []*otlptrace.Span(nil)
return SpanSlice{&orig}
}
// Len returns the number of elements in the slice.
//
// Returns "0" for a newly instance created with "NewSpanSlice()".
func (es SpanSlice) Len() int {
return len(*es.orig)
}
// At returns the element at the given index.
//
// This function is used mostly for iterating over all the values in the slice:
// for i := 0; i < es.Len(); i++ {
// e := es.At(i)
// ... // Do something with the element
// }
func (es SpanSlice) At(ix int) Span {
return newSpan((*es.orig)[ix])
}
// CopyTo copies all elements from the current slice to the dest.
func (es SpanSlice) CopyTo(dest SpanSlice) {
srcLen := es.Len()
destCap := cap(*dest.orig)
if srcLen <= destCap {
(*dest.orig) = (*dest.orig)[:srcLen:destCap]
for i := range *es.orig {
newSpan((*es.orig)[i]).CopyTo(newSpan((*dest.orig)[i]))
}
return
}
origs := make([]otlptrace.Span, srcLen)
wrappers := make([]*otlptrace.Span, srcLen)
for i := range *es.orig {
wrappers[i] = &origs[i]
newSpan((*es.orig)[i]).CopyTo(newSpan(wrappers[i]))
}
*dest.orig = wrappers
}
// EnsureCapacity is an operation that ensures the slice has at least the specified capacity.
// 1. If the newCap <= cap then no change in capacity.
// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap.
//
// Here is how a new SpanSlice can be initialized:
// es := NewSpanSlice()
// es.EnsureCapacity(4)
// for i := 0; i < 4; i++ {
// e := es.AppendEmpty()
// // Here should set all the values for e.
// }
func (es SpanSlice) EnsureCapacity(newCap int) {
oldCap := cap(*es.orig)
if newCap <= oldCap {
return
}
newOrig := make([]*otlptrace.Span, len(*es.orig), newCap)
copy(newOrig, *es.orig)
*es.orig = newOrig
}
// AppendEmpty will append to the end of the slice an empty Span.
// It returns the newly added Span.
func (es SpanSlice) AppendEmpty() Span {
*es.orig = append(*es.orig, &otlptrace.Span{})
return es.At(es.Len() - 1)
}
// Sort sorts the Span elements within SpanSlice given the
// provided less function so that two instances of SpanSlice
// can be compared.
//
// Returns the same instance to allow nicer code like:
// lessFunc := func(a, b Span) bool {
// return a.Name() < b.Name() // choose any comparison here
// }
// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc))
func (es SpanSlice) Sort(less func(a, b Span) bool) SpanSlice {
sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) })
return es
}
// MoveAndAppendTo moves all elements from the current slice and appends them to the dest.
// The current slice will be cleared.
func (es SpanSlice) MoveAndAppendTo(dest SpanSlice) {
if *dest.orig == nil {
// We can simply move the entire vector and avoid any allocations.
*dest.orig = *es.orig
} else {
*dest.orig = append(*dest.orig, *es.orig...)
}
*es.orig = nil
}
// RemoveIf calls f sequentially for each element present in the slice.
// If f returns true, the element is removed from the slice.
func (es SpanSlice) RemoveIf(f func(Span) bool) {
newLen := 0
for i := 0; i < len(*es.orig); i++ {
if f(es.At(i)) {
continue
}
if newLen == i {
// Nothing to move, element is at the right place.
newLen++
continue
}
(*es.orig)[newLen] = (*es.orig)[i]
newLen++
}
// TODO: Prevent memory leak by erasing truncated values.
*es.orig = (*es.orig)[:newLen]
}
// Span represents a single operation within a trace.
// See Span definition in OTLP: https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto
//
// This is a reference type, if passed by value and callee modifies it the
// caller will see the modification.
//
// Must use NewSpan function to create new instances.
// Important: zero-initialized instance is not valid for use.
//
type Span struct {
orig *otlptrace.Span
}
func newSpan(orig *otlptrace.Span) Span {
return Span{orig: orig}
}
// NewSpan creates a new empty Span.
//
// This must be used only in testing code since no "Set" method available.
func NewSpan() Span {
return newSpan(&otlptrace.Span{})
}
// MoveTo moves all properties from the current struct to dest
// reseting the current instance to its zero value
func (ms Span) MoveTo(dest Span) {
*dest.orig = *ms.orig
*ms.orig = otlptrace.Span{}
}
// TraceID returns the traceid associated with this Span.
func (ms Span) TraceID() TraceID {
return TraceID{orig: ((*ms.orig).TraceId)}
}
// SetTraceID replaces the traceid associated with this Span.
func (ms Span) SetTraceID(v TraceID) {
(*ms.orig).TraceId = v.orig
}
// SpanID returns the spanid associated with this Span.
func (ms Span) SpanID() SpanID {
return SpanID{orig: ((*ms.orig).SpanId)}
}
// SetSpanID replaces the spanid associated with this Span.
func (ms Span) SetSpanID(v SpanID) {
(*ms.orig).SpanId = v.orig
}
// TraceState returns the tracestate associated with this Span.
func (ms Span) TraceState() TraceState {
return TraceState((*ms.orig).TraceState)
}
// SetTraceState replaces the tracestate associated with this Span.
func (ms Span) SetTraceState(v TraceState) {
(*ms.orig).TraceState = string(v)
}
// ParentSpanID returns the parentspanid associated with this Span.
func (ms Span) ParentSpanID() SpanID {
return SpanID{orig: ((*ms.orig).ParentSpanId)}
}
// SetParentSpanID replaces the parentspanid associated with this Span.
func (ms Span) SetParentSpanID(v SpanID) {
(*ms.orig).ParentSpanId = v.orig
}
// Name returns the name associated with this Span.
func (ms Span) Name() string {
return (*ms.orig).Name
}
// SetName replaces the name associated with this Span.
func (ms Span) SetName(v string) {
(*ms.orig).Name = v
}
// Kind returns the kind associated with this Span.
func (ms Span) Kind() SpanKind {
return SpanKind((*ms.orig).Kind)
}
// SetKind replaces the kind associated with this Span.
func (ms Span) SetKind(v SpanKind) {
(*ms.orig).Kind = otlptrace.Span_SpanKind(v)
}
// StartTimestamp returns the starttimestamp associated with this Span.
func (ms Span) StartTimestamp() Timestamp {
return Timestamp((*ms.orig).StartTimeUnixNano)
}
// SetStartTimestamp replaces the starttimestamp associated with this Span.
func (ms Span) SetStartTimestamp(v Timestamp) {
(*ms.orig).StartTimeUnixNano = uint64(v)
}
// EndTimestamp returns the endtimestamp associated with this Span.
func (ms Span) EndTimestamp() Timestamp {
return Timestamp((*ms.orig).EndTimeUnixNano)
}
// SetEndTimestamp replaces the endtimestamp associated with this Span.
func (ms Span) SetEndTimestamp(v Timestamp) {
(*ms.orig).EndTimeUnixNano = uint64(v)
}
// Attributes returns the Attributes associated with this Span.
func (ms Span) Attributes() AttributeMap {
return newAttributeMap(&(*ms.orig).Attributes)
}
// DroppedAttributesCount returns the droppedattributescount associated with this Span.
func (ms Span) DroppedAttributesCount() uint32 {
return (*ms.orig).DroppedAttributesCount
}
// SetDroppedAttributesCount replaces the droppedattributescount associated with this Span.
func (ms Span) SetDroppedAttributesCount(v uint32) {
(*ms.orig).DroppedAttributesCount = v
}
// Events returns the Events associated with this Span.
func (ms Span) Events() SpanEventSlice {
return newSpanEventSlice(&(*ms.orig).Events)
}
// DroppedEventsCount returns the droppedeventscount associated with this Span.
func (ms Span) DroppedEventsCount() uint32 {
return (*ms.orig).DroppedEventsCount
}
// SetDroppedEventsCount replaces the droppedeventscount associated with this Span.
func (ms Span) SetDroppedEventsCount(v uint32) {
(*ms.orig).DroppedEventsCount = v
}
// Links returns the Links associated with this Span.
func (ms Span) Links() SpanLinkSlice {
return newSpanLinkSlice(&(*ms.orig).Links)
}
// DroppedLinksCount returns the droppedlinkscount associated with this Span.
func (ms Span) DroppedLinksCount() uint32 {
return (*ms.orig).DroppedLinksCount
}
// SetDroppedLinksCount replaces the droppedlinkscount associated with this Span.
func (ms Span) SetDroppedLinksCount(v uint32) {
(*ms.orig).DroppedLinksCount = v
}
// Status returns the status associated with this Span.
func (ms Span) Status() SpanStatus {
return newSpanStatus(&(*ms.orig).Status)
}
// CopyTo copies all properties from the current struct to the dest.
func (ms Span) CopyTo(dest Span) {
dest.SetTraceID(ms.TraceID())
dest.SetSpanID(ms.SpanID())
dest.SetTraceState(ms.TraceState())
dest.SetParentSpanID(ms.ParentSpanID())
dest.SetName(ms.Name())
dest.SetKind(ms.Kind())
dest.SetStartTimestamp(ms.StartTimestamp())
dest.SetEndTimestamp(ms.EndTimestamp())
ms.Attributes().CopyTo(dest.Attributes())
dest.SetDroppedAttributesCount(ms.DroppedAttributesCount())
ms.Events().CopyTo(dest.Events())
dest.SetDroppedEventsCount(ms.DroppedEventsCount())
ms.Links().CopyTo(dest.Links())
dest.SetDroppedLinksCount(ms.DroppedLinksCount())
ms.Status().CopyTo(dest.Status())
}
// SpanEventSlice logically represents a slice of SpanEvent.
//
// This is a reference type. If passed by value and callee modifies it, the
// caller will see the modification.
//
// Must use NewSpanEventSlice function to create new instances.
// Important: zero-initialized instance is not valid for use.
type SpanEventSlice struct {
// orig points to the slice otlptrace.Span_Event field contained somewhere else.
// We use pointer-to-slice to be able to modify it in functions like EnsureCapacity.
orig *[]*otlptrace.Span_Event
}
func newSpanEventSlice(orig *[]*otlptrace.Span_Event) SpanEventSlice {
return SpanEventSlice{orig}
}
// NewSpanEventSlice creates a SpanEventSlice with 0 elements.
// Can use "EnsureCapacity" to initialize with a given capacity.
func NewSpanEventSlice() SpanEventSlice {
orig := []*otlptrace.Span_Event(nil)
return SpanEventSlice{&orig}
}
// Len returns the number of elements in the slice.
//
// Returns "0" for a newly instance created with "NewSpanEventSlice()".
func (es SpanEventSlice) Len() int {
return len(*es.orig)
}
// At returns the element at the given index.
//
// This function is used mostly for iterating over all the values in the slice:
// for i := 0; i < es.Len(); i++ {
// e := es.At(i)
// ... // Do something with the element
// }
func (es SpanEventSlice) At(ix int) SpanEvent {
return newSpanEvent((*es.orig)[ix])
}
// CopyTo copies all elements from the current slice to the dest.
func (es SpanEventSlice) CopyTo(dest SpanEventSlice) {
srcLen := es.Len()
destCap := cap(*dest.orig)
if srcLen <= destCap {
(*dest.orig) = (*dest.orig)[:srcLen:destCap]
for i := range *es.orig {
newSpanEvent((*es.orig)[i]).CopyTo(newSpanEvent((*dest.orig)[i]))
}
return
}
origs := make([]otlptrace.Span_Event, srcLen)
wrappers := make([]*otlptrace.Span_Event, srcLen)
for i := range *es.orig {
wrappers[i] = &origs[i]
newSpanEvent((*es.orig)[i]).CopyTo(newSpanEvent(wrappers[i]))
}
*dest.orig = wrappers
}
// EnsureCapacity is an operation that ensures the slice has at least the specified capacity.
// 1. If the newCap <= cap then no change in capacity.
// 2. If the newCap > cap then the slice capacity will be expanded to equal newCap.
//
// Here is how a new SpanEventSlice can be initialized:
// es := NewSpanEventSlice()
// es.EnsureCapacity(4)
// for i := 0; i < 4; i++ {
// e := es.AppendEmpty()
// // Here should set all the values for e.
// }
func (es SpanEventSlice) EnsureCapacity(newCap int) {
oldCap := cap(*es.orig)
if newCap <= oldCap {
return
}
newOrig := make([]*otlptrace.Span_Event, len(*es.orig), newCap)
copy(newOrig, *es.orig)
*es.orig = newOrig
}
// AppendEmpty will append to the end of the slice an empty SpanEvent.
// It returns the newly added SpanEvent.
func (es SpanEventSlice) AppendEmpty() SpanEvent {
*es.orig = append(*es.orig, &otlptrace.Span_Event{})
return es.At(es.Len() - 1)
}
// Sort sorts the SpanEvent elements within SpanEventSlice given the
// provided less function so that two instances of SpanEventSlice
// can be compared.
//
// Returns the same instance to allow nicer code like:
// lessFunc := func(a, b SpanEvent) bool {
// return a.Name() < b.Name() // choose any comparison here
// }
// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc))
func (es SpanEventSlice) Sort(less func(a, b SpanEvent) bool) SpanEventSlice {
sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) })
return es
}
// MoveAndAppendTo moves all elements from the current slice and appends them to the dest.
// The current slice will be cleared.
func (es SpanEventSlice) MoveAndAppendTo(dest SpanEventSlice) {
if *dest.orig == nil {
// We can simply move the entire vector and avoid any allocations.
*dest.orig = *es.orig
} else {
*dest.orig = append(*dest.orig, *es.orig...)
}
*es.orig = nil
}
// RemoveIf calls f sequentially for each element present in the slice.
// If f returns true, the element is removed from the slice.
func (es SpanEventSlice) RemoveIf(f func(SpanEvent) bool) {
newLen := 0
for i := 0; i < len(*es.orig); i++ {
if f(es.At(i)) {
continue
}
if newLen == i {
// Nothing to move, element is at the right place.
newLen++
continue
}
(*es.orig)[newLen] = (*es.orig)[i]
newLen++
}
// TODO: Prevent memory leak by erasing truncated values.
*es.orig = (*es.orig)[:newLen]
}
// SpanEvent is a time-stamped annotation of the span, consisting of user-supplied
// text description and key-value pairs. See OTLP for event definition.
//
// This is a reference type, if passed by value and callee modifies it the
// caller will see the modification.
//
// Must use NewSpanEvent function to create new instances.
// Important: zero-initialized instance is not valid for use.
//
type SpanEvent struct {
orig *otlptrace.Span_Event
}
func newSpanEvent(orig *otlptrace.Span_Event) SpanEvent {
return SpanEvent{orig: orig}
}
// NewSpanEvent creates a new empty SpanEvent.
//
// This must be used only in testing code since no "Set" method available.
func NewSpanEvent() SpanEvent {
return newSpanEvent(&otlptrace.Span_Event{})
}
// MoveTo moves all properties from the current struct to dest
// reseting the current instance to its zero value
func (ms SpanEvent) MoveTo(dest SpanEvent) {
*dest.orig = *ms.orig
*ms.orig = otlptrace.Span_Event{}
}
// Timestamp returns the timestamp associated with this SpanEvent.
func (ms SpanEvent) Timestamp() Timestamp {
return Timestamp((*ms.orig).TimeUnixNano)
}
// SetTimestamp replaces the timestamp associated with this SpanEvent.
func (ms SpanEvent) SetTimestamp(v Timestamp) {
(*ms.orig).TimeUnixNano = uint64(v)
}
// Name returns the name associated with this SpanEvent.
func (ms SpanEvent) Name() string {
return (*ms.orig).Name
}
// SetName replaces the name associated with this SpanEvent.
func (ms SpanEvent) SetName(v string) {
(*ms.orig).Name = v
}
// Attributes returns the Attributes associated with this SpanEvent.
func (ms SpanEvent) Attributes() AttributeMap {
return newAttributeMap(&(*ms.orig).Attributes)
}
// DroppedAttributesCount returns the droppedattributescount associated with this SpanEvent.
func (ms SpanEvent) DroppedAttributesCount() uint32 {
return (*ms.orig).DroppedAttributesCount
}
// SetDroppedAttributesCount replaces the droppedattributescount associated with this SpanEvent.
func (ms SpanEvent) SetDroppedAttributesCount(v uint32) {
(*ms.orig).DroppedAttributesCount = v
}
// CopyTo copies all properties from the current struct to the dest.
func (ms SpanEvent) CopyTo(dest SpanEvent) {
dest.SetTimestamp(ms.Timestamp())
dest.SetName(ms.Name())
ms.Attributes().CopyTo(dest.Attributes())
dest.SetDroppedAttributesCount(ms.DroppedAttributesCount())
}
// SpanLinkSlice logically represents a slice of SpanLink.
//
// This is a reference type. If passed by value and callee modifies it, the
// caller will see the modification.
//
// Must use NewSpanLinkSlice function to create new instances.
// Important: zero-initialized instance is not valid for use.
type SpanLinkSlice struct {
// orig points to the slice otlptrace.Span_Link field contained somewhere else.
// We use pointer-to-slice to be able to modify it in functions like EnsureCapacity.
orig *[]*otlptrace.Span_Link
}
func newSpanLinkSlice(orig *[]*otlptrace.Span_Link) SpanLinkSlice {
return SpanLinkSlice{orig}
}
// NewSpanLinkSlice creates a SpanLinkSlice with 0 elements.
// Can use "EnsureCapacity" to initialize with a given capacity.
func NewSpanLinkSlice() SpanLinkSlice {
orig := []*otlptrace.Span_Link(nil)
return SpanLinkSlice{&orig}
}
// Len returns the number of elements in the slice.
//
// Returns "0" for a newly instance created with "NewSpanLinkSlice()".
func (es SpanLinkSlice) Len() int {
return len(*es.orig)
}
// At returns the element at the given index.
//
// This function is used mostly for iterating over all the values in the slice:
// for i := 0; i < es.Len(); i++ {
// e := es.At(i)
// ... // Do something with the element
// }
func (es SpanLinkSlice) At(ix int) SpanLink {
return newSpanLink((*es.orig)[ix])
}
// CopyTo copies all elements from the current slice to the dest.
func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) {
srcLen := es.Len()
destCap := cap(*dest.orig)
if srcLen <= destCap {
(*dest.orig) = (*dest.orig)[:srcLen:destCap]
for i := range *es.orig {
newSpanLink((*es.orig)[i]).CopyTo(newSpanLink((*dest.orig)[i]))
}
return
}
origs := make([]otlptrace.Span_Link, srcLen)
wrappers := make([]*otlptrace.Span_Link, srcLen)
for i := range *es.orig {
wrappers[i] = &origs[i]
newSpanLink((*es.orig)[i]).CopyTo(newSpanLink(wrappers[i]))
}