You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-29 23:07:45 +02:00
Separate trace API components into own files (#5620)
This moves the `Span` (along with the `SpanKind` and `Link`), `Tracer`, and `TracerProvider` out of the single trace.go file and into their own files. This change is intended to help developers find these types when looking at the directory and to break up the long trace.go file.
This commit is contained in:
@@ -5,13 +5,10 @@ package trace
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
)
|
||||
|
||||
func TestSpanContextIsValid(t *testing.T) {
|
||||
@@ -460,80 +457,6 @@ func TestStringSpanID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSpanKind(t *testing.T) {
|
||||
tests := []struct {
|
||||
in SpanKind
|
||||
want SpanKind
|
||||
}{
|
||||
{
|
||||
SpanKindUnspecified,
|
||||
SpanKindInternal,
|
||||
},
|
||||
{
|
||||
SpanKindInternal,
|
||||
SpanKindInternal,
|
||||
},
|
||||
{
|
||||
SpanKindServer,
|
||||
SpanKindServer,
|
||||
},
|
||||
{
|
||||
SpanKindClient,
|
||||
SpanKindClient,
|
||||
},
|
||||
{
|
||||
SpanKindProducer,
|
||||
SpanKindProducer,
|
||||
},
|
||||
{
|
||||
SpanKindConsumer,
|
||||
SpanKindConsumer,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if got := ValidateSpanKind(test.in); got != test.want {
|
||||
t.Errorf("ValidateSpanKind(%#v) = %#v, want %#v", test.in, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpanKindString(t *testing.T) {
|
||||
tests := []struct {
|
||||
in SpanKind
|
||||
want string
|
||||
}{
|
||||
{
|
||||
SpanKindUnspecified,
|
||||
"unspecified",
|
||||
},
|
||||
{
|
||||
SpanKindInternal,
|
||||
"internal",
|
||||
},
|
||||
{
|
||||
SpanKindServer,
|
||||
"server",
|
||||
},
|
||||
{
|
||||
SpanKindClient,
|
||||
"client",
|
||||
},
|
||||
{
|
||||
SpanKindProducer,
|
||||
"producer",
|
||||
},
|
||||
{
|
||||
SpanKindConsumer,
|
||||
"consumer",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if got := test.in.String(); got != test.want {
|
||||
t.Errorf("%#v.String() = %#v, want %#v", test.in, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertSpanContextEqual(got SpanContext, want SpanContext) bool {
|
||||
return got.spanID == want.spanID &&
|
||||
got.traceID == want.traceID &&
|
||||
@@ -631,19 +554,6 @@ func TestSpanContextDerivation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinkFromContext(t *testing.T) {
|
||||
k1v1 := attribute.String("key1", "value1")
|
||||
spanCtx := SpanContext{traceID: TraceID([16]byte{1}), remote: true}
|
||||
|
||||
receiverCtx := ContextWithRemoteSpanContext(context.Background(), spanCtx)
|
||||
link := LinkFromContext(receiverCtx, k1v1)
|
||||
|
||||
if !assertSpanContextEqual(link.SpanContext, spanCtx) {
|
||||
t.Fatalf("LinkFromContext: Unexpected context created: %s", cmp.Diff(link.SpanContext, spanCtx))
|
||||
}
|
||||
assert.Equal(t, link.Attributes[0], k1v1)
|
||||
}
|
||||
|
||||
func TestConfigLinkMutability(t *testing.T) {
|
||||
sc0 := NewSpanContext(SpanContextConfig{TraceID: [16]byte{1}})
|
||||
sc1 := NewSpanContext(SpanContextConfig{TraceID: [16]byte{2}})
|
||||
|
||||
Reference in New Issue
Block a user