Skip to content

Commit a99f872

Browse files
VineethReddy02lizthegrey
authored andcommitted
Span interface should only allow LinkedTo at creation. (#349)
* Remove AddLink & Link from Span Interface I have remove AddLink and Link from the interface and all it refereneces and replaced AddLink with addlink, Also Removed respective unit tests Signed-off-by: vineeth <[email protected]> * removing the unused code from unit tests Signed-off-by: VineethReddy02 <[email protected]>
1 parent 3d78564 commit a99f872

File tree

9 files changed

+16
-121
lines changed

9 files changed

+16
-121
lines changed

api/testharness/harness.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,6 @@ func (h *Harness) testSpan(tracerFactory func() trace.Tracer) {
304304
"#AddEventWithTimestamp": func(span trace.Span) {
305305
span.AddEventWithTimestamp(context.Background(), time.Now(), "test event")
306306
},
307-
"#AddLink": func(span trace.Span) {
308-
span.AddLink(trace.Link{})
309-
},
310-
"#Link": func(span trace.Span) {
311-
span.Link(core.SpanContext{})
312-
},
313307
"#SetStatus": func(span trace.Span) {
314308
span.SetStatus(codes.Internal)
315309
},

api/trace/api.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,6 @@ type Span interface {
7272
// IsRecording returns true if the span is active and recording events is enabled.
7373
IsRecording() bool
7474

75-
// AddLink adds a link to the span.
76-
AddLink(link Link)
77-
78-
// Link creates a link between this span and the other span specified by the SpanContext.
79-
// It then adds the newly created Link to the span.
80-
Link(sc core.SpanContext, attrs ...core.KeyValue)
81-
8275
// SpanContext returns span context of the span. Returned SpanContext is usable
8376
// even after the span ends.
8477
SpanContext() core.SpanContext

api/trace/current_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,3 @@ func (mockSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyValue
103103
// AddEventWithTimestamp does nothing.
104104
func (mockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) {
105105
}
106-
107-
// AddLink does nothing.
108-
func (mockSpan) AddLink(link trace.Link) {
109-
}
110-
111-
// Link does nothing.
112-
func (mockSpan) Link(sc core.SpanContext, attrs ...core.KeyValue) {
113-
}

api/trace/noop_span.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,4 @@ func (NoopSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time,
7373

7474
// SetName does nothing.
7575
func (NoopSpan) SetName(name string) {
76-
}
77-
78-
// AddLink does nothing.
79-
func (NoopSpan) AddLink(link Link) {
80-
}
81-
82-
// Link does nothing.
83-
func (NoopSpan) Link(sc core.SpanContext, attrs ...core.KeyValue) {
84-
}
76+
}

bridge/opentracing/internal/mock.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,6 @@ func (s *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Tim
289289
})
290290
}
291291

292-
func (s *MockSpan) AddLink(link oteltrace.Link) {
293-
// TODO
294-
}
295-
296-
func (s *MockSpan) Link(sc otelcore.SpanContext, attrs ...otelcore.KeyValue) {
297-
// TODO
298-
}
299-
300292
func (s *MockSpan) OverrideTracer(tracer oteltrace.Tracer) {
301293
s.officialTracer = tracer
302294
}

internal/trace/mock_span.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,3 @@ func (ms *MockSpan) AddEvent(ctx context.Context, msg string, attrs ...core.KeyV
8282
// AddEvent does nothing.
8383
func (ms *MockSpan) AddEventWithTimestamp(ctx context.Context, timestamp time.Time, msg string, attrs ...core.KeyValue) {
8484
}
85-
86-
// AddLink does nothing.
87-
func (ms *MockSpan) AddLink(link apitrace.Link) {
88-
}
89-
90-
// Link does nothing.
91-
func (ms *MockSpan) Link(sc core.SpanContext, attrs ...core.KeyValue) {
92-
}

sdk/trace/span.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -189,33 +189,10 @@ func (s *span) SetName(name string) {
189189
makeSamplingDecision(data)
190190
}
191191

192-
// AddLink implements Span interface. Specified link is added to the span.
193-
// If the total number of links associated with the span exceeds the limit
194-
// then the oldest link is removed to create space for the link being added.
195-
func (s *span) AddLink(link apitrace.Link) {
196-
if !s.IsRecording() {
197-
return
198-
}
199-
s.addLink(link)
200-
}
201-
202-
// Link implements Span interface. It is similar to AddLink but it excepts
203-
// SpanContext and attributes as arguments instead of Link. It first creates
204-
// a Link object and then adds to the span.
205-
func (s *span) Link(sc core.SpanContext, attrs ...core.KeyValue) {
192+
func (s *span) addLink(link apitrace.Link) {
206193
if !s.IsRecording() {
207194
return
208195
}
209-
attrsCopy := attrs
210-
if attrs != nil {
211-
attrsCopy = make([]core.KeyValue, len(attrs))
212-
copy(attrsCopy, attrs)
213-
}
214-
link := apitrace.Link{SpanContext: sc, Attributes: attrsCopy}
215-
s.addLink(link)
216-
}
217-
218-
func (s *span) addLink(link apitrace.Link) {
219196
s.mu.Lock()
220197
defer s.mu.Unlock()
221198
s.links.add(link)

sdk/trace/trace_test.go

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -482,63 +482,25 @@ func TestEventsOverLimit(t *testing.T) {
482482
}
483483
}
484484

485-
func TestAddLinks(t *testing.T) {
486-
te := &testExporter{}
487-
tp, _ := NewProvider(WithSyncer(te))
488-
489-
span := startSpan(tp, "AddLinks")
490-
k1v1 := key.New("key1").String("value1")
491-
k2v2 := key.New("key2").String("value2")
492-
493-
sc1 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}}
494-
sc2 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}}
495-
496-
link1 := apitrace.Link{SpanContext: sc1, Attributes: []core.KeyValue{k1v1}}
497-
link2 := apitrace.Link{SpanContext: sc2, Attributes: []core.KeyValue{k2v2}}
498-
span.AddLink(link1)
499-
span.AddLink(link2)
500-
501-
got, err := endSpan(te, span)
502-
if err != nil {
503-
t.Fatal(err)
504-
}
505-
506-
want := &export.SpanData{
507-
SpanContext: core.SpanContext{
508-
TraceID: tid,
509-
TraceFlags: 0x1,
510-
},
511-
ParentSpanID: sid,
512-
Name: "AddLinks/span0",
513-
HasRemoteParent: true,
514-
Links: []apitrace.Link{
515-
{SpanContext: sc1, Attributes: []core.KeyValue{k1v1}},
516-
{SpanContext: sc2, Attributes: []core.KeyValue{k2v2}},
517-
},
518-
SpanKind: apitrace.SpanKindInternal,
519-
}
520-
if diff := cmpDiff(got, want); diff != "" {
521-
t.Errorf("AddLink: -got +want %s", diff)
522-
}
523-
}
524-
525485
func TestLinks(t *testing.T) {
526486
te := &testExporter{}
527487
tp, _ := NewProvider(WithSyncer(te))
528488

529-
span := startSpan(tp, "Links")
530489
k1v1 := key.New("key1").String("value1")
531490
k2v2 := key.New("key2").String("value2")
532491
k3v3 := key.New("key3").String("value3")
533492

534493
sc1 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}}
535494
sc2 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}}
536495

537-
span.Link(sc1, key.New("key1").String("value1"))
538-
span.Link(sc2,
539-
key.New("key2").String("value2"),
540-
key.New("key3").String("value3"),
496+
span := startSpan(tp, "Links",
497+
apitrace.LinkedTo(sc1, key.New("key1").String("value1")),
498+
apitrace.LinkedTo(sc2,
499+
key.New("key2").String("value2"),
500+
key.New("key3").String("value3"),
501+
),
541502
)
503+
542504
got, err := endSpan(te, span)
543505
if err != nil {
544506
t.Fatal(err)
@@ -572,15 +534,16 @@ func TestLinksOverLimit(t *testing.T) {
572534
sc3 := core.SpanContext{TraceID: core.TraceID([16]byte{1, 1}), SpanID: core.SpanID{3}}
573535

574536
tp, _ := NewProvider(WithConfig(cfg), WithSyncer(te))
575-
span := startSpan(tp, "LinksOverLimit")
537+
538+
span := startSpan(tp, "LinksOverLimit",
539+
apitrace.LinkedTo(sc1, key.New("key1").String("value1")),
540+
apitrace.LinkedTo(sc2, key.New("key2").String("value2")),
541+
apitrace.LinkedTo(sc3, key.New("key3").String("value3")),
542+
)
576543

577544
k2v2 := key.New("key2").String("value2")
578545
k3v3 := key.New("key3").String("value3")
579546

580-
span.Link(sc1, key.New("key1").String("value1"))
581-
span.Link(sc2, key.New("key2").String("value2"))
582-
span.Link(sc3, key.New("key3").String("value3"))
583-
584547
got, err := endSpan(te, span)
585548
if err != nil {
586549
t.Fatal(err)

sdk/trace/tracer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti
5959
spanName := tr.spanNameWithPrefix(name)
6060
span := startSpanInternal(tr, spanName, parent, remoteParent, opts)
6161
for _, l := range opts.Links {
62-
span.AddLink(l)
62+
span.addLink(l)
6363
}
6464
span.SetAttributes(opts.Attributes...)
6565

0 commit comments

Comments
 (0)