1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-30 21:20:04 +02:00

testtrace.Span tracks and returns its SpanKind. (#987)

* Span tracks and returns its SpanKind.

* Include SpanKind addition in CHANGELOG.

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
Rey Abolofia 2020-07-29 16:06:20 -07:00 committed by GitHub
parent 26e85e1830
commit fa883d426b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 0 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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)
})
})
}

View File

@ -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 {