| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
// Package oc2otel provides conversion from OpenCensus to OpenTelemetry. |
| 5 |
package oc2otel // import "go.opentelemetry.io/otel/bridge/opencensus/internal/oc2otel" |
| 6 |
|
| 7 |
import ( |
| 8 |
octrace "go.opencensus.io/trace" |
| 9 |
|
| 10 |
"go.opentelemetry.io/otel/attribute" |
| 11 |
) |
| 12 |
|
| 13 |
func Attributes(attr []octrace.Attribute) []attribute.KeyValue { |
| 14 |
otelAttr := make([]attribute.KeyValue, len(attr)) |
| 15 |
for i, a := range attr { |
| 16 |
otelAttr[i] = attribute.KeyValue{ |
| 17 |
Key: attribute.Key(a.Key()), |
| 18 |
Value: AttributeValue(a.Value()), |
| 19 |
} |
| 20 |
} |
| 21 |
return otelAttr |
| 22 |
} |
| 23 |
|
| 24 |
func AttributesFromMap(attr map[string]any) []attribute.KeyValue { |
| 25 |
otelAttr := make([]attribute.KeyValue, 0, len(attr)) |
| 26 |
for k, v := range attr { |
| 27 |
otelAttr = append(otelAttr, attribute.KeyValue{ |
| 28 |
Key: attribute.Key(k), |
| 29 |
Value: AttributeValue(v), |
| 30 |
}) |
| 31 |
} |
| 32 |
return otelAttr |
| 33 |
} |
| 34 |
|
| 35 |
func AttributeValue(ocval any) attribute.Value { |
| 36 |
switch v := ocval.(type) { |
| 37 |
case bool: |
| 38 |
return attribute.BoolValue(v) |
| 39 |
case int64: |
| 40 |
return attribute.Int64Value(v) |
| 41 |
case float64: |
| 42 |
return attribute.Float64Value(v) |
| 43 |
case string: |
| 44 |
return attribute.StringValue(v) |
| 45 |
default: |
| 46 |
return attribute.StringValue("unknown") |
| 47 |
} |
| 48 |
} |