1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-17 01:12:45 +02:00

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

This commit is contained in:
Gustavo Silva Paiva
2019-10-21 14:15:49 -03:00
committed by rghetia
parent 1191a07836
commit 9b5f5dd13a
5 changed files with 28 additions and 28 deletions

View File

@ -102,14 +102,14 @@ type SpanOption func(*SpanOptions)
type SpanOptions struct { type SpanOptions struct {
Attributes []core.KeyValue Attributes []core.KeyValue
StartTime time.Time StartTime time.Time
Reference Reference Relation Relation
Record bool 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 // other span. The other span could be related as a parent or linked or any other
// future relationship type. // future relationship type.
type Reference struct { type Relation struct {
core.SpanContext core.SpanContext
RelationshipType RelationshipType
} }
@ -171,7 +171,7 @@ func WithRecord() SpanOption {
// ChildOf. TODO: do we need this?. // ChildOf. TODO: do we need this?.
func ChildOf(sc core.SpanContext) SpanOption { func ChildOf(sc core.SpanContext) SpanOption {
return func(o *SpanOptions) { return func(o *SpanOptions) {
o.Reference = Reference{ o.Relation = Relation{
SpanContext: sc, SpanContext: sc,
RelationshipType: ChildOfRelationship, RelationshipType: ChildOfRelationship,
} }
@ -181,7 +181,7 @@ func ChildOf(sc core.SpanContext) SpanOption {
// FollowsFrom. TODO: do we need this?. // FollowsFrom. TODO: do we need this?.
func FollowsFrom(sc core.SpanContext) SpanOption { func FollowsFrom(sc core.SpanContext) SpanOption {
return func(o *SpanOptions) { return func(o *SpanOptions) {
o.Reference = Reference{ o.Relation = Relation{
SpanContext: sc, SpanContext: sc,
RelationshipType: FollowsFromRelationship, RelationshipType: FollowsFromRelationship,
} }

View File

@ -311,14 +311,14 @@ func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOptio
opt.Apply(&sso) opt.Apply(&sso)
} }
// TODO: handle links, needs SpanData to be in the API first? // 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? // TODO: handle span kind, needs SpanData to be in the API first?
attributes, _, hadTrueErrorTag := otTagsToOtelAttributesKindAndError(sso.Tags) attributes, _, hadTrueErrorTag := otTagsToOtelAttributesKindAndError(sso.Tags)
checkCtx := migration.WithDeferredSetup(context.Background()) checkCtx := migration.WithDeferredSetup(context.Background())
checkCtx2, otelSpan := t.setTracer.tracer().Start(checkCtx, operationName, func(opts *oteltrace.SpanOptions) { checkCtx2, otelSpan := t.setTracer.tracer().Start(checkCtx, operationName, func(opts *oteltrace.SpanOptions) {
opts.Attributes = attributes opts.Attributes = attributes
opts.StartTime = sso.StartTime opts.StartTime = sso.StartTime
opts.Reference = bReference.ToOtelReference() opts.Relation = bRelation.ToOtelRelation()
opts.Record = true opts.Record = true
}) })
if checkCtx != checkCtx2 { if checkCtx != checkCtx2 {
@ -330,8 +330,8 @@ func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOptio
otelSpan.SetStatus(codes.Unknown) otelSpan.SetStatus(codes.Unknown)
} }
var otSpanContext ot.SpanContext var otSpanContext ot.SpanContext
if bReference.spanContext != nil { if bRelation.spanContext != nil {
otSpanContext = bReference.spanContext otSpanContext = bRelation.spanContext
} }
sctx := newBridgeSpanContext(otelSpan.SpanContext(), otSpanContext) sctx := newBridgeSpanContext(otelSpan.SpanContext(), otSpanContext)
span := &bridgeSpan{ span := &bridgeSpan{
@ -435,27 +435,27 @@ func otTagToOtelCoreKey(k string) otelcore.Key {
return otelcore.Key(k) return otelcore.Key(k)
} }
type bridgeReference struct { type bridgeRelation struct {
spanContext *bridgeSpanContext spanContext *bridgeSpanContext
relationshipType oteltrace.RelationshipType relationshipType oteltrace.RelationshipType
} }
func (r bridgeReference) ToOtelReference() oteltrace.Reference { func (r bridgeRelation) ToOtelRelation() oteltrace.Relation {
if r.spanContext == nil { if r.spanContext == nil {
return oteltrace.Reference{} return oteltrace.Relation{}
} }
return oteltrace.Reference{ return oteltrace.Relation{
SpanContext: r.spanContext.otelSpanContext, SpanContext: r.spanContext.otelSpanContext,
RelationshipType: r.relationshipType, RelationshipType: r.relationshipType,
} }
} }
func otSpanReferencesToBridgeReferenceAndLinks(references []ot.SpanReference) (bridgeReference, []*bridgeSpanContext) { func otSpanReferencesToBridgeRelationAndLinks(references []ot.SpanReference) (bridgeRelation, []*bridgeSpanContext) {
if len(references) == 0 { if len(references) == 0 {
return bridgeReference{}, nil return bridgeRelation{}, nil
} }
first := references[0] first := references[0]
bReference := bridgeReference{ relation := bridgeRelation{
spanContext: mustGetBridgeSpanContext(first.ReferencedContext), spanContext: mustGetBridgeSpanContext(first.ReferencedContext),
relationshipType: otSpanReferenceTypeToOtelRelationshipType(first.Type), relationshipType: otSpanReferenceTypeToOtelRelationshipType(first.Type),
} }
@ -463,7 +463,7 @@ func otSpanReferencesToBridgeReferenceAndLinks(references []ot.SpanReference) (b
for _, reference := range references[1:] { for _, reference := range references[1:] {
links = append(links, mustGetBridgeSpanContext(reference.ReferencedContext)) links = append(links, mustGetBridgeSpanContext(reference.ReferencedContext))
} }
return bReference, links return relation, links
} }
func mustGetBridgeSpanContext(ctx ot.SpanContext) *bridgeSpanContext { func mustGetBridgeSpanContext(ctx ot.SpanContext) *bridgeSpanContext {

View File

@ -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 { func (t *MockTracer) getParentSpanContext(ctx context.Context, spanOpts *oteltrace.SpanOptions) otelcore.SpanContext {
if spanOpts.Reference.RelationshipType == oteltrace.ChildOfRelationship && if spanOpts.Relation.RelationshipType == oteltrace.ChildOfRelationship &&
spanOpts.Reference.SpanContext.IsValid() { spanOpts.Relation.SpanContext.IsValid() {
return spanOpts.Reference.SpanContext return spanOpts.Relation.SpanContext
} }
if parentSpanContext := oteltrace.CurrentSpan(ctx).SpanContext(); parentSpanContext.IsValid() { if parentSpanContext := oteltrace.CurrentSpan(ctx).SpanContext(); parentSpanContext.IsValid() {
return parentSpanContext return parentSpanContext

View File

@ -57,9 +57,9 @@ func (mt *MockTracer) WithSpan(ctx context.Context, name string, body func(conte
return body(ctx) return body(ctx)
} }
// Start starts a MockSpan. It creates a new Span based on Reference SpanContext option. // Start starts a MockSpan. It creates a new Span based on Relation SpanContext option.
// TracdID is used from Reference Span Context and SpanID is assigned. // TracdID is used from Relation Span Context and SpanID is assigned.
// If Reference SpanContext option is not specified then random TraceID is used. // If Relation SpanContext option is not specified then random TraceID is used.
// No other options are supported. // No other options are supported.
func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.SpanOption) (context.Context, apitrace.Span) { func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.SpanOption) (context.Context, apitrace.Span) {
var opts apitrace.SpanOptions var opts apitrace.SpanOptions
@ -68,7 +68,7 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Span
} }
var span *MockSpan var span *MockSpan
var sc core.SpanContext var sc core.SpanContext
if !opts.Reference.SpanContext.IsValid() { if !opts.Relation.SpanContext.IsValid() {
sc = core.SpanContext{ sc = core.SpanContext{
TraceID: core.TraceID{ TraceID: core.TraceID{
High: rand.Uint64(), High: rand.Uint64(),
@ -79,7 +79,7 @@ func (mt *MockTracer) Start(ctx context.Context, name string, o ...apitrace.Span
sc.TraceFlags = core.TraceFlagsSampled sc.TraceFlags = core.TraceFlagsSampled
} }
} else { } else {
sc = opts.Reference.SpanContext sc = opts.Relation.SpanContext
} }
sc.SpanID = atomic.AddUint64(mt.StartSpanID, 1) sc.SpanID = atomic.AddUint64(mt.StartSpanID, 1)
span = &MockSpan{ span = &MockSpan{

View File

@ -39,10 +39,10 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti
op(&opts) op(&opts)
} }
if reference := opts.Reference; reference.SpanContext != core.EmptySpanContext() { if relation := opts.Relation; relation.SpanContext != core.EmptySpanContext() {
switch reference.RelationshipType { switch relation.RelationshipType {
case apitrace.ChildOfRelationship, apitrace.FollowsFromRelationship: case apitrace.ChildOfRelationship, apitrace.FollowsFromRelationship:
parent = opts.Reference.SpanContext parent = relation.SpanContext
remoteParent = true remoteParent = true
default: default:
// Future relationship types may have different behavior, // Future relationship types may have different behavior,