Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api(trace): change 'reference' to 'relation' #225

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions api/trace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ type SpanOption func(*SpanOptions)
type SpanOptions struct {
Attributes []core.KeyValue
StartTime time.Time
Reference Reference
Relation Relation
Record bool
}

// Reference is used to establish relationship between newly created span and the
// Relation is used to establish relationship between newly created span and the
// other span. The other span could be related as a parent or linked or any other
// future relationship type.
type Reference struct {
type Relation struct {
core.SpanContext
RelationshipType
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func WithRecord() SpanOption {
// ChildOf. TODO: do we need this?.
func ChildOf(sc core.SpanContext) SpanOption {
return func(o *SpanOptions) {
o.Reference = Reference{
o.Relation = Relation{
SpanContext: sc,
RelationshipType: ChildOfRelationship,
}
Expand All @@ -181,7 +181,7 @@ func ChildOf(sc core.SpanContext) SpanOption {
// FollowsFrom. TODO: do we need this?.
func FollowsFrom(sc core.SpanContext) SpanOption {
return func(o *SpanOptions) {
o.Reference = Reference{
o.Relation = Relation{
SpanContext: sc,
RelationshipType: FollowsFromRelationship,
}
Expand Down
24 changes: 12 additions & 12 deletions experimental/bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOptio
opt.Apply(&sso)
}
// TODO: handle links, needs SpanData to be in the API first?
bReference, _ := otSpanReferencesToBridgeReferenceAndLinks(sso.References)
bRelation, _ := otSpanReferencesToBridgeRelationAndLinks(sso.References)
// TODO: handle span kind, needs SpanData to be in the API first?
attributes, _, hadTrueErrorTag := otTagsToOtelAttributesKindAndError(sso.Tags)
checkCtx := migration.WithDeferredSetup(context.Background())
checkCtx2, otelSpan := t.setTracer.tracer().Start(checkCtx, operationName, func(opts *oteltrace.SpanOptions) {
opts.Attributes = attributes
opts.StartTime = sso.StartTime
opts.Reference = bReference.ToOtelReference()
opts.Relation = bRelation.ToOtelRelation()
opts.Record = true
})
if checkCtx != checkCtx2 {
Expand All @@ -330,8 +330,8 @@ func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOptio
otelSpan.SetStatus(codes.Unknown)
}
var otSpanContext ot.SpanContext
if bReference.spanContext != nil {
otSpanContext = bReference.spanContext
if bRelation.spanContext != nil {
otSpanContext = bRelation.spanContext
}
sctx := newBridgeSpanContext(otelSpan.SpanContext(), otSpanContext)
span := &bridgeSpan{
Expand Down Expand Up @@ -435,35 +435,35 @@ func otTagToOtelCoreKey(k string) otelcore.Key {
return otelcore.Key(k)
}

type bridgeReference struct {
type bridgeRelation struct {
spanContext *bridgeSpanContext
relationshipType oteltrace.RelationshipType
}

func (r bridgeReference) ToOtelReference() oteltrace.Reference {
func (r bridgeRelation) ToOtelRelation() oteltrace.Relation {
if r.spanContext == nil {
return oteltrace.Reference{}
return oteltrace.Relation{}
}
return oteltrace.Reference{
return oteltrace.Relation{
SpanContext: r.spanContext.otelSpanContext,
RelationshipType: r.relationshipType,
}
}

func otSpanReferencesToBridgeReferenceAndLinks(references []ot.SpanReference) (bridgeReference, []*bridgeSpanContext) {
func otSpanReferencesToBridgeRelationAndLinks(references []ot.SpanReference) (bridgeRelation, []*bridgeSpanContext) {
if len(references) == 0 {
return bridgeReference{}, nil
return bridgeRelation{}, nil
}
first := references[0]
bReference := bridgeReference{
relation := bridgeRelation{
spanContext: mustGetBridgeSpanContext(first.ReferencedContext),
relationshipType: otSpanReferenceTypeToOtelRelationshipType(first.Type),
}
var links []*bridgeSpanContext
for _, reference := range references[1:] {
links = append(links, mustGetBridgeSpanContext(reference.ReferencedContext))
}
return bReference, links
return relation, links
}

func mustGetBridgeSpanContext(ctx ot.SpanContext) *bridgeSpanContext {
Expand Down
6 changes: 3 additions & 3 deletions experimental/bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ func (t *MockTracer) getParentSpanID(ctx context.Context, spanOpts *oteltrace.Sp
}

func (t *MockTracer) getParentSpanContext(ctx context.Context, spanOpts *oteltrace.SpanOptions) otelcore.SpanContext {
if spanOpts.Reference.RelationshipType == oteltrace.ChildOfRelationship &&
spanOpts.Reference.SpanContext.IsValid() {
return spanOpts.Reference.SpanContext
if spanOpts.Relation.RelationshipType == oteltrace.ChildOfRelationship &&
spanOpts.Relation.SpanContext.IsValid() {
return spanOpts.Relation.SpanContext
}
if parentSpanContext := oteltrace.CurrentSpan(ctx).SpanContext(); parentSpanContext.IsValid() {
return parentSpanContext
Expand Down
10 changes: 5 additions & 5 deletions internal/trace/mock_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func (mt *MockTracer) WithSpan(ctx context.Context, name string, body func(conte
return body(ctx)
}

// Start starts a MockSpan. It creates a new Span based on Reference SpanContext option.
// TracdID is used from Reference Span Context and SpanID is assigned.
// If Reference SpanContext option is not specified then random TraceID is used.
// Start starts a MockSpan. It creates a new Span based on Relation SpanContext option.
// TracdID is used from Relation Span Context and SpanID is assigned.
// If Relation SpanContext option is not specified then random TraceID is used.
// No other options are supported.
func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.SpanOption) (context.Context, apitrace.Span) {
var opts apitrace.SpanOptions
Expand All @@ -68,7 +68,7 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Span
}
var span *MockSpan
var sc core.SpanContext
if !opts.Reference.SpanContext.IsValid() {
if !opts.Relation.SpanContext.IsValid() {
sc = core.SpanContext{
TraceID: core.TraceID{
High: rand.Uint64(),
Expand All @@ -79,7 +79,7 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Span
sc.TraceFlags = core.TraceFlagsSampled
}
} else {
sc = opts.Reference.SpanContext
sc = opts.Relation.SpanContext
}
sc.SpanID = atomic.AddUint64(mt.StartSpanID, 1)
span = &MockSpan{
Expand Down
6 changes: 3 additions & 3 deletions sdk/trace/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti
op(&opts)
}

if reference := opts.Reference; reference.SpanContext != core.EmptySpanContext() {
switch reference.RelationshipType {
if relation := opts.Relation; relation.SpanContext != core.EmptySpanContext() {
switch relation.RelationshipType {
case apitrace.ChildOfRelationship, apitrace.FollowsFromRelationship:
parent = opts.Reference.SpanContext
parent = relation.SpanContext
remoteParent = true
default:
// Future relationship types may have different behavior,
Expand Down