-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotel.zzzgo
632 lines (590 loc) · 20.9 KB
/
otel.zzzgo
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
// TEMPLATE-FILE
// TEMPLATE-FILE
package xopotel
import (
"context"
"fmt"
"regexp"
"runtime"
"strconv"
"sync/atomic"
"time"
"github.com/xoplog/xop-go"
"github.com/xoplog/xop-go/xopbase"
"github.com/xoplog/xop-go/xopnum"
"github.com/xoplog/xop-go/xoptrace"
"github.com/google/uuid"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"
)
func xopTraceFromSpan(span oteltrace.Span) xoptrace.Trace {
var xoptrace xoptrace.Trace
sc := span.SpanContext()
xoptrace.TraceID().SetArray(sc.TraceID())
xoptrace.SpanID().SetArray(sc.SpanID())
xoptrace.Flags().SetArray([1]byte{byte(sc.TraceFlags())})
// xoptrace.Version().SetArray([1]byte{0})
return xoptrace
}
// SpanToLog allows xop to add logs to an existing OTEL span. log.Done() will be
// ignored for this span.
func SpanToLog(ctx context.Context, name string, extraModifiers ...xop.SeedModifier) *xop.Logger {
span := oteltrace.SpanFromContext(ctx)
xoptrace := xopTraceFromSpan(span)
tracer := span.TracerProvider().Tracer("xoputil")
log := xop.NewSeed(makeSeedModifier(ctx, tracer,
xop.WithTrace(xoptrace),
xop.WithBase(&logger{
id: "otel-" + uuid.New().String(),
doLogging: true,
ignoreDone: span,
tracer: tracer,
}),
)).SubSpan(name)
go func() {
<-ctx.Done()
log.Done()
}()
return log
}
func (_ idGenerator) NewIDs(ctx context.Context) (oteltrace.TraceID, oteltrace.SpanID) {
override := overrideFromContext(ctx)
traceID, spanID, _ := override.Get()
return traceID, spanID
}
func (_ idGenerator) NewSpanID(ctx context.Context, _ oteltrace.TraceID) oteltrace.SpanID {
override := overrideFromContext(ctx)
_, spanID, _ := override.Get()
return spanID
}
// SeedModifier provides a xop.SeedModifier to set up an OTEL Tracer as a xopbase.Logger
// so that xop logs are output through the OTEL Tracer.
//
// As of the writing of this comment, the Open Telemetry Go library does not support
// logging so to use it for logging purposes, log lines are sent as span "Events".
//
// The recommended way to create a TracerProvider includes using WithBatcher to
// control the flow of data to SpanExporters. The default configuration for the Batcher
// limits spans to 128 Events each. It imposes other limits too but the default event
// limit is the one that is likely to be hit with even modest usage.
//
// Using SeedModifier, the TraceProvider does not have to have been created using IDGenerator().
func SeedModifier(ctx context.Context, traceProvider oteltrace.TracerProvider) xop.SeedModifier {
tracer := traceProvider.Tracer("xopotel",
oteltrace.WithInstrumentationAttributes(
xopOTELVersion.String(xopotelVersionValue),
xopVersion.String(xopVersionValue),
),
oteltrace.WithInstrumentationVersion(xopotelVersionValue),
)
return makeSeedModifier(ctx, tracer)
}
func makeSeedModifier(ctx context.Context, tracer oteltrace.Tracer, extraModifiers ...xop.SeedModifier) xop.SeedModifier {
modifiers := []xop.SeedModifier{
xop.WithBase(&logger{
id: "otel-" + uuid.New().String(),
doLogging: true,
tracer: tracer,
spanFromContext: true,
}),
xop.WithContext(ctx),
xop.WithReactive(func(ctx context.Context, seed xop.Seed, nameOrDescription string, isChildSpan bool, ts time.Time) []xop.SeedModifier {
if isChildSpan {
ctx, span := buildSpan(ctx, ts, seed.Bundle(), nameOrDescription, tracer, nil)
return []xop.SeedModifier{
xop.WithContext(ctx),
xop.WithSpan(span.SpanContext().SpanID()),
}
}
parentCtx := ctx
bundle := seed.Bundle()
ctx, _, otelSpan := buildRequestSpan(ctx, ts, bundle, nameOrDescription, seed.SourceInfo(), tracer, nil)
if bundle.Parent.IsZero() {
parentSpan := oteltrace.SpanFromContext(parentCtx)
if parentSpan.SpanContext().HasTraceID() {
bundle.Parent.Flags().SetArray([1]byte{byte(parentSpan.SpanContext().TraceFlags())})
bundle.Parent.TraceID().SetArray(parentSpan.SpanContext().TraceID())
bundle.Parent.SpanID().SetArray(parentSpan.SpanContext().SpanID())
}
bundle.State.SetString(otelSpan.SpanContext().TraceState().String())
bundle.Trace.Flags().SetArray([1]byte{byte(otelSpan.SpanContext().TraceFlags())})
bundle.Trace.TraceID().SetArray(otelSpan.SpanContext().TraceID())
bundle.Trace.SpanID().SetArray(otelSpan.SpanContext().SpanID())
}
bundle.Trace.SpanID().SetArray(otelSpan.SpanContext().SpanID())
return []xop.SeedModifier{
xop.WithContext(ctx),
xop.WithBundle(bundle),
}
}),
}
return xop.CombineSeedModifiers(append(modifiers, extraModifiers...)...)
}
// BaseLogger provides SeedModifiers to set up an OTEL Tracer as a xopbase.Logger
// so that xop logs are output through the OTEL Tracer.
//
// As of the writing of this comment, the Open Telemetry Go library does not support
// logging so to use it for logging purposes, log lines are sent as span "Events".
//
// The recommended way to create a TracerProvider includes using WithBatcher to
// control the flow of data to SpanExporters. The default configuration for the Batcher
// limits spans to 128 Events each. It imposes other limits too but the default event
// limit is the one that is likely to be hit with even modest usage.
//
// The TracerProvider MUST be created with IDGenerator(). Without that, the SpanID
// created by Xop will be ignored and that will cause problems with propagation.
func BaseLogger(traceProvider oteltrace.TracerProvider) xopbase.Logger {
tracer := traceProvider.Tracer("xopotel",
oteltrace.WithInstrumentationAttributes(
xopOTELVersion.String(xopotelVersionValue),
xopVersion.String(xopVersionValue),
),
oteltrace.WithInstrumentationVersion(xopotelVersionValue),
)
return &logger{
id: "otel-" + uuid.New().String(),
doLogging: true,
tracer: tracer,
spanFromContext: false,
}
}
func (logger *logger) ID() string { return logger.id }
func (logger *logger) ReferencesKept() bool { return true }
func (logger *logger) Buffered() bool { return false }
func buildRequestSpan(ctx context.Context, ts time.Time, bundle xoptrace.Bundle, description string, sourceInfo xopbase.SourceInfo, tracer oteltrace.Tracer, bufferedRequest *bufferedRequest) (context.Context, bool, oteltrace.Span) {
spanKind := oteltrace.SpanKindServer
isXOP := sourceInfo.Source != otelDataSource
if !isXOP {
// replaying data originally coming from OTEL.
// The spanKind is encoded as the namespace.
if sk, ok := spanKindFromString[sourceInfo.Namespace]; ok {
spanKind = sk
}
}
opts := []oteltrace.SpanStartOption{
oteltrace.WithSpanKind(spanKind),
oteltrace.WithTimestamp(ts),
}
otelStuff := bufferedRequest.getStuff(bundle, true)
opts = append(opts, otelStuff.SpanOptions()...)
if bundle.Parent.TraceID().IsZero() {
opts = append(opts, oteltrace.WithNewRoot())
}
ctx, otelSpan := tracer.Start(overrideIntoContext(ctx, bundle), description, opts...)
if isXOP {
if !bundle.Baggage.IsZero() {
otelSpan.SetAttributes(xopBaggage.String(bundle.Baggage.String()))
}
otelSpan.SetAttributes(
xopVersion.String(xopVersionValue),
xopOTELVersion.String(xopotelVersionValue),
xopSource.String(sourceInfo.Source+" "+sourceInfo.SourceVersion.String()),
xopNamespace.String(sourceInfo.Namespace+" "+sourceInfo.NamespaceVersion.String()),
)
}
otelStuff.Set(otelSpan)
return ctx, isXOP, otelSpan
}
func (logger *logger) Request(ctx context.Context, ts time.Time, bundle xoptrace.Bundle, description string, sourceInfo xopbase.SourceInfo) xopbase.Request {
var otelSpan oteltrace.Span
var isXOP bool
if logger.spanFromContext {
otelSpan = oteltrace.SpanFromContext(ctx)
isXOP = sourceInfo.Source != otelDataSource
} else {
ctx, isXOP, otelSpan = buildRequestSpan(ctx, ts, bundle, description, sourceInfo, logger.tracer, logger.bufferedRequest)
}
r := &request{
span: &span{
logger: logger,
otelSpan: otelSpan,
ctx: ctx,
isXOP: isXOP,
},
attributesDefined: make(map[string]struct{}),
}
r.span.request = r
return r
}
func (request *request) SetErrorReporter(f func(error)) { request.errorReporter = f }
func (request *request) Flush() {}
func (request *request) Final() {}
func (span *span) Boring(_ bool) {}
func (span *span) ID() string { return span.logger.id }
func (span *span) Done(endTime time.Time, final bool) {
if !final {
return
}
if span.logger.ignoreDone == span.otelSpan {
// skip Done for spans passed in to SpanLog()
return
}
span.otelSpan.End(oteltrace.WithTimestamp(endTime))
}
func buildSpan(ctx context.Context, ts time.Time, bundle xoptrace.Bundle, description string, tracer oteltrace.Tracer, bufferedRequest *bufferedRequest) (context.Context, oteltrace.Span) {
opts := []oteltrace.SpanStartOption{
oteltrace.WithTimestamp(ts),
oteltrace.WithSpanKind(oteltrace.SpanKindInternal),
}
otelStuff := bufferedRequest.getStuff(bundle, true)
opts = append(opts, otelStuff.SpanOptions()...)
ctx, otelSpan := tracer.Start(overrideIntoContext(ctx, bundle), description, opts...)
otelStuff.Set(otelSpan)
return ctx, otelSpan
}
func (parentSpan *span) Span(ctx context.Context, ts time.Time, bundle xoptrace.Bundle, description string, spanSequenceCode string) xopbase.Span {
var otelSpan oteltrace.Span
if parentSpan.logger.spanFromContext {
otelSpan = oteltrace.SpanFromContext(ctx)
} else {
if parentSpan.logger.bufferedRequest != nil {
ctx = parentSpan.ctx
}
ctx, otelSpan = buildSpan(ctx, ts, bundle, description, parentSpan.logger.tracer, parentSpan.logger.bufferedRequest)
}
s := &span{
logger: parentSpan.logger,
otelSpan: otelSpan,
ctx: ctx,
request: parentSpan.request,
isXOP: parentSpan.isXOP,
}
if parentSpan.isXOP && spanSequenceCode != "" {
otelSpan.SetAttributes(xopSpanSequence.String(spanSequenceCode))
}
return s
}
func (span *span) NoPrefill() xopbase.Prefilled {
return &prefilled{
builderWithSpan: builderWithSpan{
span: span,
},
}
}
func (span *span) StartPrefill() xopbase.Prefilling {
return &prefilling{
builderWithSpan: builderWithSpan{
span: span,
},
}
}
func (prefill *prefilling) PrefillComplete(msg string) xopbase.Prefilled {
prefill.builder.prefillMsg = msg
return &prefilled{
builderWithSpan: prefill.builderWithSpan,
}
}
func (prefilled *prefilled) Line(level xopnum.Level, ts time.Time, frames []runtime.Frame) xopbase.Line {
if !prefilled.span.logger.doLogging || !prefilled.span.otelSpan.IsRecording() {
return xopbase.SkipLine
}
// PERFORMANCE: get line from a pool
line := &line{}
line.level = level
line.span = prefilled.span
line.attributes = line.prealloc[:2] // reserving two spots at the beginnging
line.attributes = append(line.attributes, prefilled.span.spanPrefill...)
line.attributes = append(line.attributes, prefilled.attributes...)
line.prefillMsg = prefilled.prefillMsg
line.linkKey = prefilled.linkKey
line.linkValue = prefilled.linkValue
line.timestamp = ts
if len(frames) > 0 {
fs := make([]string, len(frames))
for i, frame := range frames {
fs[i] = frame.File + ":" + strconv.Itoa(frame.Line)
}
line.attributes = append(line.attributes, xopStackTrace.StringSlice(fs))
}
return line
}
func (line *line) Link(k string, v xoptrace.Trace) {
if k == xopOTELLinkDetail.String() {
// Link will not be called with OTEL->XOP->OTEL so no need to
// suppress anything
return
}
line.attributes = append(line.attributes,
xopType.String("link"),
xopLinkData.String(v.String()),
)
line.done(line.prefillMsg + k)
if line.span.logger.bufferedRequest != nil {
// add span.Links() is handled in buffered.zzzgo so
// a sub-span is not needed here.
return
}
_, tmpSpan := line.span.logger.tracer.Start(line.span.ctx, k,
oteltrace.WithLinks(
oteltrace.Link{
SpanContext: oteltrace.NewSpanContext(oteltrace.SpanContextConfig{
TraceID: v.TraceID().Array(),
SpanID: v.SpanID().Array(),
TraceFlags: oteltrace.TraceFlags(v.Flags().Array()[0]),
TraceState: emptyTraceState, // TODO: is this right?
Remote: true, // information not available
}),
}),
oteltrace.WithAttributes(
spanIsLinkEventKey.Bool(true),
),
)
tmpSpan.AddEvent(line.level.String(),
oteltrace.WithTimestamp(line.timestamp),
oteltrace.WithAttributes(line.attributes...))
tmpSpan.SetAttributes(xopType.String("link-event"))
tmpSpan.End()
}
func (line *line) Model(msg string, v xopbase.ModelArg) {
v.Encode()
line.attributes = append(line.attributes,
xopType.String("model"),
xopModelType.String(v.ModelType),
xopEncoding.String(v.Encoding.String()),
xopModel.String(string(v.Encoded)),
)
line.done(line.prefillMsg + msg)
}
func (line *line) Msg(msg string) {
if line.span.isXOP {
line.attributes = append(line.attributes, xopType.String("line"))
}
line.done(line.prefillMsg + msg)
// PERFORMANCE: return line to pool
}
func (line *line) done(msg string) {
if line.span.isXOP {
line.attributes[0] = xopLineNumber.Int64(int64(atomic.AddInt32(&line.span.request.lineCount, 1)))
line.attributes[1] = xopLevel.String(line.level.String())
} else {
line.attributes = line.attributes[2:]
}
if line.timestamp.IsZero() {
line.span.otelSpan.AddEvent(msg,
oteltrace.WithAttributes(line.attributes...))
} else {
line.span.otelSpan.AddEvent(msg,
oteltrace.WithTimestamp(line.timestamp),
oteltrace.WithAttributes(line.attributes...))
}
}
var templateRE = regexp.MustCompile(`\{.+?\}`)
func (line *line) Template(template string) {
kv := make(map[string]int)
for i, a := range line.attributes {
kv[string(a.Key)] = i
}
msg := templateRE.ReplaceAllStringFunc(template, func(k string) string {
k = k[1 : len(k)-1]
if i, ok := kv[k]; ok {
a := line.attributes[i]
switch a.Value.Type() {
case attribute.BOOL:
return strconv.FormatBool(a.Value.AsBool())
case attribute.INT64:
return strconv.FormatInt(a.Value.AsInt64(), 10)
case attribute.FLOAT64:
return strconv.FormatFloat(a.Value.AsFloat64(), 'g', -1, 64)
case attribute.STRING:
return a.Value.AsString()
case attribute.BOOLSLICE:
return fmt.Sprint(a.Value.AsBoolSlice())
case attribute.INT64SLICE:
return fmt.Sprint(a.Value.AsInt64Slice())
case attribute.FLOAT64SLICE:
return fmt.Sprint(a.Value.AsFloat64Slice())
case attribute.STRINGSLICE:
return fmt.Sprint(a.Value.AsStringSlice())
default:
return "{" + k + "}"
}
}
return "''"
})
line.attributes = append(line.attributes,
xopType.String("line"),
xopTemplate.String(template),
)
line.done(line.prefillMsg + msg)
}
func (builder *builder) Enum(k *xopat.EnumAttribute, v xopat.Enum) {
builder.attributes = append(builder.attributes, attribute.StringSlice(k.Key().String(), []string{v.String(), "enum", strconv.FormatInt(v.Int64(), 10)}))
}
func (builder *builder) Any(k xopat.K, v xopbase.ModelArg) {
v.Encode()
builder.attributes = append(builder.attributes, attribute.StringSlice(k.String(), []string{string(v.Encoded), "any", v.Encoding.String(), v.ModelType}))
}
func (builder *builder) Time(k xopat.K, v time.Time) {
builder.attributes = append(builder.attributes, attribute.StringSlice(k.String(), []string{v.Format(time.RFC3339Nano), "time"}))
}
func (builder *builder) Duration(k xopat.K, v time.Duration) {
builder.attributes = append(builder.attributes, attribute.StringSlice(k.String(), []string{v.String(), "dur"}))
}
func (builder *builder) Uint64(k xopat.K, v uint64, dt xopbase.DataType) {
builder.attributes = append(builder.attributes, attribute.StringSlice(k.String(), []string{strconv.FormatUint(v, 10), xopbase.DataTypeToString[dt]}))
}
func (builder *builder) Int64(k xopat.K, v int64, dt xopbase.DataType) {
builder.attributes = append(builder.attributes, attribute.StringSlice(k.String(), []string{strconv.FormatInt(v, 10), xopbase.DataTypeToString[dt]}))
}
func (builder *builder) Float64(k xopat.K, v float64, dt xopbase.DataType) {
builder.attributes = append(builder.attributes, attribute.StringSlice(k.String(), []string{strconv.FormatFloat(v, 'g', -1, 64), xopbase.DataTypeToString[dt]}))
}
func (builder *builder) String(k xopat.K, v string, dt xopbase.DataType) {
builder.attributes = append(builder.attributes, attribute.StringSlice(k.String(), []string{v, xopbase.DataTypeToString[dt]}))
}
func (builder *builder) Bool(k xopat.K, v bool) {
builder.attributes = append(builder.attributes, attribute.Bool(k.String(), v))
}
var skipIfOTEL = map[string]struct{}{
otelReplayStuff.Key().String(): {},
}
// MACRO BaseAttribute
func (span *span) MetadataZZZ(k *xopat.ZZZAttribute, v zzz) {
//CONDITIONAL ONLY:Any
if k.Key().String() == otelReplayStuff.Key().String() {
return
}
//END CONDITIONAL
key := k.Key()
if span.isXOP {
if _, ok := span.request.attributesDefined[key.String()]; !ok {
if k.Description() != xopSynthesizedForOTEL {
span.request.otelSpan.SetAttributes(attribute.String(attributeDefinitionPrefix+key.String(), k.DefinitionJSONString()))
span.request.attributesDefined[key.String()] = struct{}{}
}
}
}
//CONDITIONAL ONLY:Link
if k.Key().String() == otelLink.Key().String() {
return
}
value := v.String()
if span.logger.bufferedRequest == nil {
_, tmpSpan := span.logger.tracer.Start(span.ctx, k.Key().String(),
oteltrace.WithLinks(
oteltrace.Link{
SpanContext: oteltrace.NewSpanContext(oteltrace.SpanContextConfig{
TraceID: v.TraceID().Array(),
SpanID: v.SpanID().Array(),
TraceFlags: oteltrace.TraceFlags(v.Flags().Array()[0]),
TraceState: emptyTraceState, // TODO: is this right?
Remote: true, // information not available
}),
Attributes: []attribute.KeyValue{
xopLinkMetadataKey.String(key.String()),
},
}),
oteltrace.WithAttributes(
spanIsLinkAttributeKey.Bool(true),
),
)
tmpSpan.SetAttributes(spanIsLinkAttributeKey.Bool(true))
tmpSpan.End()
}
//CONDITIONAL ONLY:Enum
value := v.String() + "/" + strconv.FormatInt(v.Int64(), 10)
//CONDITIONAL ONLY:Time
value := v.Format(time.RFC3339Nano)
//CONDITIONAL ONLY:Any
enc, err := v.MarshalJSON()
var value string
if err != nil {
value = fmt.Sprintf("[zopotel] could not marshal %T value: %s", v, err)
} else {
value = string(enc)
}
//CONDITIONAL ONLY:Int64,String,Float64,Bool
value := v
//END CONDITIONAL
if !k.Multiple() {
if k.Locked() {
span.lock.Lock()
defer span.lock.Unlock()
if span.hasPrior == nil {
span.hasPrior = make(map[string]struct{})
}
if _, ok := span.hasPrior[key.String()]; ok {
return
}
span.hasPrior[key.String()] = struct{}{}
}
//CONDITIONAL ONLY:Enum,Time,String,Any,Link
span.otelSpan.SetAttributes(attribute.String(key.String(), value))
//CONDITIONAL ONLY:Int64
if k.SubType() == xopat.AttributeTypeDuration {
span.otelSpan.SetAttributes(attribute.String(key.String(), time.Duration(value).String()))
} else {
span.otelSpan.SetAttributes(attribute.ZZZ(key.String(), value))
}
//CONDITIONAL SKIP:Enum,Time,String,Any,Link,Int64
span.otelSpan.SetAttributes(attribute.ZZZ(key.String(), value))
//END CONDITIONAL
return
}
span.lock.Lock()
defer span.lock.Unlock()
if k.Distinct() {
if span.metadataSeen == nil {
span.metadataSeen = make(map[string]interface{})
}
seenRaw, ok := span.metadataSeen[key.String()]
if !ok {
//CONDITIONAL ONLY:Enum,Time,String,Any,Link
seen := make(map[string]struct{})
//ELSE CONDITIONAL
seen := make(map[zzz]struct{})
//END CONDITIONAL
span.metadataSeen[key.String()] = seen
seen[value] = struct{}{}
} else {
//CONDITIONAL ONLY:Enum,Time,String,Any,Link
seen := seenRaw.(map[string]struct{})
//ELSE CONDITIONAL
seen := seenRaw.(map[zzz]struct{})
//END CONDITIONAL
if _, ok := seen[value]; ok {
return
}
seen[value] = struct{}{}
}
}
//CONDITIONAL ONLY:Enum,Time,String,Any,Link
if span.priorStringSlices == nil {
span.priorStringSlices = make(map[string][]string)
}
s := span.priorStringSlices[key.String()]
s = append(s, value)
span.priorStringSlices[key.String()] = s
span.otelSpan.SetAttributes(attribute.StringSlice(key.String(), s))
//CONDITIONAL ONLY:Int64
if k.SubType() == xopat.AttributeTypeDuration {
if span.priorStringSlices == nil {
span.priorStringSlices = make(map[string][]string)
}
s := span.priorStringSlices[key.String()]
s = append(s, time.Duration(value).String())
span.priorStringSlices[key.String()] = s
span.otelSpan.SetAttributes(attribute.StringSlice(key.String(), s))
} else {
if span.priorZZZSlices == nil {
span.priorZZZSlices = make(map[string][]zzz)
}
s := span.priorZZZSlices[key.String()]
s = append(s, value)
span.priorZZZSlices[key.String()] = s
span.otelSpan.SetAttributes(attribute.ZZZSlice(key.String(), s))
}
//CONDITIONAL SKIP:Enum,Time,String,Any,Link,Int64
if span.priorZZZSlices == nil {
span.priorZZZSlices = make(map[string][]zzz)
}
s := span.priorZZZSlices[key.String()]
s = append(s, value)
span.priorZZZSlices[key.String()] = s
span.otelSpan.SetAttributes(attribute.ZZZSlice(key.String(), s))
//END CONDITIONAL
}
var spanKindFromString = map[string]oteltrace.SpanKind{
// MACRO OTELSpanKinds
oteltrace.ZZZ.String(): oteltrace.ZZZ,
}