// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Package tracetransform provides conversion functionality for the otlptrace // exporters.
package tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform" import ( commonpb ) // KeyValues transforms a slice of attribute KeyValues into OTLP key-values. func ( []attribute.KeyValue) []*commonpb.KeyValue { if len() == 0 { return nil } := make([]*commonpb.KeyValue, 0, len()) for , := range { = append(, KeyValue()) } return } // Iterator transforms an attribute iterator into OTLP key-values. func ( attribute.Iterator) []*commonpb.KeyValue { := .Len() if == 0 { return nil } := make([]*commonpb.KeyValue, 0, ) for .Next() { = append(, KeyValue(.Attribute())) } return } // ResourceAttributes transforms a Resource OTLP key-values. func ( *resource.Resource) []*commonpb.KeyValue { return Iterator(.Iter()) } // KeyValue transforms an attribute KeyValue into an OTLP key-value. func ( attribute.KeyValue) *commonpb.KeyValue { return &commonpb.KeyValue{Key: string(.Key), Value: Value(.Value)} } // Value transforms an attribute Value into an OTLP AnyValue. func ( attribute.Value) *commonpb.AnyValue { := new(commonpb.AnyValue) switch .Type() { case attribute.BOOL: .Value = &commonpb.AnyValue_BoolValue{ BoolValue: .AsBool(), } case attribute.BOOLSLICE: .Value = &commonpb.AnyValue_ArrayValue{ ArrayValue: &commonpb.ArrayValue{ Values: boolSliceValues(.AsBoolSlice()), }, } case attribute.INT64: .Value = &commonpb.AnyValue_IntValue{ IntValue: .AsInt64(), } case attribute.INT64SLICE: .Value = &commonpb.AnyValue_ArrayValue{ ArrayValue: &commonpb.ArrayValue{ Values: int64SliceValues(.AsInt64Slice()), }, } case attribute.FLOAT64: .Value = &commonpb.AnyValue_DoubleValue{ DoubleValue: .AsFloat64(), } case attribute.FLOAT64SLICE: .Value = &commonpb.AnyValue_ArrayValue{ ArrayValue: &commonpb.ArrayValue{ Values: float64SliceValues(.AsFloat64Slice()), }, } case attribute.STRING: .Value = &commonpb.AnyValue_StringValue{ StringValue: .AsString(), } case attribute.STRINGSLICE: .Value = &commonpb.AnyValue_ArrayValue{ ArrayValue: &commonpb.ArrayValue{ Values: stringSliceValues(.AsStringSlice()), }, } default: .Value = &commonpb.AnyValue_StringValue{ StringValue: "INVALID", } } return } func boolSliceValues( []bool) []*commonpb.AnyValue { := make([]*commonpb.AnyValue, len()) for , := range { [] = &commonpb.AnyValue{ Value: &commonpb.AnyValue_BoolValue{ BoolValue: , }, } } return } func int64SliceValues( []int64) []*commonpb.AnyValue { := make([]*commonpb.AnyValue, len()) for , := range { [] = &commonpb.AnyValue{ Value: &commonpb.AnyValue_IntValue{ IntValue: , }, } } return } func float64SliceValues( []float64) []*commonpb.AnyValue { := make([]*commonpb.AnyValue, len()) for , := range { [] = &commonpb.AnyValue{ Value: &commonpb.AnyValue_DoubleValue{ DoubleValue: , }, } } return } func stringSliceValues( []string) []*commonpb.AnyValue { := make([]*commonpb.AnyValue, len()) for , := range { [] = &commonpb.AnyValue{ Value: &commonpb.AnyValue_StringValue{ StringValue: , }, } } return }