1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-04-15 11:36:44 +02:00

Merge branch 'master' into master

This commit is contained in:
Liz Fong-Jones 2020-05-05 14:08:55 -04:00 committed by GitHub
commit eccf13148d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 405 additions and 416 deletions

View File

@ -23,7 +23,6 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/key" "go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/internal/matchers" "go.opentelemetry.io/otel/internal/matchers"
@ -79,7 +78,7 @@ func (h *Harness) TestTracer(subjectFactory func() trace.Tracer) {
ctx, span := subject.Start(context.Background(), "test") ctx, span := subject.Start(context.Background(), "test")
e.Expect(span).NotToBeNil() e.Expect(span).NotToBeNil()
e.Expect(span.SpanContext()).NotToEqual(core.EmptySpanContext()) e.Expect(span.SpanContext()).NotToEqual(trace.EmptySpanContext())
e.Expect(trace.SpanFromContext(ctx)).ToEqual(span) e.Expect(trace.SpanFromContext(ctx)).ToEqual(span)
}) })

View File

@ -30,10 +30,10 @@ type alwaysOffSampler struct{}
// It always returns a Decision with Sampled value set to false // It always returns a Decision with Sampled value set to false
// and with Attributes set to an empty slice. // and with Attributes set to an empty slice.
func (ns alwaysOffSampler) ShouldSample( func (ns alwaysOffSampler) ShouldSample(
_ core.SpanContext, _ SpanContext,
_ bool, _ bool,
_ core.TraceID, _ ID,
_ core.SpanID, _ SpanID,
_ string, _ string,
_ SpanKind, _ SpanKind,
_ []core.KeyValue, _ []core.KeyValue,

View File

@ -24,7 +24,7 @@ import (
func TestNeverSamperShouldSample(t *testing.T) { func TestNeverSamperShouldSample(t *testing.T) {
gotD := AlwaysOffSampler().ShouldSample( gotD := AlwaysOffSampler().ShouldSample(
core.SpanContext{}, false, core.TraceID{}, core.SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) SpanContext{}, false, ID{}, SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{})
wantD := Decision{Sampled: false} wantD := Decision{Sampled: false}
if diff := cmp.Diff(wantD, gotD); diff != "" { if diff := cmp.Diff(wantD, gotD); diff != "" {
t.Errorf("Decision: +got, -want%v", diff) t.Errorf("Decision: +got, -want%v", diff)

View File

@ -30,10 +30,10 @@ type alwaysOnSampler struct{}
// It always returns a Decision with Sampled value set to true // It always returns a Decision with Sampled value set to true
// and with Attributes set to an empty slice. // and with Attributes set to an empty slice.
func (as alwaysOnSampler) ShouldSample( func (as alwaysOnSampler) ShouldSample(
_ core.SpanContext, _ SpanContext,
_ bool, _ bool,
_ core.TraceID, _ ID,
_ core.SpanID, _ SpanID,
_ string, _ string,
_ SpanKind, _ SpanKind,
_ []core.KeyValue, _ []core.KeyValue,

View File

@ -24,7 +24,7 @@ import (
func TestAlwaysOnSamplerShouldSample(t *testing.T) { func TestAlwaysOnSamplerShouldSample(t *testing.T) {
gotD := AlwaysOnSampler().ShouldSample( gotD := AlwaysOnSampler().ShouldSample(
core.SpanContext{}, false, core.TraceID{}, core.SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{}) SpanContext{}, false, ID{}, SpanID{}, "span", SpanKindClient, []core.KeyValue{}, []Link{})
wantD := Decision{Sampled: true} wantD := Decision{Sampled: true}
if diff := cmp.Diff(wantD, gotD); diff != "" { if diff := cmp.Diff(wantD, gotD); diff != "" {
t.Errorf("Decision: +got, -want%v", diff) t.Errorf("Decision: +got, -want%v", diff)

View File

@ -105,7 +105,7 @@ type Span interface {
// SpanContext returns span context of the span. Returned SpanContext is usable // SpanContext returns span context of the span. Returned SpanContext is usable
// even after the span ends. // even after the span ends.
SpanContext() core.SpanContext SpanContext() SpanContext
// SetStatus sets the status of the span in the form of a code // SetStatus sets the status of the span in the form of a code
// and a message. SetStatus overrides the value of previous // and a message. SetStatus overrides the value of previous
@ -152,7 +152,7 @@ type StartConfig struct {
// on service provider side so two traces (from Client and from Service Provider) can // on service provider side so two traces (from Client and from Service Provider) can
// be correlated. // be correlated.
type Link struct { type Link struct {
core.SpanContext SpanContext
Attributes []core.KeyValue Attributes []core.KeyValue
} }
@ -248,7 +248,7 @@ func WithNewRoot() StartOption {
} }
// LinkedTo allows instantiating a Span with initial Links. // LinkedTo allows instantiating a Span with initial Links.
func LinkedTo(sc core.SpanContext, attrs ...core.KeyValue) StartOption { func LinkedTo(sc SpanContext, attrs ...core.KeyValue) StartOption {
return func(c *StartConfig) { return func(c *StartConfig) {
c.Links = append(c.Links, Link{sc, attrs}) c.Links = append(c.Links, Link{sc, attrs})
} }

View File

@ -19,7 +19,6 @@ import (
"fmt" "fmt"
"strings" "strings"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/propagation"
) )
@ -57,7 +56,7 @@ func (b3 B3) Inject(ctx context.Context, supplier propagation.HTTPSupplier) {
return return
} }
if b3.SingleHeader { if b3.SingleHeader {
sampled := sc.TraceFlags & core.TraceFlagsSampled sampled := sc.TraceFlags & FlagsSampled
supplier.Set(B3SingleHeader, supplier.Set(B3SingleHeader,
fmt.Sprintf("%s-%s-%.1d", sc.TraceID, sc.SpanID, sampled)) fmt.Sprintf("%s-%s-%.1d", sc.TraceID, sc.SpanID, sampled))
} else { } else {
@ -76,7 +75,7 @@ func (b3 B3) Inject(ctx context.Context, supplier propagation.HTTPSupplier) {
// Extract retrieves B3 Headers from the supplier // Extract retrieves B3 Headers from the supplier
func (b3 B3) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context { func (b3 B3) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context {
var sc core.SpanContext var sc SpanContext
if b3.SingleHeader { if b3.SingleHeader {
sc = b3.extractSingleHeader(supplier) sc = b3.extractSingleHeader(supplier)
} else { } else {
@ -88,84 +87,84 @@ func (b3 B3) Extract(ctx context.Context, supplier propagation.HTTPSupplier) con
return ContextWithRemoteSpanContext(ctx, sc) return ContextWithRemoteSpanContext(ctx, sc)
} }
func (b3 B3) extract(supplier propagation.HTTPSupplier) core.SpanContext { func (b3 B3) extract(supplier propagation.HTTPSupplier) SpanContext {
tid, err := core.TraceIDFromHex(supplier.Get(B3TraceIDHeader)) tid, err := IDFromHex(supplier.Get(B3TraceIDHeader))
if err != nil { if err != nil {
return core.EmptySpanContext() return EmptySpanContext()
} }
sid, err := core.SpanIDFromHex(supplier.Get(B3SpanIDHeader)) sid, err := SpanIDFromHex(supplier.Get(B3SpanIDHeader))
if err != nil { if err != nil {
return core.EmptySpanContext() return EmptySpanContext()
} }
sampled, ok := b3.extractSampledState(supplier.Get(B3SampledHeader)) sampled, ok := b3.extractSampledState(supplier.Get(B3SampledHeader))
if !ok { if !ok {
return core.EmptySpanContext() return EmptySpanContext()
} }
debug, ok := b3.extracDebugFlag(supplier.Get(B3DebugFlagHeader)) debug, ok := b3.extracDebugFlag(supplier.Get(B3DebugFlagHeader))
if !ok { if !ok {
return core.EmptySpanContext() return EmptySpanContext()
} }
if debug == core.TraceFlagsSampled { if debug == FlagsSampled {
sampled = core.TraceFlagsSampled sampled = FlagsSampled
} }
sc := core.SpanContext{ sc := SpanContext{
TraceID: tid, TraceID: tid,
SpanID: sid, SpanID: sid,
TraceFlags: sampled, TraceFlags: sampled,
} }
if !sc.IsValid() { if !sc.IsValid() {
return core.EmptySpanContext() return EmptySpanContext()
} }
return sc return sc
} }
func (b3 B3) extractSingleHeader(supplier propagation.HTTPSupplier) core.SpanContext { func (b3 B3) extractSingleHeader(supplier propagation.HTTPSupplier) SpanContext {
h := supplier.Get(B3SingleHeader) h := supplier.Get(B3SingleHeader)
if h == "" || h == "0" { if h == "" || h == "0" {
return core.EmptySpanContext() return EmptySpanContext()
} }
sc := core.SpanContext{} sc := SpanContext{}
parts := strings.Split(h, "-") parts := strings.Split(h, "-")
l := len(parts) l := len(parts)
if l > 4 { if l > 4 {
return core.EmptySpanContext() return EmptySpanContext()
} }
if l < 2 { if l < 2 {
return core.EmptySpanContext() return EmptySpanContext()
} }
var err error var err error
sc.TraceID, err = core.TraceIDFromHex(parts[0]) sc.TraceID, err = IDFromHex(parts[0])
if err != nil { if err != nil {
return core.EmptySpanContext() return EmptySpanContext()
} }
sc.SpanID, err = core.SpanIDFromHex(parts[1]) sc.SpanID, err = SpanIDFromHex(parts[1])
if err != nil { if err != nil {
return core.EmptySpanContext() return EmptySpanContext()
} }
if l > 2 { if l > 2 {
var ok bool var ok bool
sc.TraceFlags, ok = b3.extractSampledState(parts[2]) sc.TraceFlags, ok = b3.extractSampledState(parts[2])
if !ok { if !ok {
return core.EmptySpanContext() return EmptySpanContext()
} }
} }
if l == 4 { if l == 4 {
_, err = core.SpanIDFromHex(parts[3]) _, err = SpanIDFromHex(parts[3])
if err != nil { if err != nil {
return core.EmptySpanContext() return EmptySpanContext()
} }
} }
if !sc.IsValid() { if !sc.IsValid() {
return core.EmptySpanContext() return EmptySpanContext()
} }
return sc return sc
@ -177,14 +176,14 @@ func (b3 B3) extractSampledState(sampled string) (flag byte, ok bool) {
case "", "0": case "", "0":
return 0, true return 0, true
case "1": case "1":
return core.TraceFlagsSampled, true return FlagsSampled, true
case "true": case "true":
if !b3.SingleHeader { if !b3.SingleHeader {
return core.TraceFlagsSampled, true return FlagsSampled, true
} }
case "d": case "d":
if b3.SingleHeader { if b3.SingleHeader {
return core.TraceFlagsSampled, true return FlagsSampled, true
} }
} }
return 0, false return 0, false
@ -196,7 +195,7 @@ func (b3 B3) extracDebugFlag(debug string) (flag byte, ok bool) {
case "", "0": case "", "0":
return 0, true return 0, true
case "1": case "1":
return core.TraceFlagsSampled, true return FlagsSampled, true
} }
return 0, false return 0, false
} }

View File

@ -16,8 +16,6 @@ package trace
import ( import (
"context" "context"
"go.opentelemetry.io/otel/api/core"
) )
type traceContextKeyType int type traceContextKeyType int
@ -43,15 +41,15 @@ func SpanFromContext(ctx context.Context) Span {
// ContextWithRemoteSpanContext creates a new context with a remote // ContextWithRemoteSpanContext creates a new context with a remote
// span context set to the passed span context. // span context set to the passed span context.
func ContextWithRemoteSpanContext(ctx context.Context, sc core.SpanContext) context.Context { func ContextWithRemoteSpanContext(ctx context.Context, sc SpanContext) context.Context {
return context.WithValue(ctx, remoteContextKey, sc) return context.WithValue(ctx, remoteContextKey, sc)
} }
// RemoteSpanContextFromContext returns the remote span context stored // RemoteSpanContextFromContext returns the remote span context stored
// in the context. // in the context.
func RemoteSpanContextFromContext(ctx context.Context) core.SpanContext { func RemoteSpanContextFromContext(ctx context.Context) SpanContext {
if sc, ok := ctx.Value(remoteContextKey).(core.SpanContext); ok { if sc, ok := ctx.Value(remoteContextKey).(SpanContext); ok {
return sc return sc
} }
return core.EmptySpanContext() return EmptySpanContext()
} }

View File

@ -72,8 +72,8 @@ type mockSpan struct{}
var _ trace.Span = mockSpan{} var _ trace.Span = mockSpan{}
// SpanContext returns an invalid span context. // SpanContext returns an invalid span context.
func (mockSpan) SpanContext() core.SpanContext { func (mockSpan) SpanContext() trace.SpanContext {
return core.EmptySpanContext() return trace.EmptySpanContext()
} }
// IsRecording always returns false for mockSpan. // IsRecording always returns false for mockSpan.

View File

@ -29,8 +29,8 @@ type NoopSpan struct {
var _ Span = (*NoopSpan)(nil) var _ Span = (*NoopSpan)(nil)
// SpanContext returns an invalid span context. // SpanContext returns an invalid span context.
func (NoopSpan) SpanContext() core.SpanContext { func (NoopSpan) SpanContext() SpanContext {
return core.EmptySpanContext() return EmptySpanContext()
} }
// IsRecording always returns false for NoopSpan. // IsRecording always returns false for NoopSpan.

View File

@ -21,10 +21,10 @@ type Sampler interface {
// or not sample the span to be created. Decision is based on a Sampler specific // or not sample the span to be created. Decision is based on a Sampler specific
// algorithm that takes into account one or more input parameters. // algorithm that takes into account one or more input parameters.
ShouldSample( ShouldSample(
sc core.SpanContext, sc SpanContext,
remote bool, remote bool,
traceID core.TraceID, traceID ID,
spanID core.SpanID, spanID SpanID,
spanName string, spanName string,
spanKind SpanKind, spanKind SpanKind,
attributes []core.KeyValue, attributes []core.KeyValue,

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package core package trace
import ( import (
"bytes" "bytes"
@ -24,10 +24,10 @@ const (
traceFlagsBitMaskSampled = byte(0x01) traceFlagsBitMaskSampled = byte(0x01)
traceFlagsBitMaskUnused = byte(0xFE) traceFlagsBitMaskUnused = byte(0xFE)
// TraceFlagsSampled is a byte with sampled bit set. It is a convenient value initializer // FlagsSampled is a byte with sampled bit set. It is a convenient value initializer
// for SpanContext TraceFlags field when a trace is sampled. // for SpanContext TraceFlags field when a trace is sampled.
TraceFlagsSampled = traceFlagsBitMaskSampled FlagsSampled = traceFlagsBitMaskSampled
TraceFlagsUnused = traceFlagsBitMaskUnused FlagsUnused = traceFlagsBitMaskUnused
ErrInvalidHexID errorConst = "trace-id and span-id can only contain [0-9a-f] characters, all lowercase" ErrInvalidHexID errorConst = "trace-id and span-id can only contain [0-9a-f] characters, all lowercase"
@ -44,26 +44,26 @@ func (e errorConst) Error() string {
return string(e) return string(e)
} }
// TraceID is a unique identity of a trace. // ID is a unique identity of a trace.
type TraceID [16]byte type ID [16]byte
var nilTraceID TraceID var nilTraceID ID
var _ json.Marshaler = nilTraceID var _ json.Marshaler = nilTraceID
// IsValid checks whether the trace ID is valid. A valid trace ID does // IsValid checks whether the trace ID is valid. A valid trace ID does
// not consist of zeros only. // not consist of zeros only.
func (t TraceID) IsValid() bool { func (t ID) IsValid() bool {
return !bytes.Equal(t[:], nilTraceID[:]) return !bytes.Equal(t[:], nilTraceID[:])
} }
// MarshalJSON implements a custom marshal function to encode TraceID // MarshalJSON implements a custom marshal function to encode TraceID
// as a hex string. // as a hex string.
func (t TraceID) MarshalJSON() ([]byte, error) { func (t ID) MarshalJSON() ([]byte, error) {
return json.Marshal(t.String()) return json.Marshal(t.String())
} }
// String returns the hex string representation form of a TraceID // String returns the hex string representation form of a TraceID
func (t TraceID) String() string { func (t ID) String() string {
return hex.EncodeToString(t[:]) return hex.EncodeToString(t[:])
} }
@ -90,11 +90,11 @@ func (s SpanID) String() string {
return hex.EncodeToString(s[:]) return hex.EncodeToString(s[:])
} }
// TraceIDFromHex returns a TraceID from a hex string if it is compliant // IDFromHex returns a TraceID from a hex string if it is compliant
// with the w3c trace-context specification. // with the w3c trace-context specification.
// See more at https://www.w3.org/TR/trace-context/#trace-id // See more at https://www.w3.org/TR/trace-context/#trace-id
func TraceIDFromHex(h string) (TraceID, error) { func IDFromHex(h string) (ID, error) {
t := TraceID{} t := ID{}
if len(h) != 32 { if len(h) != 32 {
return t, ErrInvalidTraceIDLength return t, ErrInvalidTraceIDLength
} }
@ -152,7 +152,7 @@ func decodeHex(h string, b []byte) error {
// SpanContext contains basic information about the span - its trace // SpanContext contains basic information about the span - its trace
// ID, span ID and trace flags. // ID, span ID and trace flags.
type SpanContext struct { type SpanContext struct {
TraceID TraceID TraceID ID
SpanID SpanID SpanID SpanID
TraceFlags byte TraceFlags byte
} }

View File

@ -12,19 +12,19 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package core_test package trace_test
import ( import (
"testing" "testing"
"go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/trace"
) )
func TestIsValid(t *testing.T) { func TestIsValid(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
tid core.TraceID tid trace.ID
sid core.SpanID sid trace.SpanID
want bool want bool
}{ }{
{ {
@ -34,23 +34,23 @@ func TestIsValid(t *testing.T) {
want: true, want: true,
}, { }, {
name: "SpanContext.IsValid() returns false if sc has neither an Trace ID nor Span ID", name: "SpanContext.IsValid() returns false if sc has neither an Trace ID nor Span ID",
tid: core.TraceID([16]byte{}), tid: trace.ID([16]byte{}),
sid: [8]byte{}, sid: [8]byte{},
want: false, want: false,
}, { }, {
name: "SpanContext.IsValid() returns false if sc has a Span ID but not a Trace ID", name: "SpanContext.IsValid() returns false if sc has a Span ID but not a Trace ID",
tid: core.TraceID([16]byte{}), tid: trace.ID([16]byte{}),
sid: [8]byte{42}, sid: [8]byte{42},
want: false, want: false,
}, { }, {
name: "SpanContext.IsValid() returns false if sc has a Trace ID but not a Span ID", name: "SpanContext.IsValid() returns false if sc has a Trace ID but not a Span ID",
tid: core.TraceID([16]byte{1}), tid: trace.ID([16]byte{1}),
sid: [8]byte{}, sid: [8]byte{},
want: false, want: false,
}, },
} { } {
t.Run(testcase.name, func(t *testing.T) { t.Run(testcase.name, func(t *testing.T) {
sc := core.SpanContext{ sc := trace.SpanContext{
TraceID: testcase.tid, TraceID: testcase.tid,
SpanID: testcase.sid, SpanID: testcase.sid,
} }
@ -66,12 +66,12 @@ func TestIsValidFromHex(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
hex string hex string
tid core.TraceID tid trace.ID
valid bool valid bool
}{ }{
{ {
name: "Valid TraceID", name: "Valid TraceID",
tid: core.TraceID([16]byte{128, 241, 152, 238, 86, 52, 59, 168, 100, 254, 139, 42, 87, 211, 239, 247}), tid: trace.ID([16]byte{128, 241, 152, 238, 86, 52, 59, 168, 100, 254, 139, 42, 87, 211, 239, 247}),
hex: "80f198ee56343ba864fe8b2a57d3eff7", hex: "80f198ee56343ba864fe8b2a57d3eff7",
valid: true, valid: true,
}, { }, {
@ -89,7 +89,7 @@ func TestIsValidFromHex(t *testing.T) {
}, },
} { } {
t.Run(testcase.name, func(t *testing.T) { t.Run(testcase.name, func(t *testing.T) {
tid, err := core.TraceIDFromHex(testcase.hex) tid, err := trace.IDFromHex(testcase.hex)
if testcase.valid && err != nil { if testcase.valid && err != nil {
t.Errorf("Expected TraceID %s to be valid but end with error %s", testcase.hex, err.Error()) t.Errorf("Expected TraceID %s to be valid but end with error %s", testcase.hex, err.Error())
@ -109,22 +109,22 @@ func TestIsValidFromHex(t *testing.T) {
func TestHasTraceID(t *testing.T) { func TestHasTraceID(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
tid core.TraceID tid trace.ID
want bool want bool
}{ }{
{ {
name: "SpanContext.HasTraceID() returns true if both Low and High are nonzero", name: "SpanContext.HasTraceID() returns true if both Low and High are nonzero",
tid: core.TraceID([16]byte{1}), tid: trace.ID([16]byte{1}),
want: true, want: true,
}, { }, {
name: "SpanContext.HasTraceID() returns false if neither Low nor High are nonzero", name: "SpanContext.HasTraceID() returns false if neither Low nor High are nonzero",
tid: core.TraceID{}, tid: trace.ID{},
want: false, want: false,
}, },
} { } {
t.Run(testcase.name, func(t *testing.T) { t.Run(testcase.name, func(t *testing.T) {
//proto: func (sc SpanContext) HasTraceID() bool{} //proto: func (sc SpanContext) HasTraceID() bool{}
sc := core.SpanContext{TraceID: testcase.tid} sc := trace.SpanContext{TraceID: testcase.tid}
have := sc.HasTraceID() have := sc.HasTraceID()
if have != testcase.want { if have != testcase.want {
t.Errorf("Want: %v, but have: %v", testcase.want, have) t.Errorf("Want: %v, but have: %v", testcase.want, have)
@ -136,16 +136,16 @@ func TestHasTraceID(t *testing.T) {
func TestHasSpanID(t *testing.T) { func TestHasSpanID(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
sc core.SpanContext sc trace.SpanContext
want bool want bool
}{ }{
{ {
name: "SpanContext.HasSpanID() returns true if self.SpanID != 0", name: "SpanContext.HasSpanID() returns true if self.SpanID != 0",
sc: core.SpanContext{SpanID: [8]byte{42}}, sc: trace.SpanContext{SpanID: [8]byte{42}},
want: true, want: true,
}, { }, {
name: "SpanContext.HasSpanID() returns false if self.SpanID == 0", name: "SpanContext.HasSpanID() returns false if self.SpanID == 0",
sc: core.SpanContext{}, sc: trace.SpanContext{},
want: false, want: false,
}, },
} { } {
@ -162,26 +162,26 @@ func TestHasSpanID(t *testing.T) {
func TestSpanContextIsSampled(t *testing.T) { func TestSpanContextIsSampled(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
sc core.SpanContext sc trace.SpanContext
want bool want bool
}{ }{
{ {
name: "sampled", name: "sampled",
sc: core.SpanContext{ sc: trace.SpanContext{
TraceID: core.TraceID([16]byte{1}), TraceID: trace.ID([16]byte{1}),
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
want: true, want: true,
}, { }, {
name: "sampled plus unused", name: "sampled plus unused",
sc: core.SpanContext{ sc: trace.SpanContext{
TraceID: core.TraceID([16]byte{1}), TraceID: trace.ID([16]byte{1}),
TraceFlags: core.TraceFlagsSampled | core.TraceFlagsUnused, TraceFlags: trace.FlagsSampled | trace.FlagsUnused,
}, },
want: true, want: true,
}, { }, {
name: "not sampled/default", name: "not sampled/default",
sc: core.SpanContext{TraceID: core.TraceID{}}, sc: trace.SpanContext{TraceID: trace.ID{}},
want: false, want: false,
}, },
} { } {
@ -197,17 +197,17 @@ func TestSpanContextIsSampled(t *testing.T) {
func TestStringTraceID(t *testing.T) { func TestStringTraceID(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
tid core.TraceID tid trace.ID
want string want string
}{ }{
{ {
name: "TraceID.String returns string representation of self.TraceID values > 0", name: "TraceID.String returns string representation of self.TraceID values > 0",
tid: core.TraceID([16]byte{255}), tid: trace.ID([16]byte{255}),
want: "ff000000000000000000000000000000", want: "ff000000000000000000000000000000",
}, },
{ {
name: "TraceID.String returns string representation of self.TraceID values == 0", name: "TraceID.String returns string representation of self.TraceID values == 0",
tid: core.TraceID([16]byte{}), tid: trace.ID([16]byte{}),
want: "00000000000000000000000000000000", want: "00000000000000000000000000000000",
}, },
} { } {
@ -224,17 +224,17 @@ func TestStringTraceID(t *testing.T) {
func TestStringSpanID(t *testing.T) { func TestStringSpanID(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string name string
sid core.SpanID sid trace.SpanID
want string want string
}{ }{
{ {
name: "SpanID.String returns string representation of self.SpanID values > 0", name: "SpanID.String returns string representation of self.SpanID values > 0",
sid: core.SpanID([8]byte{255}), sid: trace.SpanID([8]byte{255}),
want: "ff00000000000000", want: "ff00000000000000",
}, },
{ {
name: "SpanID.String returns string representation of self.SpanID values == 0", name: "SpanID.String returns string representation of self.SpanID values == 0",
sid: core.SpanID([8]byte{}), sid: trace.SpanID([8]byte{}),
want: "0000000000000000", want: "0000000000000000",
}, },
} { } {

View File

@ -15,14 +15,13 @@
package testtrace_test package testtrace_test
import ( import (
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
) )
type extractTest struct { type extractTest struct {
name string name string
headers map[string]string headers map[string]string
wantSc core.SpanContext wantSc trace.SpanContext
} }
var extractMultipleHeaders = []extractTest{ var extractMultipleHeaders = []extractTest{
@ -32,7 +31,7 @@ var extractMultipleHeaders = []extractTest{
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3SpanIDHeader: "00f067aa0ba902b7",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -44,7 +43,7 @@ var extractMultipleHeaders = []extractTest{
trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3SpanIDHeader: "00f067aa0ba902b7",
trace.B3SampledHeader: "0", trace.B3SampledHeader: "0",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -56,10 +55,10 @@ var extractMultipleHeaders = []extractTest{
trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3SpanIDHeader: "00f067aa0ba902b7",
trace.B3SampledHeader: "1", trace.B3SampledHeader: "1",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
@ -69,10 +68,10 @@ var extractMultipleHeaders = []extractTest{
trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3SpanIDHeader: "00f067aa0ba902b7",
trace.B3SampledHeader: "true", trace.B3SampledHeader: "true",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
@ -82,10 +81,10 @@ var extractMultipleHeaders = []extractTest{
trace.B3SpanIDHeader: "00f067aa0ba902b7", trace.B3SpanIDHeader: "00f067aa0ba902b7",
trace.B3DebugFlagHeader: "1", trace.B3DebugFlagHeader: "1",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
@ -99,10 +98,10 @@ var extractMultipleHeaders = []extractTest{
trace.B3SampledHeader: "0", trace.B3SampledHeader: "0",
trace.B3DebugFlagHeader: "1", trace.B3DebugFlagHeader: "1",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
@ -113,10 +112,10 @@ var extractMultipleHeaders = []extractTest{
trace.B3SampledHeader: "1", trace.B3SampledHeader: "1",
trace.B3ParentSpanIDHeader: "00f067aa0ba90200", trace.B3ParentSpanIDHeader: "00f067aa0ba90200",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
@ -124,7 +123,7 @@ var extractMultipleHeaders = []extractTest{
headers: map[string]string{ headers: map[string]string{
trace.B3SampledHeader: "0", trace.B3SampledHeader: "0",
}, },
wantSc: core.EmptySpanContext(), wantSc: trace.EmptySpanContext(),
}, },
} }
@ -134,7 +133,7 @@ var extractSingleHeader = []extractTest{
headers: map[string]string{ headers: map[string]string{
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7", trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -144,7 +143,7 @@ var extractSingleHeader = []extractTest{
headers: map[string]string{ headers: map[string]string{
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-0", trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-0",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -154,10 +153,10 @@ var extractSingleHeader = []extractTest{
headers: map[string]string{ headers: map[string]string{
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1", trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
@ -165,10 +164,10 @@ var extractSingleHeader = []extractTest{
headers: map[string]string{ headers: map[string]string{
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d", trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
@ -176,10 +175,10 @@ var extractSingleHeader = []extractTest{
headers: map[string]string{ headers: map[string]string{
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1-00000000000000cd", trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-1-00000000000000cd",
}, },
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
@ -187,7 +186,7 @@ var extractSingleHeader = []extractTest{
headers: map[string]string{ headers: map[string]string{
trace.B3SingleHeader: "0", trace.B3SingleHeader: "0",
}, },
wantSc: core.EmptySpanContext(), wantSc: trace.EmptySpanContext(),
}, },
} }
@ -436,7 +435,7 @@ var extractInvalidB3SingleHeader = []extractTest{
type injectTest struct { type injectTest struct {
name string name string
parentSc core.SpanContext parentSc trace.SpanContext
wantHeaders map[string]string wantHeaders map[string]string
doNotWantHeaders []string doNotWantHeaders []string
} }
@ -444,10 +443,10 @@ type injectTest struct {
var injectB3MultipleHeader = []injectTest{ var injectB3MultipleHeader = []injectTest{
{ {
name: "valid spancontext, sampled", name: "valid spancontext, sampled",
parentSc: core.SpanContext{ parentSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
wantHeaders: map[string]string{ wantHeaders: map[string]string{
trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736", trace.B3TraceIDHeader: "4bf92f3577b34da6a3ce929d0e0e4736",
@ -460,7 +459,7 @@ var injectB3MultipleHeader = []injectTest{
}, },
{ {
name: "valid spancontext, not sampled", name: "valid spancontext, not sampled",
parentSc: core.SpanContext{ parentSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -475,7 +474,7 @@ var injectB3MultipleHeader = []injectTest{
}, },
{ {
name: "valid spancontext, with unsupported bit set in traceflags", name: "valid spancontext, with unsupported bit set in traceflags",
parentSc: core.SpanContext{ parentSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: 0xff, TraceFlags: 0xff,
@ -494,10 +493,10 @@ var injectB3MultipleHeader = []injectTest{
var injectB3SingleleHeader = []injectTest{ var injectB3SingleleHeader = []injectTest{
{ {
name: "valid spancontext, sampled", name: "valid spancontext, sampled",
parentSc: core.SpanContext{ parentSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
wantHeaders: map[string]string{ wantHeaders: map[string]string{
trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1", trace.B3SingleHeader: "4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-1",
@ -511,7 +510,7 @@ var injectB3SingleleHeader = []injectTest{
}, },
{ {
name: "valid spancontext, not sampled", name: "valid spancontext, not sampled",
parentSc: core.SpanContext{ parentSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -527,7 +526,7 @@ var injectB3SingleleHeader = []injectTest{
}, },
{ {
name: "valid spancontext, with unsupported bit set in traceflags", name: "valid spancontext, with unsupported bit set in traceflags",
parentSc: core.SpanContext{ parentSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: 0xff, TraceFlags: 0xff,

View File

@ -18,12 +18,12 @@ import (
"encoding/binary" "encoding/binary"
"sync" "sync"
"go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/trace"
) )
type Generator interface { type Generator interface {
TraceID() core.TraceID TraceID() trace.ID
SpanID() core.SpanID SpanID() trace.SpanID
} }
var _ Generator = (*CountGenerator)(nil) var _ Generator = (*CountGenerator)(nil)
@ -41,7 +41,7 @@ func NewCountGenerator() *CountGenerator {
return &CountGenerator{} return &CountGenerator{}
} }
func (g *CountGenerator) TraceID() core.TraceID { func (g *CountGenerator) TraceID() trace.ID {
g.lock.Lock() g.lock.Lock()
defer g.lock.Unlock() defer g.lock.Unlock()
@ -51,7 +51,7 @@ func (g *CountGenerator) TraceID() core.TraceID {
g.traceIDLow++ g.traceIDLow++
} }
var traceID core.TraceID var traceID trace.ID
binary.BigEndian.PutUint64(traceID[0:8], g.traceIDLow) binary.BigEndian.PutUint64(traceID[0:8], g.traceIDLow)
binary.BigEndian.PutUint64(traceID[8:], g.traceIDHigh) binary.BigEndian.PutUint64(traceID[8:], g.traceIDHigh)
@ -59,13 +59,13 @@ func (g *CountGenerator) TraceID() core.TraceID {
return traceID return traceID
} }
func (g *CountGenerator) SpanID() core.SpanID { func (g *CountGenerator) SpanID() trace.SpanID {
g.lock.Lock() g.lock.Lock()
defer g.lock.Unlock() defer g.lock.Unlock()
g.spanID++ g.spanID++
var spanID core.SpanID var spanID trace.SpanID
binary.BigEndian.PutUint64(spanID[:], g.spanID) binary.BigEndian.PutUint64(spanID[:], g.spanID)

View File

@ -21,7 +21,6 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
) )
@ -33,11 +32,11 @@ type outOfThinAirPropagator struct {
var _ propagation.HTTPPropagator = outOfThinAirPropagator{} var _ propagation.HTTPPropagator = outOfThinAirPropagator{}
func (p outOfThinAirPropagator) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context { func (p outOfThinAirPropagator) Extract(ctx context.Context, supplier propagation.HTTPSupplier) context.Context {
traceID, err := core.TraceIDFromHex("938753245abe987f098c0987a9873987") traceID, err := trace.IDFromHex("938753245abe987f098c0987a9873987")
require.NoError(p.t, err) require.NoError(p.t, err)
spanID, err := core.SpanIDFromHex("2345f98c0987a09d") spanID, err := trace.SpanIDFromHex("2345f98c0987a09d")
require.NoError(p.t, err) require.NoError(p.t, err)
sc := core.SpanContext{ sc := trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: 0, TraceFlags: 0,

View File

@ -39,8 +39,8 @@ var _ trace.Span = (*Span)(nil)
type Span struct { type Span struct {
lock *sync.RWMutex lock *sync.RWMutex
tracer *Tracer tracer *Tracer
spanContext core.SpanContext spanContext trace.SpanContext
parentSpanID core.SpanID parentSpanID trace.SpanID
ended bool ended bool
name string name string
startTime time.Time startTime time.Time
@ -49,7 +49,7 @@ type Span struct {
statusMessage string statusMessage string
attributes map[core.Key]core.Value attributes map[core.Key]core.Value
events []Event events []Event
links map[core.SpanContext][]core.KeyValue links map[trace.SpanContext][]core.KeyValue
} }
func (s *Span) Tracer() trace.Tracer { func (s *Span) Tracer() trace.Tracer {
@ -138,7 +138,7 @@ func (s *Span) IsRecording() bool {
return true return true
} }
func (s *Span) SpanContext() core.SpanContext { func (s *Span) SpanContext() trace.SpanContext {
return s.spanContext return s.spanContext
} }
@ -191,7 +191,7 @@ func (s *Span) Name() string {
// ParentSpanID returns the SpanID of the parent Span. // ParentSpanID returns the SpanID of the parent Span.
// If the Span is a root Span and therefore does not have a parent, the returned SpanID will be invalid // If the Span is a root Span and therefore does not have a parent, the returned SpanID will be invalid
// (i.e., it will contain all zeroes). // (i.e., it will contain all zeroes).
func (s *Span) ParentSpanID() core.SpanID { func (s *Span) ParentSpanID() trace.SpanID {
return s.parentSpanID return s.parentSpanID
} }
@ -219,8 +219,8 @@ func (s *Span) Events() []Event {
// Links returns the links set on the Span at creation time. // Links returns the links set on the Span at creation time.
// If multiple links for the same SpanContext were set, the last link will be used. // If multiple links for the same SpanContext were set, the last link will be used.
func (s *Span) Links() map[core.SpanContext][]core.KeyValue { func (s *Span) Links() map[trace.SpanContext][]core.KeyValue {
links := make(map[core.SpanContext][]core.KeyValue) links := make(map[trace.SpanContext][]core.KeyValue)
for sc, attributes := range s.links { for sc, attributes := range s.links {
links[sc] = append([]core.KeyValue{}, attributes...) links[sc] = append([]core.KeyValue{}, attributes...)

View File

@ -19,7 +19,6 @@ import (
"net/http" "net/http"
"testing" "testing"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
mocktrace "go.opentelemetry.io/otel/internal/trace" mocktrace "go.opentelemetry.io/otel/internal/trace"
) )
@ -39,18 +38,18 @@ func BenchmarkInject(b *testing.B) {
func injectSubBenchmarks(b *testing.B, fn func(context.Context, *testing.B)) { func injectSubBenchmarks(b *testing.B, fn func(context.Context, *testing.B)) {
b.Run("SampledSpanContext", func(b *testing.B) { b.Run("SampledSpanContext", func(b *testing.B) {
var id uint64 var id uint64
spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7") spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7")
traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") traceID, _ := trace.IDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
mockTracer := &mocktrace.MockTracer{ mockTracer := &mocktrace.MockTracer{
Sampled: false, Sampled: false,
StartSpanID: &id, StartSpanID: &id,
} }
b.ReportAllocs() b.ReportAllocs()
sc := core.SpanContext{ sc := trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
} }
ctx := trace.ContextWithRemoteSpanContext(context.Background(), sc) ctx := trace.ContextWithRemoteSpanContext(context.Background(), sc)
ctx, _ = mockTracer.Start(ctx, "inject") ctx, _ = mockTracer.Start(ctx, "inject")

View File

@ -21,7 +21,6 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
mocktrace "go.opentelemetry.io/otel/internal/trace" mocktrace "go.opentelemetry.io/otel/internal/trace"
@ -32,13 +31,13 @@ var (
spanID = mustSpanIDFromHex("00f067aa0ba902b7") spanID = mustSpanIDFromHex("00f067aa0ba902b7")
) )
func mustTraceIDFromHex(s string) (t core.TraceID) { func mustTraceIDFromHex(s string) (t trace.ID) {
t, _ = core.TraceIDFromHex(s) t, _ = trace.IDFromHex(s)
return return
} }
func mustSpanIDFromHex(s string) (t core.SpanID) { func mustSpanIDFromHex(s string) (t trace.SpanID) {
t, _ = core.SpanIDFromHex(s) t, _ = trace.SpanIDFromHex(s)
return return
} }
@ -47,12 +46,12 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
header string header string
wantSc core.SpanContext wantSc trace.SpanContext
}{ }{
{ {
name: "valid w3cHeader", name: "valid w3cHeader",
header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00", header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00",
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -60,34 +59,34 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
{ {
name: "valid w3cHeader and sampled", name: "valid w3cHeader and sampled",
header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
name: "future version", name: "future version",
header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
name: "future options with sampled bit set", name: "future options with sampled bit set",
header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09",
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
name: "future options with sampled bit cleared", name: "future options with sampled bit cleared",
header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-08", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-08",
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -95,28 +94,28 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
{ {
name: "future additional data", name: "future additional data",
header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-XYZxsf09", header: "02-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-XYZxsf09",
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
name: "valid b3Header ending in dash", name: "valid b3Header ending in dash",
header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01-", header: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01-",
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
{ {
name: "future valid b3Header ending in dash", name: "future valid b3Header ending in dash",
header: "01-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-", header: "01-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-09-",
wantSc: core.SpanContext{ wantSc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
}, },
} }
@ -137,7 +136,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
} }
func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) { func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) {
wantSc := core.EmptySpanContext() wantSc := trace.EmptySpanContext()
props := propagation.New(propagation.WithExtractors(trace.TraceContext{})) props := propagation.New(propagation.WithExtractors(trace.TraceContext{}))
tests := []struct { tests := []struct {
name string name string
@ -233,21 +232,21 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
props := propagation.New(propagation.WithInjectors(trace.TraceContext{})) props := propagation.New(propagation.WithInjectors(trace.TraceContext{}))
tests := []struct { tests := []struct {
name string name string
sc core.SpanContext sc trace.SpanContext
wantHeader string wantHeader string
}{ }{
{ {
name: "valid spancontext, sampled", name: "valid spancontext, sampled",
sc: core.SpanContext{ sc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
}, },
wantHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-01", wantHeader: "00-4bf92f3577b34da6a3ce929d0e0e4736-0000000000000001-01",
}, },
{ {
name: "valid spancontext, not sampled", name: "valid spancontext, not sampled",
sc: core.SpanContext{ sc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -255,7 +254,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
}, },
{ {
name: "valid spancontext, with unsupported bit set in traceflags", name: "valid spancontext, with unsupported bit set in traceflags",
sc: core.SpanContext{ sc: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: 0xff, TraceFlags: 0xff,
@ -264,7 +263,7 @@ func TestInjectTraceContextToHTTPReq(t *testing.T) {
}, },
{ {
name: "invalid spancontext", name: "invalid spancontext",
sc: core.EmptySpanContext(), sc: trace.EmptySpanContext(),
wantHeader: "", wantHeader: "",
}, },
} }

View File

@ -51,8 +51,8 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti
opt(&c) opt(&c)
} }
var traceID core.TraceID var traceID trace.ID
var parentSpanID core.SpanID var parentSpanID trace.SpanID
parentSpanContext, _, links := parent.GetSpanContextAndLinks(ctx, c.NewRoot) parentSpanContext, _, links := parent.GetSpanContextAndLinks(ctx, c.NewRoot)
@ -75,13 +75,13 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti
lock: &sync.RWMutex{}, lock: &sync.RWMutex{},
tracer: t, tracer: t,
startTime: startTime, startTime: startTime,
spanContext: core.SpanContext{ spanContext: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
parentSpanID: parentSpanID, parentSpanID: parentSpanID,
attributes: make(map[core.Key]core.Value), attributes: make(map[core.Key]core.Value),
links: make(map[core.SpanContext][]core.KeyValue), links: make(map[trace.SpanContext][]core.KeyValue),
} }
span.SetName(name) span.SetName(name)

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/propagation"
) )
@ -63,7 +62,7 @@ func (TraceContext) Inject(ctx context.Context, supplier propagation.HTTPSupplie
supportedVersion, supportedVersion,
sc.TraceID, sc.TraceID,
sc.SpanID, sc.SpanID,
sc.TraceFlags&core.TraceFlagsSampled) sc.TraceFlags&FlagsSampled)
supplier.Set(traceparentHeader, h) supplier.Set(traceparentHeader, h)
} }
@ -80,68 +79,68 @@ func (tc TraceContext) Extract(ctx context.Context, supplier propagation.HTTPSup
return ContextWithRemoteSpanContext(ctx, sc) return ContextWithRemoteSpanContext(ctx, sc)
} }
func (TraceContext) extract(supplier propagation.HTTPSupplier) core.SpanContext { func (TraceContext) extract(supplier propagation.HTTPSupplier) SpanContext {
h := supplier.Get(traceparentHeader) h := supplier.Get(traceparentHeader)
if h == "" { if h == "" {
return core.EmptySpanContext() return EmptySpanContext()
} }
matches := traceCtxRegExp.FindStringSubmatch(h) matches := traceCtxRegExp.FindStringSubmatch(h)
if len(matches) == 0 { if len(matches) == 0 {
return core.EmptySpanContext() return EmptySpanContext()
} }
if len(matches) < 5 { // four subgroups plus the overall match if len(matches) < 5 { // four subgroups plus the overall match
return core.EmptySpanContext() return EmptySpanContext()
} }
if len(matches[1]) != 2 { if len(matches[1]) != 2 {
return core.EmptySpanContext() return EmptySpanContext()
} }
ver, err := hex.DecodeString(matches[1]) ver, err := hex.DecodeString(matches[1])
if err != nil { if err != nil {
return core.EmptySpanContext() return EmptySpanContext()
} }
version := int(ver[0]) version := int(ver[0])
if version > maxVersion { if version > maxVersion {
return core.EmptySpanContext() return EmptySpanContext()
} }
if version == 0 && len(matches) != 5 { // four subgroups plus the overall match if version == 0 && len(matches) != 5 { // four subgroups plus the overall match
return core.EmptySpanContext() return EmptySpanContext()
} }
if len(matches[2]) != 32 { if len(matches[2]) != 32 {
return core.EmptySpanContext() return EmptySpanContext()
} }
var sc core.SpanContext var sc SpanContext
sc.TraceID, err = core.TraceIDFromHex(matches[2][:32]) sc.TraceID, err = IDFromHex(matches[2][:32])
if err != nil { if err != nil {
return core.EmptySpanContext() return EmptySpanContext()
} }
if len(matches[3]) != 16 { if len(matches[3]) != 16 {
return core.EmptySpanContext() return EmptySpanContext()
} }
sc.SpanID, err = core.SpanIDFromHex(matches[3]) sc.SpanID, err = SpanIDFromHex(matches[3])
if err != nil { if err != nil {
return core.EmptySpanContext() return EmptySpanContext()
} }
if len(matches[4]) != 2 { if len(matches[4]) != 2 {
return core.EmptySpanContext() return EmptySpanContext()
} }
opts, err := hex.DecodeString(matches[4]) opts, err := hex.DecodeString(matches[4])
if err != nil || len(opts) < 1 || (version == 0 && opts[0] > 2) { if err != nil || len(opts) < 1 || (version == 0 && opts[0] > 2) {
return core.EmptySpanContext() return EmptySpanContext()
} }
sc.TraceFlags = opts[0] &^ core.TraceFlagsUnused sc.TraceFlags = opts[0] &^ FlagsUnused
if !sc.IsValid() { if !sc.IsValid() {
return core.EmptySpanContext() return EmptySpanContext()
} }
return sc return sc

View File

@ -40,12 +40,12 @@ import (
type bridgeSpanContext struct { type bridgeSpanContext struct {
baggageItems otelcorrelation.Map baggageItems otelcorrelation.Map
otelSpanContext otelcore.SpanContext otelSpanContext oteltrace.SpanContext
} }
var _ ot.SpanContext = &bridgeSpanContext{} var _ ot.SpanContext = &bridgeSpanContext{}
func newBridgeSpanContext(otelSpanContext otelcore.SpanContext, parentOtSpanContext ot.SpanContext) *bridgeSpanContext { func newBridgeSpanContext(otelSpanContext oteltrace.SpanContext, parentOtSpanContext ot.SpanContext) *bridgeSpanContext {
bCtx := &bridgeSpanContext{ bCtx := &bridgeSpanContext{
baggageItems: otelcorrelation.NewEmptyMap(), baggageItems: otelcorrelation.NewEmptyMap(),
otelSpanContext: otelSpanContext, otelSpanContext: otelSpanContext,
@ -582,10 +582,10 @@ func otSpanReferenceTypeToString(refType ot.SpanReferenceType) string {
type fakeSpan struct { type fakeSpan struct {
oteltrace.NoopSpan oteltrace.NoopSpan
sc otelcore.SpanContext sc oteltrace.SpanContext
} }
func (s fakeSpan) SpanContext() otelcore.SpanContext { func (s fakeSpan) SpanContext() oteltrace.SpanContext {
return s.sc return s.sc
} }

View File

@ -49,8 +49,8 @@ type MockContextKeyValue struct {
type MockTracer struct { type MockTracer struct {
Resources otelcorrelation.Map Resources otelcorrelation.Map
FinishedSpans []*MockSpan FinishedSpans []*MockSpan
SpareTraceIDs []otelcore.TraceID SpareTraceIDs []oteltrace.ID
SpareSpanIDs []otelcore.SpanID SpareSpanIDs []oteltrace.SpanID
SpareContextKeyValues []MockContextKeyValue SpareContextKeyValues []MockContextKeyValue
randLock sync.Mutex randLock sync.Mutex
@ -87,7 +87,7 @@ func (t *MockTracer) Start(ctx context.Context, name string, opts ...oteltrace.S
if startTime.IsZero() { if startTime.IsZero() {
startTime = time.Now() startTime = time.Now()
} }
spanContext := otelcore.SpanContext{ spanContext := oteltrace.SpanContext{
TraceID: t.getTraceID(ctx, &spanOpts), TraceID: t.getTraceID(ctx, &spanOpts),
SpanID: t.getSpanID(), SpanID: t.getSpanID(),
TraceFlags: 0, TraceFlags: 0,
@ -126,7 +126,7 @@ func (t *MockTracer) addSpareContextValue(ctx context.Context) context.Context {
return ctx return ctx
} }
func (t *MockTracer) getTraceID(ctx context.Context, spanOpts *oteltrace.StartConfig) otelcore.TraceID { func (t *MockTracer) getTraceID(ctx context.Context, spanOpts *oteltrace.StartConfig) oteltrace.ID {
if parent := t.getParentSpanContext(ctx, spanOpts); parent.IsValid() { if parent := t.getParentSpanContext(ctx, spanOpts); parent.IsValid() {
return parent.TraceID return parent.TraceID
} }
@ -141,19 +141,19 @@ func (t *MockTracer) getTraceID(ctx context.Context, spanOpts *oteltrace.StartCo
return t.getRandTraceID() return t.getRandTraceID()
} }
func (t *MockTracer) getParentSpanID(ctx context.Context, spanOpts *oteltrace.StartConfig) otelcore.SpanID { func (t *MockTracer) getParentSpanID(ctx context.Context, spanOpts *oteltrace.StartConfig) oteltrace.SpanID {
if parent := t.getParentSpanContext(ctx, spanOpts); parent.IsValid() { if parent := t.getParentSpanContext(ctx, spanOpts); parent.IsValid() {
return parent.SpanID return parent.SpanID
} }
return otelcore.SpanID{} return oteltrace.SpanID{}
} }
func (t *MockTracer) getParentSpanContext(ctx context.Context, spanOpts *oteltrace.StartConfig) otelcore.SpanContext { func (t *MockTracer) getParentSpanContext(ctx context.Context, spanOpts *oteltrace.StartConfig) oteltrace.SpanContext {
spanCtx, _, _ := otelparent.GetSpanContextAndLinks(ctx, spanOpts.NewRoot) spanCtx, _, _ := otelparent.GetSpanContextAndLinks(ctx, spanOpts.NewRoot)
return spanCtx return spanCtx
} }
func (t *MockTracer) getSpanID() otelcore.SpanID { func (t *MockTracer) getSpanID() oteltrace.SpanID {
if len(t.SpareSpanIDs) > 0 { if len(t.SpareSpanIDs) > 0 {
spanID := t.SpareSpanIDs[0] spanID := t.SpareSpanIDs[0]
t.SpareSpanIDs = t.SpareSpanIDs[1:] t.SpareSpanIDs = t.SpareSpanIDs[1:]
@ -165,21 +165,21 @@ func (t *MockTracer) getSpanID() otelcore.SpanID {
return t.getRandSpanID() return t.getRandSpanID()
} }
func (t *MockTracer) getRandSpanID() otelcore.SpanID { func (t *MockTracer) getRandSpanID() oteltrace.SpanID {
t.randLock.Lock() t.randLock.Lock()
defer t.randLock.Unlock() defer t.randLock.Unlock()
sid := otelcore.SpanID{} sid := oteltrace.SpanID{}
t.rand.Read(sid[:]) t.rand.Read(sid[:])
return sid return sid
} }
func (t *MockTracer) getRandTraceID() otelcore.TraceID { func (t *MockTracer) getRandTraceID() oteltrace.ID {
t.randLock.Lock() t.randLock.Lock()
defer t.randLock.Unlock() defer t.randLock.Unlock()
tid := otelcore.TraceID{} tid := oteltrace.ID{}
t.rand.Read(tid[:]) t.rand.Read(tid[:])
return tid return tid
@ -199,21 +199,21 @@ type MockEvent struct {
type MockSpan struct { type MockSpan struct {
mockTracer *MockTracer mockTracer *MockTracer
officialTracer oteltrace.Tracer officialTracer oteltrace.Tracer
spanContext otelcore.SpanContext spanContext oteltrace.SpanContext
SpanKind oteltrace.SpanKind SpanKind oteltrace.SpanKind
recording bool recording bool
Attributes otelcorrelation.Map Attributes otelcorrelation.Map
StartTime time.Time StartTime time.Time
EndTime time.Time EndTime time.Time
ParentSpanID otelcore.SpanID ParentSpanID oteltrace.SpanID
Events []MockEvent Events []MockEvent
} }
var _ oteltrace.Span = &MockSpan{} var _ oteltrace.Span = &MockSpan{}
var _ migration.OverrideTracerSpanExtension = &MockSpan{} var _ migration.OverrideTracerSpanExtension = &MockSpan{}
func (s *MockSpan) SpanContext() otelcore.SpanContext { func (s *MockSpan) SpanContext() oteltrace.SpanContext {
return s.spanContext return s.spanContext
} }

View File

@ -143,8 +143,8 @@ func TestMixedAPIs(t *testing.T) {
// simple test // simple test
type simpleTest struct { type simpleTest struct {
traceID otelcore.TraceID traceID oteltrace.ID
spanIDs []otelcore.SpanID spanIDs []oteltrace.SpanID
} }
func newSimpleTest() *simpleTest { func newSimpleTest() *simpleTest {
@ -178,11 +178,11 @@ func (st *simpleTest) noop(t *testing.T, ctx context.Context) context.Context {
// current/active span test // current/active span test
type currentActiveSpanTest struct { type currentActiveSpanTest struct {
traceID otelcore.TraceID traceID oteltrace.ID
spanIDs []otelcore.SpanID spanIDs []oteltrace.SpanID
recordedCurrentOtelSpanIDs []otelcore.SpanID recordedCurrentOtelSpanIDs []oteltrace.SpanID
recordedActiveOTSpanIDs []otelcore.SpanID recordedActiveOTSpanIDs []oteltrace.SpanID
} }
func newCurrentActiveSpanTest() *currentActiveSpanTest { func newCurrentActiveSpanTest() *currentActiveSpanTest {
@ -233,7 +233,7 @@ func (cast *currentActiveSpanTest) recordSpans(t *testing.T, ctx context.Context
spanID := oteltrace.SpanFromContext(ctx).SpanContext().SpanID spanID := oteltrace.SpanFromContext(ctx).SpanContext().SpanID
cast.recordedCurrentOtelSpanIDs = append(cast.recordedCurrentOtelSpanIDs, spanID) cast.recordedCurrentOtelSpanIDs = append(cast.recordedCurrentOtelSpanIDs, spanID)
spanID = otelcore.SpanID{} spanID = oteltrace.SpanID{}
if bridgeSpan, ok := ot.SpanFromContext(ctx).(*bridgeSpan); ok { if bridgeSpan, ok := ot.SpanFromContext(ctx).(*bridgeSpan); ok {
spanID = bridgeSpan.otelSpan.SpanContext().SpanID spanID = bridgeSpan.otelSpan.SpanContext().SpanID
} }
@ -614,20 +614,20 @@ func generateBaggageKeys(key string) (otKey, otelKey string) {
// helpers // helpers
func checkTraceAndSpans(t *testing.T, tracer *internal.MockTracer, expectedTraceID otelcore.TraceID, expectedSpanIDs []otelcore.SpanID) { func checkTraceAndSpans(t *testing.T, tracer *internal.MockTracer, expectedTraceID oteltrace.ID, expectedSpanIDs []oteltrace.SpanID) {
expectedSpanCount := len(expectedSpanIDs) expectedSpanCount := len(expectedSpanIDs)
// reverse spanIDs, since first span ID belongs to root, that // reverse spanIDs, since first span ID belongs to root, that
// finishes last // finishes last
spanIDs := make([]otelcore.SpanID, len(expectedSpanIDs)) spanIDs := make([]oteltrace.SpanID, len(expectedSpanIDs))
copy(spanIDs, expectedSpanIDs) copy(spanIDs, expectedSpanIDs)
reverse(len(spanIDs), func(i, j int) { reverse(len(spanIDs), func(i, j int) {
spanIDs[i], spanIDs[j] = spanIDs[j], spanIDs[i] spanIDs[i], spanIDs[j] = spanIDs[j], spanIDs[i]
}) })
// the last finished span has no parent // the last finished span has no parent
parentSpanIDs := append(spanIDs[1:], otelcore.SpanID{}) parentSpanIDs := append(spanIDs[1:], oteltrace.SpanID{})
sks := map[otelcore.SpanID]oteltrace.SpanKind{ sks := map[oteltrace.SpanID]oteltrace.SpanKind{
{125}: oteltrace.SpanKindProducer, {125}: oteltrace.SpanKindProducer,
{124}: oteltrace.SpanKindInternal, {124}: oteltrace.SpanKindInternal,
{123}: oteltrace.SpanKindClient, {123}: oteltrace.SpanKindClient,
@ -661,12 +661,12 @@ func reverse(length int, swap func(i, j int)) {
} }
} }
func simpleTraceID() otelcore.TraceID { func simpleTraceID() oteltrace.ID {
return [16]byte{123, 42} return [16]byte{123, 42}
} }
func simpleSpanIDs(count int) []otelcore.SpanID { func simpleSpanIDs(count int) []oteltrace.SpanID {
base := []otelcore.SpanID{ base := []oteltrace.SpanID{
{123}, {123},
{124}, {124},
{125}, {125},

View File

@ -123,7 +123,7 @@ func TestLinks(t *testing.T) {
l := []apitrace.Link{ l := []apitrace.Link{
{}, {},
{ {
SpanContext: core.EmptySpanContext(), SpanContext: apitrace.EmptySpanContext(),
Attributes: attrs, Attributes: attrs,
}, },
} }
@ -270,12 +270,12 @@ func TestSpanData(t *testing.T) {
startTime := time.Unix(1585674086, 1234) startTime := time.Unix(1585674086, 1234)
endTime := startTime.Add(10 * time.Second) endTime := startTime.Add(10 * time.Second)
spanData := &export.SpanData{ spanData := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: apitrace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: apitrace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
SpanKind: apitrace.SpanKindServer, SpanKind: apitrace.SpanKindServer,
ParentSpanID: core.SpanID{0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8}, ParentSpanID: apitrace.SpanID{0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8},
Name: "span data to span data", Name: "span data to span data",
StartTime: startTime, StartTime: startTime,
EndTime: endTime, EndTime: endTime,
@ -293,9 +293,9 @@ func TestSpanData(t *testing.T) {
}, },
Links: []apitrace.Link{ Links: []apitrace.Link{
{ {
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: core.TraceID{0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF}, TraceID: apitrace.ID{0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF},
SpanID: core.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7}, SpanID: apitrace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7},
TraceFlags: 0, TraceFlags: 0,
}, },
Attributes: []core.KeyValue{ Attributes: []core.KeyValue{
@ -303,9 +303,9 @@ func TestSpanData(t *testing.T) {
}, },
}, },
{ {
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: core.TraceID{0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF}, TraceID: apitrace.ID{0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF},
SpanID: core.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7}, SpanID: apitrace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7},
TraceFlags: 0, TraceFlags: 0,
}, },
Attributes: []core.KeyValue{ Attributes: []core.KeyValue{

View File

@ -81,9 +81,9 @@ func TestExportSpans(t *testing.T) {
{ {
[]*tracesdk.SpanData{ []*tracesdk.SpanData{
{ {
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: core.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), TraceID: apitrace.ID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}),
SpanID: core.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}),
TraceFlags: byte(1), TraceFlags: byte(1),
}, },
SpanKind: apitrace.SpanKindServer, SpanKind: apitrace.SpanKindServer,
@ -99,12 +99,12 @@ func TestExportSpans(t *testing.T) {
Resource: resource.New(key.String("instance", "tester-a")), Resource: resource.New(key.String("instance", "tester-a")),
}, },
{ {
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: core.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}), TraceID: apitrace.ID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}),
SpanID: core.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 2}), SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 2}),
TraceFlags: byte(1), TraceFlags: byte(1),
}, },
ParentSpanID: core.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), ParentSpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}),
SpanKind: apitrace.SpanKindInternal, SpanKind: apitrace.SpanKindInternal,
Name: "internal process", Name: "internal process",
StartTime: startTime, StartTime: startTime,
@ -118,9 +118,9 @@ func TestExportSpans(t *testing.T) {
Resource: resource.New(key.String("instance", "tester-a")), Resource: resource.New(key.String("instance", "tester-a")),
}, },
{ {
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: core.TraceID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}), TraceID: apitrace.ID([16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}),
SpanID: core.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}), SpanID: apitrace.SpanID([8]byte{0, 0, 0, 0, 0, 0, 0, 1}),
TraceFlags: byte(1), TraceFlags: byte(1),
}, },
SpanKind: apitrace.SpanKindServer, SpanKind: apitrace.SpanKindServer,

View File

@ -191,11 +191,11 @@ func TestNewRawExporterWithAgentShouldFailIfEndpointInvalid(t *testing.T) {
func Test_spanDataToThrift(t *testing.T) { func Test_spanDataToThrift(t *testing.T) {
now := time.Now() now := time.Now()
traceID, _ := core.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") traceID, _ := apitrace.IDFromHex("0102030405060708090a0b0c0d0e0f10")
spanID, _ := core.SpanIDFromHex("0102030405060708") spanID, _ := apitrace.SpanIDFromHex("0102030405060708")
linkTraceID, _ := core.TraceIDFromHex("0102030405060709090a0b0c0d0e0f11") linkTraceID, _ := apitrace.IDFromHex("0102030405060709090a0b0c0d0e0f11")
linkSpanID, _ := core.SpanIDFromHex("0102030405060709") linkSpanID, _ := apitrace.SpanIDFromHex("0102030405060709")
eventNameValue := "event-test" eventNameValue := "event-test"
keyValue := "value" keyValue := "value"
@ -215,7 +215,7 @@ func Test_spanDataToThrift(t *testing.T) {
{ {
name: "no parent", name: "no parent",
data: &export.SpanData{ data: &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },
@ -224,7 +224,7 @@ func Test_spanDataToThrift(t *testing.T) {
EndTime: now, EndTime: now,
Links: []apitrace.Link{ Links: []apitrace.Link{
{ {
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: linkTraceID, TraceID: linkTraceID,
SpanID: linkSpanID, SpanID: linkSpanID,
}, },

View File

@ -40,14 +40,14 @@ func TestExporter_ExportSpan(t *testing.T) {
// setup test span // setup test span
now := time.Now() now := time.Now()
traceID, _ := core.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") traceID, _ := trace.IDFromHex("0102030405060708090a0b0c0d0e0f10")
spanID, _ := core.SpanIDFromHex("0102030405060708") spanID, _ := trace.SpanIDFromHex("0102030405060708")
keyValue := "value" keyValue := "value"
doubleValue := 123.456 doubleValue := 123.456
resource := resource.New(key.String("rk1", "rv11")) resource := resource.New(key.String("rk1", "rv11"))
testSpan := &export.SpanData{ testSpan := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
}, },

View File

@ -30,7 +30,6 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
export "go.opentelemetry.io/otel/sdk/export/trace" export "go.opentelemetry.io/otel/sdk/export/trace"
) )
@ -137,11 +136,11 @@ func TestExportSpans(t *testing.T) {
spans := []*export.SpanData{ spans := []*export.SpanData{
// parent // parent
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{}, ParentSpanID: trace.SpanID{},
SpanKind: trace.SpanKindServer, SpanKind: trace.SpanKindServer,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -153,11 +152,11 @@ func TestExportSpans(t *testing.T) {
}, },
// child // child
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8}, SpanID: trace.SpanID{0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8},
}, },
ParentSpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, ParentSpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
SpanKind: trace.SpanKindServer, SpanKind: trace.SpanKindServer,
Name: "bar", Name: "bar",
StartTime: time.Date(2020, time.March, 11, 19, 24, 15, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 15, 0, time.UTC),

View File

@ -62,18 +62,18 @@ func toZipkinSpanContext(data *export.SpanData) zkmodel.SpanContext {
} }
} }
func toZipkinTraceID(traceID core.TraceID) zkmodel.TraceID { func toZipkinTraceID(traceID trace.ID) zkmodel.TraceID {
return zkmodel.TraceID{ return zkmodel.TraceID{
High: binary.BigEndian.Uint64(traceID[:8]), High: binary.BigEndian.Uint64(traceID[:8]),
Low: binary.BigEndian.Uint64(traceID[8:]), Low: binary.BigEndian.Uint64(traceID[8:]),
} }
} }
func toZipkinID(spanID core.SpanID) zkmodel.ID { func toZipkinID(spanID trace.SpanID) zkmodel.ID {
return zkmodel.ID(binary.BigEndian.Uint64(spanID[:])) return zkmodel.ID(binary.BigEndian.Uint64(spanID[:]))
} }
func toZipkinParentID(spanID core.SpanID) *zkmodel.ID { func toZipkinParentID(spanID trace.SpanID) *zkmodel.ID {
if spanID.IsValid() { if spanID.IsValid() {
id := toZipkinID(spanID) id := toZipkinID(spanID)
return &id return &id

View File

@ -32,11 +32,11 @@ func TestModelConversion(t *testing.T) {
inputBatch := []*export.SpanData{ inputBatch := []*export.SpanData{
// typical span data // typical span data
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38},
SpanKind: trace.SpanKindServer, SpanKind: trace.SpanKindServer,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -65,11 +65,11 @@ func TestModelConversion(t *testing.T) {
// span data with no parent (same as typical, but has // span data with no parent (same as typical, but has
// invalid parent) // invalid parent)
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{}, ParentSpanID: trace.SpanID{},
SpanKind: trace.SpanKindServer, SpanKind: trace.SpanKindServer,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -97,11 +97,11 @@ func TestModelConversion(t *testing.T) {
}, },
// span data of unspecified kind // span data of unspecified kind
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38},
SpanKind: trace.SpanKindUnspecified, SpanKind: trace.SpanKindUnspecified,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -129,11 +129,11 @@ func TestModelConversion(t *testing.T) {
}, },
// span data of internal kind // span data of internal kind
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38},
SpanKind: trace.SpanKindInternal, SpanKind: trace.SpanKindInternal,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -161,11 +161,11 @@ func TestModelConversion(t *testing.T) {
}, },
// span data of client kind // span data of client kind
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38},
SpanKind: trace.SpanKindClient, SpanKind: trace.SpanKindClient,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -193,11 +193,11 @@ func TestModelConversion(t *testing.T) {
}, },
// span data of producer kind // span data of producer kind
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38},
SpanKind: trace.SpanKindProducer, SpanKind: trace.SpanKindProducer,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -225,11 +225,11 @@ func TestModelConversion(t *testing.T) {
}, },
// span data of consumer kind // span data of consumer kind
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38},
SpanKind: trace.SpanKindConsumer, SpanKind: trace.SpanKindConsumer,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -257,11 +257,11 @@ func TestModelConversion(t *testing.T) {
}, },
// span data with no events // span data with no events
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38},
SpanKind: trace.SpanKindServer, SpanKind: trace.SpanKindServer,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),
@ -276,11 +276,11 @@ func TestModelConversion(t *testing.T) {
}, },
// span data with an "error" attribute set to "false" // span data with an "error" attribute set to "false"
{ {
SpanContext: core.SpanContext{ SpanContext: trace.SpanContext{
TraceID: core.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, TraceID: trace.ID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F},
SpanID: core.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8},
}, },
ParentSpanID: core.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, ParentSpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38},
SpanKind: trace.SpanKindServer, SpanKind: trace.SpanKindServer,
Name: "foo", Name: "foo",
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC),

View File

@ -26,7 +26,7 @@ import (
// MockSpan is a mock span used in association with MockTracer for testing purpose only. // MockSpan is a mock span used in association with MockTracer for testing purpose only.
type MockSpan struct { type MockSpan struct {
sc core.SpanContext sc apitrace.SpanContext
tracer apitrace.Tracer tracer apitrace.Tracer
Name string Name string
} }
@ -35,9 +35,9 @@ var _ apitrace.Span = (*MockSpan)(nil)
// SpanContext returns associated core.SpanContext. If the receiver is nil it returns // SpanContext returns associated core.SpanContext. If the receiver is nil it returns
// an empty core.SpanContext // an empty core.SpanContext
func (ms *MockSpan) SpanContext() core.SpanContext { func (ms *MockSpan) SpanContext() apitrace.SpanContext {
if ms == nil { if ms == nil {
return core.EmptySpanContext() return apitrace.EmptySpanContext()
} }
return ms.sc return ms.sc
} }

View File

@ -20,7 +20,6 @@ import (
"encoding/binary" "encoding/binary"
"sync/atomic" "sync/atomic"
"go.opentelemetry.io/otel/api/core"
apitrace "go.opentelemetry.io/otel/api/trace" apitrace "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/internal/trace/parent" "go.opentelemetry.io/otel/internal/trace/parent"
) )
@ -62,15 +61,15 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Star
op(&opts) op(&opts)
} }
var span *MockSpan var span *MockSpan
var sc core.SpanContext var sc apitrace.SpanContext
parentSpanContext, _, _ := parent.GetSpanContextAndLinks(ctx, opts.NewRoot) parentSpanContext, _, _ := parent.GetSpanContextAndLinks(ctx, opts.NewRoot)
if !parentSpanContext.IsValid() { if !parentSpanContext.IsValid() {
sc = core.SpanContext{} sc = apitrace.SpanContext{}
_, _ = rand.Read(sc.TraceID[:]) _, _ = rand.Read(sc.TraceID[:])
if mt.Sampled { if mt.Sampled {
sc.TraceFlags = core.TraceFlagsSampled sc.TraceFlags = apitrace.FlagsSampled
} }
} else { } else {
sc = parentSpanContext sc = parentSpanContext

View File

@ -22,7 +22,7 @@ import (
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
) )
func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (core.SpanContext, bool, []trace.Link) { func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (trace.SpanContext, bool, []trace.Link) {
lsctx := trace.SpanFromContext(ctx).SpanContext() lsctx := trace.SpanFromContext(ctx).SpanContext()
rsctx := trace.RemoteSpanContextFromContext(ctx) rsctx := trace.RemoteSpanContextFromContext(ctx)
@ -30,7 +30,7 @@ func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (core.SpanC
links := addLinkIfValid(nil, lsctx, "current") links := addLinkIfValid(nil, lsctx, "current")
links = addLinkIfValid(links, rsctx, "remote") links = addLinkIfValid(links, rsctx, "remote")
return core.EmptySpanContext(), false, links return trace.EmptySpanContext(), false, links
} }
if lsctx.IsValid() { if lsctx.IsValid() {
return lsctx, false, nil return lsctx, false, nil
@ -38,10 +38,10 @@ func GetSpanContextAndLinks(ctx context.Context, ignoreContext bool) (core.SpanC
if rsctx.IsValid() { if rsctx.IsValid() {
return rsctx, true, nil return rsctx, true, nil
} }
return core.EmptySpanContext(), false, nil return trace.EmptySpanContext(), false, nil
} }
func addLinkIfValid(links []trace.Link, sc core.SpanContext, kind string) []trace.Link { func addLinkIfValid(links []trace.Link, sc trace.SpanContext, kind string) []trace.Link {
if !sc.IsValid() { if !sc.IsValid() {
return links return links
} }

View File

@ -54,7 +54,7 @@ func Inject(ctx context.Context, metadata *metadata.MD) {
// Extract returns the correlation context and span context that // Extract returns the correlation context and span context that
// another service encoded in the gRPC metadata object with Inject. // another service encoded in the gRPC metadata object with Inject.
// This function is meant to be used on incoming requests. // This function is meant to be used on incoming requests.
func Extract(ctx context.Context, metadata *metadata.MD) ([]core.KeyValue, core.SpanContext) { func Extract(ctx context.Context, metadata *metadata.MD) ([]core.KeyValue, trace.SpanContext) {
ctx = propagation.ExtractHTTP(ctx, global.Propagators(), &metadataSupplier{ ctx = propagation.ExtractHTTP(ctx, global.Propagators(), &metadataSupplier{
metadata: metadata, metadata: metadata,
}) })

View File

@ -32,7 +32,7 @@ var (
) )
// Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject. // Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject.
func Extract(ctx context.Context, req *http.Request) ([]core.KeyValue, []core.KeyValue, core.SpanContext) { func Extract(ctx context.Context, req *http.Request) ([]core.KeyValue, []core.KeyValue, trace.SpanContext) {
ctx = propagation.ExtractHTTP(ctx, global.Propagators(), req.Header) ctx = propagation.ExtractHTTP(ctx, global.Propagators(), req.Header)
attrs := []core.KeyValue{ attrs := []core.KeyValue{

View File

@ -22,7 +22,6 @@ import (
"net/http/httptest" "net/http/httptest"
"testing" "testing"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/global"
"go.opentelemetry.io/otel/api/propagation" "go.opentelemetry.io/otel/api/propagation"
"go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/api/trace"
@ -37,7 +36,7 @@ func TestTransportBasics(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := propagation.ExtractHTTP(r.Context(), global.Propagators(), r.Header) ctx := propagation.ExtractHTTP(r.Context(), global.Propagators(), r.Header)
span := trace.RemoteSpanContextFromContext(ctx) span := trace.RemoteSpanContextFromContext(ctx)
tgtID, err := core.SpanIDFromHex(fmt.Sprintf("%016x", id)) tgtID, err := trace.SpanIDFromHex(fmt.Sprintf("%016x", id))
if err != nil { if err != nil {
t.Fatalf("Error converting id to SpanID: %s", err.Error()) t.Fatalf("Error converting id to SpanID: %s", err.Error())
} }

View File

@ -48,8 +48,8 @@ type SpanBatcher interface {
// SpanData contains all the information collected by a span. // SpanData contains all the information collected by a span.
type SpanData struct { type SpanData struct {
SpanContext core.SpanContext SpanContext apitrace.SpanContext
ParentSpanID core.SpanID ParentSpanID apitrace.SpanID
SpanKind apitrace.SpanKind SpanKind apitrace.SpanKind
Name string Name string
StartTime time.Time StartTime time.Time

View File

@ -21,7 +21,6 @@ import (
"testing" "testing"
"time" "time"
"go.opentelemetry.io/otel/api/core"
apitrace "go.opentelemetry.io/otel/api/trace" apitrace "go.opentelemetry.io/otel/api/trace"
export "go.opentelemetry.io/otel/sdk/export/trace" export "go.opentelemetry.io/otel/sdk/export/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
@ -203,7 +202,7 @@ func generateSpan(t *testing.T, parallel bool, tr apitrace.Tracer, option testOp
for i := 0; i < option.genNumSpans; i++ { for i := 0; i < option.genNumSpans; i++ {
binary.BigEndian.PutUint64(sc.TraceID[0:8], uint64(i+1)) binary.BigEndian.PutUint64(sc.TraceID[0:8], uint64(i+1))
wg.Add(1) wg.Add(1)
f := func(sc core.SpanContext) { f := func(sc apitrace.SpanContext) {
ctx := apitrace.ContextWithRemoteSpanContext(context.Background(), sc) ctx := apitrace.ContextWithRemoteSpanContext(context.Background(), sc)
_, span := tr.Start(ctx, option.name) _, span := tr.Start(ctx, option.name)
span.End() span.End()
@ -218,10 +217,10 @@ func generateSpan(t *testing.T, parallel bool, tr apitrace.Tracer, option testOp
wg.Wait() wg.Wait()
} }
func getSpanContext() core.SpanContext { func getSpanContext() apitrace.SpanContext {
tid, _ := core.TraceIDFromHex("01020304050607080102040810203040") tid, _ := apitrace.IDFromHex("01020304050607080102040810203040")
sid, _ := core.SpanIDFromHex("0102040810203040") sid, _ := apitrace.SpanIDFromHex("0102040810203040")
return core.SpanContext{ return apitrace.SpanContext{
TraceID: tid, TraceID: tid,
SpanID: sid, SpanID: sid,
TraceFlags: 0x1, TraceFlags: 0x1,

View File

@ -18,7 +18,6 @@ import (
"context" "context"
"testing" "testing"
"go.opentelemetry.io/otel/api/core"
"go.opentelemetry.io/otel/api/key" "go.opentelemetry.io/otel/api/key"
apitrace "go.opentelemetry.io/otel/api/trace" apitrace "go.opentelemetry.io/otel/api/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
@ -134,8 +133,8 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) {
} }
func BenchmarkTraceID_DotString(b *testing.B) { func BenchmarkTraceID_DotString(b *testing.B) {
t, _ := core.TraceIDFromHex("0000000000000001000000000000002a") t, _ := apitrace.IDFromHex("0000000000000001000000000000002a")
sc := core.SpanContext{TraceID: t} sc := apitrace.SpanContext{TraceID: t}
want := "0000000000000001000000000000002a" want := "0000000000000001000000000000002a"
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
@ -146,7 +145,7 @@ func BenchmarkTraceID_DotString(b *testing.B) {
} }
func BenchmarkSpanID_DotString(b *testing.B) { func BenchmarkSpanID_DotString(b *testing.B) {
sc := core.SpanContext{SpanID: core.SpanID{1}} sc := apitrace.SpanContext{SpanID: apitrace.SpanID{1}}
want := "0100000000000000" want := "0100000000000000"
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
if got := sc.SpanID.String(); got != want { if got := sc.SpanID.String(); got != want {

View File

@ -18,7 +18,8 @@ import (
"math/rand" "math/rand"
"sync" "sync"
"go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/trace"
"go.opentelemetry.io/otel/sdk/trace/internal" "go.opentelemetry.io/otel/sdk/trace/internal"
) )
@ -30,20 +31,20 @@ type defaultIDGenerator struct {
var _ internal.IDGenerator = &defaultIDGenerator{} var _ internal.IDGenerator = &defaultIDGenerator{}
// NewSpanID returns a non-zero span ID from a randomly-chosen sequence. // NewSpanID returns a non-zero span ID from a randomly-chosen sequence.
func (gen *defaultIDGenerator) NewSpanID() core.SpanID { func (gen *defaultIDGenerator) NewSpanID() trace.SpanID {
gen.Lock() gen.Lock()
defer gen.Unlock() defer gen.Unlock()
sid := core.SpanID{} sid := trace.SpanID{}
gen.randSource.Read(sid[:]) gen.randSource.Read(sid[:])
return sid return sid
} }
// NewTraceID returns a non-zero trace ID from a randomly-chosen sequence. // NewTraceID returns a non-zero trace ID from a randomly-chosen sequence.
// mu should be held while this function is called. // mu should be held while this function is called.
func (gen *defaultIDGenerator) NewTraceID() core.TraceID { func (gen *defaultIDGenerator) NewTraceID() trace.ID {
gen.Lock() gen.Lock()
defer gen.Unlock() defer gen.Unlock()
tid := core.TraceID{} tid := trace.ID{}
gen.randSource.Read(tid[:]) gen.randSource.Read(tid[:])
return tid return tid
} }

View File

@ -15,10 +15,12 @@
// Package internal provides trace internals. // Package internal provides trace internals.
package internal package internal
import "go.opentelemetry.io/otel/api/core" import (
"go.opentelemetry.io/otel/api/trace"
)
// IDGenerator allows custom generators for TraceId and SpanId. // IDGenerator allows custom generators for TraceId and SpanId.
type IDGenerator interface { type IDGenerator interface {
NewTraceID() core.TraceID NewTraceID() trace.ID
NewSpanID() core.SpanID NewSpanID() trace.SpanID
} }

View File

@ -30,9 +30,9 @@ type Sampler interface {
// SamplingParameters contains the values passed to a Sampler. // SamplingParameters contains the values passed to a Sampler.
type SamplingParameters struct { type SamplingParameters struct {
ParentContext core.SpanContext ParentContext api.SpanContext
TraceID core.TraceID TraceID api.ID
SpanID core.SpanID SpanID api.SpanID
Name string Name string
HasRemoteParent bool HasRemoteParent bool
Kind api.SpanKind Kind api.SpanKind

View File

@ -17,18 +17,19 @@ package trace_test
import ( import (
"testing" "testing"
"go.opentelemetry.io/otel/api/core" "go.opentelemetry.io/otel/api/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
) )
func TestAlwaysParentSampleWithParentSampled(t *testing.T) { func TestAlwaysParentSampleWithParentSampled(t *testing.T) {
sampler := sdktrace.AlwaysParentSample() sampler := sdktrace.AlwaysParentSample()
traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") traceID, _ := trace.IDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7") spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7")
parentCtx := core.SpanContext{ parentCtx := trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
TraceFlags: core.TraceFlagsSampled, TraceFlags: trace.FlagsSampled,
} }
if sampler.ShouldSample(sdktrace.SamplingParameters{ParentContext: parentCtx}).Decision != sdktrace.RecordAndSampled { if sampler.ShouldSample(sdktrace.SamplingParameters{ParentContext: parentCtx}).Decision != sdktrace.RecordAndSampled {
t.Error("Sampling decision should be RecordAndSampled") t.Error("Sampling decision should be RecordAndSampled")
@ -37,9 +38,9 @@ func TestAlwaysParentSampleWithParentSampled(t *testing.T) {
func TestAlwaysParentSampleWithParentNotSampled(t *testing.T) { func TestAlwaysParentSampleWithParentNotSampled(t *testing.T) {
sampler := sdktrace.AlwaysParentSample() sampler := sdktrace.AlwaysParentSample()
traceID, _ := core.TraceIDFromHex("4bf92f3577b34da6a3ce929d0e0e4736") traceID, _ := trace.IDFromHex("4bf92f3577b34da6a3ce929d0e0e4736")
spanID, _ := core.SpanIDFromHex("00f067aa0ba902b7") spanID, _ := trace.SpanIDFromHex("00f067aa0ba902b7")
parentCtx := core.SpanContext{ parentCtx := trace.SpanContext{
TraceID: traceID, TraceID: traceID,
SpanID: spanID, SpanID: spanID,
} }

View File

@ -18,7 +18,6 @@ import (
"context" "context"
"testing" "testing"
"go.opentelemetry.io/otel/api/core"
apitrace "go.opentelemetry.io/otel/api/trace" apitrace "go.opentelemetry.io/otel/api/trace"
export "go.opentelemetry.io/otel/sdk/export/trace" export "go.opentelemetry.io/otel/sdk/export/trace"
sdktrace "go.opentelemetry.io/otel/sdk/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace"
@ -58,9 +57,9 @@ func TestSimpleSpanProcessorOnEnd(t *testing.T) {
tp.RegisterSpanProcessor(ssp) tp.RegisterSpanProcessor(ssp)
tr := tp.Tracer("SimpleSpanProcessor") tr := tp.Tracer("SimpleSpanProcessor")
tid, _ := core.TraceIDFromHex("01020304050607080102040810203040") tid, _ := apitrace.IDFromHex("01020304050607080102040810203040")
sid, _ := core.SpanIDFromHex("0102040810203040") sid, _ := apitrace.SpanIDFromHex("0102040810203040")
sc := core.SpanContext{ sc := apitrace.SpanContext{
TraceID: tid, TraceID: tid,
SpanID: sid, SpanID: sid,
TraceFlags: 0x1, TraceFlags: 0x1,

View File

@ -45,7 +45,7 @@ type span struct {
// SpanContext, so that the trace ID is propagated. // SpanContext, so that the trace ID is propagated.
data *export.SpanData data *export.SpanData
mu sync.Mutex // protects the contents of *data (but not the pointer value.) mu sync.Mutex // protects the contents of *data (but not the pointer value.)
spanContext core.SpanContext spanContext apitrace.SpanContext
// attributes are capped at configured limit. When the capacity is reached an oldest entry // attributes are capped at configured limit. When the capacity is reached an oldest entry
// is removed to create room for a new entry. // is removed to create room for a new entry.
@ -67,9 +67,9 @@ type span struct {
var _ apitrace.Span = &span{} var _ apitrace.Span = &span{}
func (s *span) SpanContext() core.SpanContext { func (s *span) SpanContext() apitrace.SpanContext {
if s == nil { if s == nil {
return core.EmptySpanContext() return apitrace.EmptySpanContext()
} }
return s.spanContext return s.spanContext
} }
@ -212,9 +212,9 @@ func (s *span) SetName(name string) {
s.data.Name = name s.data.Name = name
// SAMPLING // SAMPLING
noParent := !s.data.ParentSpanID.IsValid() noParent := !s.data.ParentSpanID.IsValid()
var ctx core.SpanContext var ctx apitrace.SpanContext
if noParent { if noParent {
ctx = core.EmptySpanContext() ctx = apitrace.EmptySpanContext()
} else { } else {
// FIXME: Where do we get the parent context from? // FIXME: Where do we get the parent context from?
// From SpanStore? // From SpanStore?
@ -303,14 +303,14 @@ func (s *span) addChild() {
s.mu.Unlock() s.mu.Unlock()
} }
func startSpanInternal(tr *tracer, name string, parent core.SpanContext, remoteParent bool, o apitrace.StartConfig) *span { func startSpanInternal(tr *tracer, name string, parent apitrace.SpanContext, remoteParent bool, o apitrace.StartConfig) *span {
var noParent bool var noParent bool
span := &span{} span := &span{}
span.spanContext = parent span.spanContext = parent
cfg := tr.provider.config.Load().(*Config) cfg := tr.provider.config.Load().(*Config)
if parent == core.EmptySpanContext() { if parent == apitrace.EmptySpanContext() {
span.spanContext.TraceID = cfg.IDGenerator.NewTraceID() span.spanContext.TraceID = cfg.IDGenerator.NewTraceID()
noParent = true noParent = true
} }
@ -370,7 +370,7 @@ func startSpanInternal(tr *tracer, name string, parent core.SpanContext, remoteP
type samplingData struct { type samplingData struct {
noParent bool noParent bool
remoteParent bool remoteParent bool
parent core.SpanContext parent apitrace.SpanContext
name string name string
cfg *Config cfg *Config
span *span span *span
@ -403,13 +403,13 @@ func makeSamplingDecision(data samplingData) SamplingResult {
Links: data.links, Links: data.links,
}) })
if sampled.Decision == RecordAndSampled { if sampled.Decision == RecordAndSampled {
spanContext.TraceFlags |= core.TraceFlagsSampled spanContext.TraceFlags |= apitrace.FlagsSampled
} else { } else {
spanContext.TraceFlags &^= core.TraceFlagsSampled spanContext.TraceFlags &^= apitrace.FlagsSampled
} }
return sampled return sampled
} }
if data.parent.TraceFlags&core.TraceFlagsSampled != 0 { if data.parent.TraceFlags&apitrace.FlagsSampled != 0 {
return SamplingResult{Decision: RecordAndSampled} return SamplingResult{Decision: RecordAndSampled}
} }
return SamplingResult{Decision: NotRecord} return SamplingResult{Decision: NotRecord}

View File

@ -38,13 +38,13 @@ import (
) )
var ( var (
tid core.TraceID tid apitrace.ID
sid core.SpanID sid apitrace.SpanID
) )
func init() { func init() {
tid, _ = core.TraceIDFromHex("01020304050607080102040810203040") tid, _ = apitrace.IDFromHex("01020304050607080102040810203040")
sid, _ = core.SpanIDFromHex("0102040810203040") sid, _ = apitrace.SpanIDFromHex("0102040810203040")
} }
func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) { func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) {
@ -195,12 +195,12 @@ func TestSampling(t *testing.T) {
for i := 0; i < total; i++ { for i := 0; i < total; i++ {
ctx := context.Background() ctx := context.Background()
if tc.parent { if tc.parent {
psc := core.SpanContext{ psc := apitrace.SpanContext{
TraceID: idg.NewTraceID(), TraceID: idg.NewTraceID(),
SpanID: idg.NewSpanID(), SpanID: idg.NewSpanID(),
} }
if tc.sampledParent { if tc.sampledParent {
psc.TraceFlags = core.TraceFlagsSampled psc.TraceFlags = apitrace.FlagsSampled
} }
ctx = apitrace.ContextWithRemoteSpanContext(ctx, psc) ctx = apitrace.ContextWithRemoteSpanContext(ctx, psc)
} }
@ -231,7 +231,7 @@ func TestStartSpanWithParent(t *testing.T) {
tr := tp.Tracer("SpanWithParent") tr := tp.Tracer("SpanWithParent")
ctx := context.Background() ctx := context.Background()
sc1 := core.SpanContext{ sc1 := apitrace.SpanContext{
TraceID: tid, TraceID: tid,
SpanID: sid, SpanID: sid,
TraceFlags: 0x1, TraceFlags: 0x1,
@ -246,7 +246,7 @@ func TestStartSpanWithParent(t *testing.T) {
t.Error(err) t.Error(err)
} }
sc2 := core.SpanContext{ sc2 := apitrace.SpanContext{
TraceID: tid, TraceID: tid,
SpanID: sid, SpanID: sid,
TraceFlags: 0x1, TraceFlags: 0x1,
@ -283,7 +283,7 @@ func TestSetSpanAttributesOnStart(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -312,7 +312,7 @@ func TestSetSpanAttributes(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -347,7 +347,7 @@ func TestSetSpanAttributesOverLimit(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -392,7 +392,7 @@ func TestEvents(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -442,7 +442,7 @@ func TestEventsOverLimit(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -469,8 +469,8 @@ func TestLinks(t *testing.T) {
k2v2 := key.New("key2").String("value2") k2v2 := key.New("key2").String("value2")
k3v3 := key.New("key3").String("value3") k3v3 := key.New("key3").String("value3")
sc1 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} sc1 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}}
sc2 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} sc2 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}}
span := startSpan(tp, "Links", span := startSpan(tp, "Links",
apitrace.LinkedTo(sc1, key.New("key1").String("value1")), apitrace.LinkedTo(sc1, key.New("key1").String("value1")),
@ -486,7 +486,7 @@ func TestLinks(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -508,9 +508,9 @@ func TestLinksOverLimit(t *testing.T) {
te := &testExporter{} te := &testExporter{}
cfg := Config{MaxLinksPerSpan: 2} cfg := Config{MaxLinksPerSpan: 2}
sc1 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} sc1 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}}
sc2 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} sc2 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}}
sc3 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}} sc3 := apitrace.SpanContext{TraceID: apitrace.ID([16]byte{1, 1}), SpanID: apitrace.SpanID{3}}
tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te)) tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te))
@ -529,7 +529,7 @@ func TestLinksOverLimit(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -554,7 +554,7 @@ func TestSetSpanName(t *testing.T) {
ctx := context.Background() ctx := context.Background()
want := "SpanName-1" want := "SpanName-1"
ctx = apitrace.ContextWithRemoteSpanContext(ctx, core.SpanContext{ ctx = apitrace.ContextWithRemoteSpanContext(ctx, apitrace.SpanContext{
TraceID: tid, TraceID: tid,
SpanID: sid, SpanID: sid,
TraceFlags: 1, TraceFlags: 1,
@ -582,7 +582,7 @@ func TestSetSpanStatus(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -604,8 +604,8 @@ func cmpDiff(x, y interface{}) string {
cmp.AllowUnexported(export.Event{})) cmp.AllowUnexported(export.Event{}))
} }
func remoteSpanContext() core.SpanContext { func remoteSpanContext() apitrace.SpanContext {
return core.SpanContext{ return apitrace.SpanContext{
TraceID: tid, TraceID: tid,
SpanID: sid, SpanID: sid,
TraceFlags: 1, TraceFlags: 1,
@ -614,7 +614,7 @@ func remoteSpanContext() core.SpanContext {
// checkChild is test utility function that tests that c has fields set appropriately, // checkChild is test utility function that tests that c has fields set appropriately,
// given that it is a child span of p. // given that it is a child span of p.
func checkChild(p core.SpanContext, apiSpan apitrace.Span) error { func checkChild(p apitrace.SpanContext, apiSpan apitrace.Span) error {
s := apiSpan.(*span) s := apiSpan.(*span)
if s == nil { if s == nil {
return fmt.Errorf("got nil child span, want non-nil") return fmt.Errorf("got nil child span, want non-nil")
@ -681,7 +681,7 @@ func endSpan(te *testExporter, span apitrace.Span) (*export.SpanData, error) {
if !got.SpanContext.SpanID.IsValid() { if !got.SpanContext.SpanID.IsValid() {
return nil, fmt.Errorf("exporting span: expected nonzero SpanID") return nil, fmt.Errorf("exporting span: expected nonzero SpanID")
} }
got.SpanContext.SpanID = core.SpanID{} got.SpanContext.SpanID = apitrace.SpanID{}
if !checkTime(&got.StartTime) { if !checkTime(&got.StartTime) {
return nil, fmt.Errorf("exporting span: expected nonzero StartTime") return nil, fmt.Errorf("exporting span: expected nonzero StartTime")
} }
@ -833,12 +833,12 @@ func TestExecutionTracerTaskEnd(t *testing.T) {
s.executionTracerTaskEnd = executionTracerTaskEnd s.executionTracerTaskEnd = executionTracerTaskEnd
spans = append(spans, s) // never sample spans = append(spans, s) // never sample
tID, _ := core.TraceIDFromHex("0102030405060708090a0b0c0d0e0f") tID, _ := apitrace.IDFromHex("0102030405060708090a0b0c0d0e0f")
sID, _ := core.SpanIDFromHex("0001020304050607") sID, _ := apitrace.SpanIDFromHex("0001020304050607")
ctx := context.Background() ctx := context.Background()
ctx = apitrace.ContextWithRemoteSpanContext(ctx, ctx = apitrace.ContextWithRemoteSpanContext(ctx,
core.SpanContext{ apitrace.SpanContext{
TraceID: tID, TraceID: tID,
SpanID: sID, SpanID: sID,
TraceFlags: 0, TraceFlags: 0,
@ -925,7 +925,7 @@ func TestRecordError(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -969,7 +969,7 @@ func TestRecordErrorWithStatus(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -1008,7 +1008,7 @@ func TestRecordErrorNil(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },
@ -1075,7 +1075,7 @@ func TestWithResource(t *testing.T) {
} }
want := &export.SpanData{ want := &export.SpanData{
SpanContext: core.SpanContext{ SpanContext: apitrace.SpanContext{
TraceID: tid, TraceID: tid,
TraceFlags: 0x1, TraceFlags: 0x1,
}, },