mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-02-03 13:11:53 +02:00
api(trace): change 'reference' to 'relation' (#225)
This commit is contained in:
parent
1191a07836
commit
9b5f5dd13a
@ -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,
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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{
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user