From fa883d426b122906d4d0e81192d3ac942e2616b4 Mon Sep 17 00:00:00 2001 From: Rey Abolofia Date: Wed, 29 Jul 2020 16:06:20 -0700 Subject: [PATCH] testtrace.Span tracks and returns its SpanKind. (#987) * Span tracks and returns its SpanKind. * Include SpanKind addition in CHANGELOG. Co-authored-by: Tyler Yahn --- CHANGELOG.md | 1 + api/trace/testtrace/span.go | 6 ++++++ api/trace/testtrace/span_test.go | 19 +++++++++++++++++++ api/trace/testtrace/tracer.go | 1 + 4 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cea2d7d1362..bb082d487f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The Zipkin exporter now has `NewExportPipeline` and `InstallNewPipeline` constructor functions to match the common pattern. These function build a new exporter with default SDK options and register the exporter with the `global` package respectively. (#944) - Add propagator option for gRPC instrumentation. (#986) +- The `testtrace` package now tracks the `trace.SpanKind` for each span. (#987) ### Changed diff --git a/api/trace/testtrace/span.go b/api/trace/testtrace/span.go index 38dd84085c1..05a4452af63 100644 --- a/api/trace/testtrace/span.go +++ b/api/trace/testtrace/span.go @@ -49,6 +49,7 @@ type Span struct { attributes map[kv.Key]kv.Value events []Event links map[trace.SpanContext][]kv.KeyValue + spanKind trace.SpanKind } func (s *Span) Tracer() trace.Tracer { @@ -262,3 +263,8 @@ func (s *Span) StatusCode() codes.Code { func (s *Span) StatusMessage() string { return s.statusMessage } + +// SpanKind returns the span kind of this span. +func (s *Span) SpanKind() trace.SpanKind { + return s.spanKind +} diff --git a/api/trace/testtrace/span_test.go b/api/trace/testtrace/span_test.go index 33cd23f6f6b..3e9920cb94e 100644 --- a/api/trace/testtrace/span_test.go +++ b/api/trace/testtrace/span_test.go @@ -607,4 +607,23 @@ func TestSpan(t *testing.T) { }) } }) + + t.Run("#SpanKind", func(t *testing.T) { + tp := testtrace.NewProvider() + t.Run("returns the value given at start", func(t *testing.T) { + t.Parallel() + + e := matchers.NewExpecter(t) + + tracer := tp.Tracer(t.Name()) + _, span := tracer.Start(context.Background(), "test", + trace.WithSpanKind(trace.SpanKindConsumer)) + + subject, ok := span.(*testtrace.Span) + e.Expect(ok).ToBeTrue() + subject.End() + + e.Expect(subject.SpanKind()).ToEqual(trace.SpanKindConsumer) + }) + }) } diff --git a/api/trace/testtrace/tracer.go b/api/trace/testtrace/tracer.go index 5408576e206..da4cdd8c875 100644 --- a/api/trace/testtrace/tracer.go +++ b/api/trace/testtrace/tracer.go @@ -50,6 +50,7 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti startTime: startTime, attributes: make(map[kv.Key]kv.Value), links: make(map[trace.SpanContext][]kv.KeyValue), + spanKind: c.SpanKind, } if c.NewRoot {