You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-23 22:34:47 +02:00
Rename otel/label -> otel/attribute (#1541)
* Rename otel/label -> otel/attr Leave the imported name alone, to avoid a large diff and conflicts * Better import comment * Update CHANGELOG.md Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * otel/attr -> otel/attribute * Missed the changelog entry * Get rid of import renaming * Merge remaining conflicts Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
This commit is contained in:
@@ -19,8 +19,8 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/internal/baggage"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
)
|
||||
|
||||
const baggageHeader = "baggage"
|
||||
@@ -38,7 +38,7 @@ func (b Baggage) Inject(ctx context.Context, carrier TextMapCarrier) {
|
||||
baggageMap := baggage.MapFromContext(ctx)
|
||||
firstIter := true
|
||||
var headerValueBuilder strings.Builder
|
||||
baggageMap.Foreach(func(kv label.KeyValue) bool {
|
||||
baggageMap.Foreach(func(kv attribute.KeyValue) bool {
|
||||
if !firstIter {
|
||||
headerValueBuilder.WriteRune(',')
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (b Baggage) Extract(parent context.Context, carrier TextMapCarrier) context
|
||||
}
|
||||
|
||||
baggageValues := strings.Split(bVal, ",")
|
||||
keyValues := make([]label.KeyValue, 0, len(baggageValues))
|
||||
keyValues := make([]attribute.KeyValue, 0, len(baggageValues))
|
||||
for _, baggageValue := range baggageValues {
|
||||
valueAndProps := strings.Split(baggageValue, ";")
|
||||
if len(valueAndProps) < 1 {
|
||||
@@ -92,7 +92,7 @@ func (b Baggage) Extract(parent context.Context, carrier TextMapCarrier) context
|
||||
trimmedValueWithProps.WriteString(prop)
|
||||
}
|
||||
|
||||
keyValues = append(keyValues, label.String(trimmedName, trimmedValueWithProps.String()))
|
||||
keyValues = append(keyValues, attribute.String(trimmedName, trimmedValueWithProps.String()))
|
||||
}
|
||||
|
||||
if len(keyValues) > 0 {
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/internal/baggage"
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
)
|
||||
|
||||
@@ -32,54 +32,54 @@ func TestExtractValidBaggageFromHTTPReq(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
header string
|
||||
wantKVs []label.KeyValue
|
||||
wantKVs []attribute.KeyValue
|
||||
}{
|
||||
{
|
||||
name: "valid w3cHeader",
|
||||
header: "key1=val1,key2=val2",
|
||||
wantKVs: []label.KeyValue{
|
||||
label.String("key1", "val1"),
|
||||
label.String("key2", "val2"),
|
||||
wantKVs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1"),
|
||||
attribute.String("key2", "val2"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid w3cHeader with spaces",
|
||||
header: "key1 = val1, key2 =val2 ",
|
||||
wantKVs: []label.KeyValue{
|
||||
label.String("key1", "val1"),
|
||||
label.String("key2", "val2"),
|
||||
wantKVs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1"),
|
||||
attribute.String("key2", "val2"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid w3cHeader with properties",
|
||||
header: "key1=val1,key2=val2;prop=1",
|
||||
wantKVs: []label.KeyValue{
|
||||
label.String("key1", "val1"),
|
||||
label.String("key2", "val2;prop=1"),
|
||||
wantKVs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1"),
|
||||
attribute.String("key2", "val2;prop=1"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid header with url-escaped comma",
|
||||
header: "key1=val1,key2=val2%2Cval3",
|
||||
wantKVs: []label.KeyValue{
|
||||
label.String("key1", "val1"),
|
||||
label.String("key2", "val2,val3"),
|
||||
wantKVs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1"),
|
||||
attribute.String("key2", "val2,val3"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid header with an invalid header",
|
||||
header: "key1=val1,key2=val2,a,val3",
|
||||
wantKVs: []label.KeyValue{
|
||||
label.String("key1", "val1"),
|
||||
label.String("key2", "val2"),
|
||||
wantKVs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1"),
|
||||
attribute.String("key2", "val2"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid header with no value",
|
||||
header: "key1=,key2=val2",
|
||||
wantKVs: []label.KeyValue{
|
||||
label.String("key1", ""),
|
||||
label.String("key2", "val2"),
|
||||
wantKVs: []attribute.KeyValue{
|
||||
attribute.String("key1", ""),
|
||||
attribute.String("key2", "val2"),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -101,9 +101,9 @@ func TestExtractValidBaggageFromHTTPReq(t *testing.T) {
|
||||
)
|
||||
}
|
||||
totalDiff := ""
|
||||
wantBaggage.Foreach(func(keyValue label.KeyValue) bool {
|
||||
wantBaggage.Foreach(func(keyValue attribute.KeyValue) bool {
|
||||
val, _ := gotBaggage.Value(keyValue.Key)
|
||||
diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{}))
|
||||
diff := cmp.Diff(keyValue, attribute.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(attribute.Value{}))
|
||||
if diff != "" {
|
||||
totalDiff += diff + "\n"
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
header string
|
||||
hasKVs []label.KeyValue
|
||||
hasKVs []attribute.KeyValue
|
||||
}{
|
||||
{
|
||||
name: "no key values",
|
||||
@@ -130,17 +130,17 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
||||
{
|
||||
name: "invalid header with existing context",
|
||||
header: "header2",
|
||||
hasKVs: []label.KeyValue{
|
||||
label.String("key1", "val1"),
|
||||
label.String("key2", "val2"),
|
||||
hasKVs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1"),
|
||||
attribute.String("key2", "val2"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty header value",
|
||||
header: "",
|
||||
hasKVs: []label.KeyValue{
|
||||
label.String("key1", "val1"),
|
||||
label.String("key2", "val2"),
|
||||
hasKVs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1"),
|
||||
attribute.String("key2", "val2"),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -162,9 +162,9 @@ func TestExtractInvalidDistributedContextFromHTTPReq(t *testing.T) {
|
||||
)
|
||||
}
|
||||
totalDiff := ""
|
||||
wantBaggage.Foreach(func(keyValue label.KeyValue) bool {
|
||||
wantBaggage.Foreach(func(keyValue attribute.KeyValue) bool {
|
||||
val, _ := gotBaggage.Value(keyValue.Key)
|
||||
diff := cmp.Diff(keyValue, label.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(label.Value{}))
|
||||
diff := cmp.Diff(keyValue, attribute.KeyValue{Key: keyValue.Key, Value: val}, cmp.AllowUnexported(attribute.Value{}))
|
||||
if diff != "" {
|
||||
totalDiff += diff + "\n"
|
||||
}
|
||||
@@ -178,33 +178,33 @@ func TestInjectBaggageToHTTPReq(t *testing.T) {
|
||||
propagator := propagation.Baggage{}
|
||||
tests := []struct {
|
||||
name string
|
||||
kvs []label.KeyValue
|
||||
kvs []attribute.KeyValue
|
||||
wantInHeader []string
|
||||
wantedLen int
|
||||
}{
|
||||
{
|
||||
name: "two simple values",
|
||||
kvs: []label.KeyValue{
|
||||
label.String("key1", "val1"),
|
||||
label.String("key2", "val2"),
|
||||
kvs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1"),
|
||||
attribute.String("key2", "val2"),
|
||||
},
|
||||
wantInHeader: []string{"key1=val1", "key2=val2"},
|
||||
},
|
||||
{
|
||||
name: "two values with escaped chars",
|
||||
kvs: []label.KeyValue{
|
||||
label.String("key1", "val1,val2"),
|
||||
label.String("key2", "val3=4"),
|
||||
kvs: []attribute.KeyValue{
|
||||
attribute.String("key1", "val1,val2"),
|
||||
attribute.String("key2", "val3=4"),
|
||||
},
|
||||
wantInHeader: []string{"key1=val1%2Cval2", "key2=val3%3D4"},
|
||||
},
|
||||
{
|
||||
name: "values of non-string types",
|
||||
kvs: []label.KeyValue{
|
||||
label.Bool("key1", true),
|
||||
label.Int("key2", 123),
|
||||
label.Int64("key3", 123),
|
||||
label.Float64("key4", 123.567),
|
||||
kvs: []attribute.KeyValue{
|
||||
attribute.Bool("key1", true),
|
||||
attribute.Int("key2", 123),
|
||||
attribute.Int64("key3", 123),
|
||||
attribute.Float64("key4", 123.567),
|
||||
},
|
||||
wantInHeader: []string{
|
||||
"key1=true",
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
@@ -151,14 +151,14 @@ func parseTraceState(in string) trace.TraceState {
|
||||
return trace.TraceState{}
|
||||
}
|
||||
|
||||
kvs := []label.KeyValue{}
|
||||
kvs := []attribute.KeyValue{}
|
||||
for _, entry := range strings.Split(in, ",") {
|
||||
parts := strings.SplitN(entry, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
// Parse failure, abort!
|
||||
return trace.TraceState{}
|
||||
}
|
||||
kvs = append(kvs, label.String(parts[0], parts[1]))
|
||||
kvs = append(kvs, attribute.String(parts[0], parts[1]))
|
||||
}
|
||||
|
||||
// Ignoring error here as "failure to parse tracestate MUST NOT
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"go.opentelemetry.io/otel/label"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/oteltest"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
@@ -280,7 +280,7 @@ func TestTraceStatePropagation(t *testing.T) {
|
||||
prop := propagation.TraceContext{}
|
||||
stateHeader := "tracestate"
|
||||
parentHeader := "traceparent"
|
||||
state, err := trace.TraceStateFromKeyValues(label.String("key1", "value1"), label.String("key2", "value2"))
|
||||
state, err := trace.TraceStateFromKeyValues(attribute.String("key1", "value1"), attribute.String("key2", "value2"))
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to construct expected TraceState: %s", err.Error())
|
||||
}
|
||||
@@ -341,7 +341,7 @@ func TestTraceStatePropagation(t *testing.T) {
|
||||
if diff := cmp.Diff(
|
||||
trace.RemoteSpanContextFromContext(ctx),
|
||||
tt.wantSc,
|
||||
cmp.AllowUnexported(label.Value{}),
|
||||
cmp.AllowUnexported(attribute.Value{}),
|
||||
cmp.AllowUnexported(trace.TraceState{}),
|
||||
); diff != "" {
|
||||
t.Errorf("Extracted tracestate: -got +want %s", diff)
|
||||
|
||||
Reference in New Issue
Block a user