Skip to content

Commit

Permalink
testtrace.Span tracks and returns its SpanKind. (#987)
Browse files Browse the repository at this point in the history
* Span tracks and returns its SpanKind.

* Include SpanKind addition in CHANGELOG.

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
purple4reina and MrAlias committed Jul 29, 2020
1 parent 26e85e1 commit fa883d4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions api/trace/testtrace/span.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
19 changes: 19 additions & 0 deletions api/trace/testtrace/span_test.go
Expand Up @@ -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)
})
})
}
1 change: 1 addition & 0 deletions api/trace/testtrace/tracer.go
Expand Up @@ -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 {
Expand Down

0 comments on commit fa883d4

Please sign in to comment.