You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-15 01:04:25 +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:
@ -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.
|
- 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)
|
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)
|
- Add propagator option for gRPC instrumentation. (#986)
|
||||||
|
- The `testtrace` package now tracks the `trace.SpanKind` for each span. (#987)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ type Span struct {
|
|||||||
attributes map[kv.Key]kv.Value
|
attributes map[kv.Key]kv.Value
|
||||||
events []Event
|
events []Event
|
||||||
links map[trace.SpanContext][]kv.KeyValue
|
links map[trace.SpanContext][]kv.KeyValue
|
||||||
|
spanKind trace.SpanKind
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Span) Tracer() trace.Tracer {
|
func (s *Span) Tracer() trace.Tracer {
|
||||||
@ -262,3 +263,8 @@ func (s *Span) StatusCode() codes.Code {
|
|||||||
func (s *Span) StatusMessage() string {
|
func (s *Span) StatusMessage() string {
|
||||||
return s.statusMessage
|
return s.statusMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SpanKind returns the span kind of this span.
|
||||||
|
func (s *Span) SpanKind() trace.SpanKind {
|
||||||
|
return s.spanKind
|
||||||
|
}
|
||||||
|
@ -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)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.StartOpti
|
|||||||
startTime: startTime,
|
startTime: startTime,
|
||||||
attributes: make(map[kv.Key]kv.Value),
|
attributes: make(map[kv.Key]kv.Value),
|
||||||
links: make(map[trace.SpanContext][]kv.KeyValue),
|
links: make(map[trace.SpanContext][]kv.KeyValue),
|
||||||
|
spanKind: c.SpanKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.NewRoot {
|
if c.NewRoot {
|
||||||
|
Reference in New Issue
Block a user