You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-27 22:49:15 +02:00
add WithSpanKind option to span creation (#234)
* add WithSpanKind option to span creation * change SpanKind to string alias and add support for SpanKind on ot bridge * fix tests * fix import order * fix nits
This commit is contained in:
committed by
rghetia
parent
8cb3786789
commit
5e3a2105b9
@@ -242,6 +242,7 @@ func TestSetSpanAttributes(t *testing.T) {
|
||||
Key: core.Key("key1"),
|
||||
Value: core.Value{Type: core.STRING, String: "value1"},
|
||||
}},
|
||||
SpanKind: "internal",
|
||||
HasRemoteParent: true,
|
||||
}
|
||||
if diff := cmp.Diff(got, want); diff != "" {
|
||||
@@ -281,6 +282,7 @@ func TestSetSpanAttributesOverLimit(t *testing.T) {
|
||||
Value: core.Value{Type: core.STRING, String: "value4"},
|
||||
},
|
||||
},
|
||||
SpanKind: "internal",
|
||||
HasRemoteParent: true,
|
||||
DroppedAttributeCount: 1,
|
||||
}
|
||||
@@ -326,6 +328,7 @@ func TestEvents(t *testing.T) {
|
||||
{Message: "foo", Attributes: []core.KeyValue{k1v1}},
|
||||
{Message: "bar", Attributes: []core.KeyValue{k2v2, k3v3}},
|
||||
},
|
||||
SpanKind: "internal",
|
||||
}
|
||||
if diff := cmp.Diff(got, want, cmp.AllowUnexported(export.Event{})); diff != "" {
|
||||
t.Errorf("Message Events: -got +want %s", diff)
|
||||
@@ -376,6 +379,7 @@ func TestEventsOverLimit(t *testing.T) {
|
||||
},
|
||||
DroppedMessageEventCount: 2,
|
||||
HasRemoteParent: true,
|
||||
SpanKind: "internal",
|
||||
}
|
||||
if diff := cmp.Diff(got, want, cmp.AllowUnexported(export.Event{})); diff != "" {
|
||||
t.Errorf("Message Event over limit: -got +want %s", diff)
|
||||
@@ -415,6 +419,7 @@ func TestAddLinks(t *testing.T) {
|
||||
{SpanContext: sc1, Attributes: []core.KeyValue{k1v1}},
|
||||
{SpanContext: sc2, Attributes: []core.KeyValue{k2v2}},
|
||||
},
|
||||
SpanKind: "internal",
|
||||
}
|
||||
if diff := cmp.Diff(got, want, cmp.AllowUnexported(export.Event{})); diff != "" {
|
||||
t.Errorf("AddLink: -got +want %s", diff)
|
||||
@@ -455,6 +460,7 @@ func TestLinks(t *testing.T) {
|
||||
{SpanContext: sc1, Attributes: []core.KeyValue{k1v1}},
|
||||
{SpanContext: sc2, Attributes: []core.KeyValue{k2v2, k3v3}},
|
||||
},
|
||||
SpanKind: "internal",
|
||||
}
|
||||
if diff := cmp.Diff(got, want, cmp.AllowUnexported(export.Event{})); diff != "" {
|
||||
t.Errorf("Link: -got +want %s", diff)
|
||||
@@ -497,6 +503,7 @@ func TestLinksOverLimit(t *testing.T) {
|
||||
},
|
||||
DroppedLinkCount: 1,
|
||||
HasRemoteParent: true,
|
||||
SpanKind: "internal",
|
||||
}
|
||||
if diff := cmp.Diff(got, want, cmp.AllowUnexported(export.Event{})); diff != "" {
|
||||
t.Errorf("Link over limit: -got +want %s", diff)
|
||||
@@ -543,6 +550,7 @@ func TestSetSpanStatus(t *testing.T) {
|
||||
},
|
||||
ParentSpanID: sid,
|
||||
Name: "SpanStatus/span0",
|
||||
SpanKind: "internal",
|
||||
Status: codes.Canceled,
|
||||
HasRemoteParent: true,
|
||||
}
|
||||
@@ -801,3 +809,41 @@ func TestCustomStartEndTime(t *testing.T) {
|
||||
t.Errorf("expected end time to be %s, got %s", endTime, got.EndTime)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithSpanKind(t *testing.T) {
|
||||
var te testExporter
|
||||
tp, _ := NewProvider(WithSyncer(&te), WithConfig(Config{DefaultSampler: AlwaysSample()}))
|
||||
tr := tp.GetTracer("withSpanKind")
|
||||
|
||||
_, span := tr.Start(context.Background(), "WithoutSpanKind")
|
||||
spanData, err := endSpan(&te, span)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
|
||||
if spanData.SpanKind != apitrace.SpanKindInternal {
|
||||
t.Errorf("Default value of Spankind should be Internal: got %+v, want %+v\n", spanData.SpanKind, apitrace.SpanKindInternal)
|
||||
}
|
||||
|
||||
sks := []apitrace.SpanKind{
|
||||
apitrace.SpanKindInternal,
|
||||
apitrace.SpanKindServer,
|
||||
apitrace.SpanKindClient,
|
||||
apitrace.SpanKindProducer,
|
||||
apitrace.SpanKindConsumer,
|
||||
}
|
||||
|
||||
for _, sk := range sks {
|
||||
te.spans = nil
|
||||
|
||||
_, span := tr.Start(context.Background(), fmt.Sprintf("SpanKind-%v", sk), apitrace.WithSpanKind(sk))
|
||||
spanData, err := endSpan(&te, span)
|
||||
if err != nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
|
||||
if spanData.SpanKind != sk {
|
||||
t.Errorf("WithSpanKind check: got %+v, want %+v\n", spanData.SpanKind, sks)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user