Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SpanKind type an integer type #288

Merged
merged 7 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions api/trace/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,36 @@ type Link struct {

// SpanKind represents the role of a Span inside a Trace. Often, this defines how a Span
// will be processed and visualized by various backends.
type SpanKind string
type SpanKind int

const (
SpanKindInternal SpanKind = "internal"
SpanKindServer SpanKind = "server"
SpanKindClient SpanKind = "client"
SpanKindProducer SpanKind = "producer"
SpanKindConsumer SpanKind = "consumer"
// These match the proto definition, see opentelemetry/proto/trace/v1/trace.proto
jmacd marked this conversation as resolved.
Show resolved Hide resolved
SpanKindUnspecified SpanKind = 0
SpanKindInternal SpanKind = 1
SpanKindServer SpanKind = 2
SpanKindClient SpanKind = 3
SpanKindProducer SpanKind = 4
SpanKindConsumer SpanKind = 5
)

// String returns the specified name of the SpanKind in lower-case.
func (sk SpanKind) String() string {
switch sk {
case SpanKindInternal:
return "internal"
case SpanKindServer:
return "server"
case SpanKindClient:
return "client"
case SpanKindProducer:
return "producer"
case SpanKindConsumer:
return "consumer"
default:
return "unspecified"
}
}

// WithStartTime sets the start time of the span to provided time t, when it is started.
// In absence of this option, wall clock time is used as start time.
// This option is typically used when starting of the span is delayed.
Expand Down
13 changes: 11 additions & 2 deletions bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,17 @@ func otTagsToOtelAttributesKindAndError(tags map[string]interface{}) ([]otelcore
for k, v := range tags {
switch k {
case string(otext.SpanKind):
if sk, ok := v.(string); ok {
kind = oteltrace.SpanKind(sk)
if s, ok := v.(string); ok {
switch strings.ToLower(s) {
case "client":
kind = oteltrace.SpanKindClient
case "server":
kind = oteltrace.SpanKindServer
case "producer":
kind = oteltrace.SpanKindProducer
case "consumer":
kind = oteltrace.SpanKindConsumer
}
}
case string(otext.Error):
if b, ok := v.(bool); ok && b {
Expand Down
9 changes: 8 additions & 1 deletion bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ func (t *MockTracer) Start(ctx context.Context, name string, opts ...oteltrace.S
startTime = time.Now()
}
spanKind := spanOpts.SpanKind
if spanKind == "" {
switch spanKind {
jmacd marked this conversation as resolved.
Show resolved Hide resolved
case oteltrace.SpanKindInternal,
oteltrace.SpanKindServer,
oteltrace.SpanKindClient,
oteltrace.SpanKindProducer,
oteltrace.SpanKindConsumer:
// valid
default:
spanKind = oteltrace.SpanKindInternal
}
spanContext := otelcore.SpanContext{
Expand Down
2 changes: 0 additions & 2 deletions bridge/opentracing/mix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"testing"

ot "github.com/opentracing/opentracing-go"
//otext "github.com/opentracing/opentracing-go/ext"
//otlog "github.com/opentracing/opentracing-go/log"

otelcore "go.opentelemetry.io/otel/api/core"
oteltrace "go.opentelemetry.io/otel/api/trace"
Expand Down
2 changes: 1 addition & 1 deletion exporter/trace/stdout/stdout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestExporter_ExportSpan(t *testing.T) {
`"TraceID":"0102030405060708090a0b0c0d0e0f10",` +
`"SpanID":"0102030405060708","TraceFlags":0},` +
`"ParentSpanID":"0000000000000000",` +
`"SpanKind":"internal",` +
`"SpanKind":1,` +
`"Name":"/foo",` +
`"StartTime":` + string(expectedSerializedNow) + "," +
`"EndTime":` + string(expectedSerializedNow) + "," +
Expand Down
2 changes: 1 addition & 1 deletion sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func startSpanInternal(tr *tracer, name string, parent core.SpanContext, remoteP
startTime = time.Now()
}
sk := o.SpanKind
if sk == "" {
if sk == apitrace.SpanKindUnspecified {
jmacd marked this conversation as resolved.
Show resolved Hide resolved
sk = apitrace.SpanKindInternal
}
span.data = &export.SpanData{
Expand Down
20 changes: 9 additions & 11 deletions sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ func TestStartSpanWithFollowsFrom(t *testing.T) {
}
}

// TODO: [rghetia] Equivalent of SpanKind Test.

func TestSetSpanAttributesOnStart(t *testing.T) {
te := &testExporter{}
tp, _ := NewProvider(WithSyncer(te))
Expand All @@ -306,7 +304,7 @@ func TestSetSpanAttributesOnStart(t *testing.T) {
Attributes: []core.KeyValue{
key.String("key1", "value1"),
},
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
HasRemoteParent: true,
}
if diff := cmpDiff(got, want); diff != "" {
Expand Down Expand Up @@ -334,7 +332,7 @@ func TestSetSpanAttributes(t *testing.T) {
Attributes: []core.KeyValue{
key.String("key1", "value1"),
},
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
HasRemoteParent: true,
}
if diff := cmpDiff(got, want); diff != "" {
Expand Down Expand Up @@ -368,7 +366,7 @@ func TestSetSpanAttributesOverLimit(t *testing.T) {
key.Bool("key1", false),
key.Int64("key4", 4),
},
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
HasRemoteParent: true,
DroppedAttributeCount: 1,
}
Expand Down Expand Up @@ -414,7 +412,7 @@ func TestEvents(t *testing.T) {
{Message: "foo", Attributes: []core.KeyValue{k1v1}},
{Message: "bar", Attributes: []core.KeyValue{k2v2, k3v3}},
},
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
}
if diff := cmpDiff(got, want); diff != "" {
t.Errorf("Message Events: -got +want %s", diff)
Expand Down Expand Up @@ -465,7 +463,7 @@ func TestEventsOverLimit(t *testing.T) {
},
DroppedMessageEventCount: 2,
HasRemoteParent: true,
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
}
if diff := cmpDiff(got, want); diff != "" {
t.Errorf("Message Event over limit: -got +want %s", diff)
Expand Down Expand Up @@ -505,7 +503,7 @@ func TestAddLinks(t *testing.T) {
{SpanContext: sc1, Attributes: []core.KeyValue{k1v1}},
{SpanContext: sc2, Attributes: []core.KeyValue{k2v2}},
},
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
}
if diff := cmpDiff(got, want); diff != "" {
t.Errorf("AddLink: -got +want %s", diff)
Expand Down Expand Up @@ -546,7 +544,7 @@ func TestLinks(t *testing.T) {
{SpanContext: sc1, Attributes: []core.KeyValue{k1v1}},
{SpanContext: sc2, Attributes: []core.KeyValue{k2v2, k3v3}},
},
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
}
if diff := cmpDiff(got, want); diff != "" {
t.Errorf("Link: -got +want %s", diff)
Expand Down Expand Up @@ -589,7 +587,7 @@ func TestLinksOverLimit(t *testing.T) {
},
DroppedLinkCount: 1,
HasRemoteParent: true,
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
}
if diff := cmpDiff(got, want); diff != "" {
t.Errorf("Link over limit: -got +want %s", diff)
Expand Down Expand Up @@ -636,7 +634,7 @@ func TestSetSpanStatus(t *testing.T) {
},
ParentSpanID: sid,
Name: "SpanStatus/span0",
SpanKind: "internal",
SpanKind: apitrace.SpanKindInternal,
Status: codes.Canceled,
HasRemoteParent: true,
}
Expand Down