From 9b5f5dd13acdf61c81488310a538f416d46f47a5 Mon Sep 17 00:00:00 2001 From: Gustavo Silva Paiva Date: Mon, 21 Oct 2019 14:15:49 -0300 Subject: [PATCH] api(trace): change 'reference' to 'relation' (#225) --- api/trace/api.go | 10 ++++---- experimental/bridge/opentracing/bridge.go | 24 +++++++++---------- .../bridge/opentracing/internal/mock.go | 6 ++--- internal/trace/mock_tracer.go | 10 ++++---- sdk/trace/tracer.go | 6 ++--- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/api/trace/api.go b/api/trace/api.go index e3297046756..015ba3e84f4 100644 --- a/api/trace/api.go +++ b/api/trace/api.go @@ -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 } @@ -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, } @@ -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, } diff --git a/experimental/bridge/opentracing/bridge.go b/experimental/bridge/opentracing/bridge.go index d8d7e4fb1b9..7fd43fed488 100644 --- a/experimental/bridge/opentracing/bridge.go +++ b/experimental/bridge/opentracing/bridge.go @@ -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 { @@ -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{ @@ -435,27 +435,27 @@ 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), } @@ -463,7 +463,7 @@ func otSpanReferencesToBridgeReferenceAndLinks(references []ot.SpanReference) (b for _, reference := range references[1:] { links = append(links, mustGetBridgeSpanContext(reference.ReferencedContext)) } - return bReference, links + return relation, links } func mustGetBridgeSpanContext(ctx ot.SpanContext) *bridgeSpanContext { diff --git a/experimental/bridge/opentracing/internal/mock.go b/experimental/bridge/opentracing/internal/mock.go index 7d0daf6866a..270e57b6ecf 100644 --- a/experimental/bridge/opentracing/internal/mock.go +++ b/experimental/bridge/opentracing/internal/mock.go @@ -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 diff --git a/internal/trace/mock_tracer.go b/internal/trace/mock_tracer.go index 12b13549e21..54eebf9f79d 100644 --- a/internal/trace/mock_tracer.go +++ b/internal/trace/mock_tracer.go @@ -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 @@ -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(), @@ -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{ diff --git a/sdk/trace/tracer.go b/sdk/trace/tracer.go index 098bd614c7f..fd855f8f028 100644 --- a/sdk/trace/tracer.go +++ b/sdk/trace/tracer.go @@ -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,