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

testtrace.Span tracks and returns its SpanKind. #987

Merged
merged 3 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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