You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
Provide conformance tests for tracers (#191)
* Provide conformance tests for tracers The test harness may be used to ensure that a given tracer behaves according to the expectations set by the API. * Add `ToMatchError` matcher * Use DeepEqual to compare unknown types in matchers Unlike basic `==`/`!=`, `reflect.DeepEqual` can compare arbitrary types (e.g., `[]string` to `[]string`) * Use struct instead of string for test context key
This commit is contained in:
committed by
rghetia
parent
11bdacf7b9
commit
3a9c80c56f
@@ -27,6 +27,8 @@ import (
|
||||
|
||||
"go.opentelemetry.io/api/core"
|
||||
"go.opentelemetry.io/api/key"
|
||||
"go.opentelemetry.io/api/testharness"
|
||||
"go.opentelemetry.io/api/trace"
|
||||
apitrace "go.opentelemetry.io/api/trace"
|
||||
"go.opentelemetry.io/sdk/export"
|
||||
)
|
||||
@@ -41,6 +43,15 @@ func init() {
|
||||
setupDefaultSamplerConfig()
|
||||
}
|
||||
|
||||
func TestTracerFollowsExpectedAPIBehaviour(t *testing.T) {
|
||||
harness := testharness.NewHarness(t)
|
||||
subjectFactory := func() trace.Tracer {
|
||||
return apitrace.GlobalTracer()
|
||||
}
|
||||
|
||||
harness.TestTracer(subjectFactory)
|
||||
}
|
||||
|
||||
func setupDefaultSamplerConfig() {
|
||||
// no random sampling, but sample children of sampled spans.
|
||||
ApplyConfig(Config{DefaultSampler: ProbabilitySampler(0)})
|
||||
@@ -54,14 +65,6 @@ func (t *testExporter) ExportSpan(ctx context.Context, d *export.SpanData) {
|
||||
t.spans = append(t.spans, d)
|
||||
}
|
||||
|
||||
func TestStartSpan(t *testing.T) {
|
||||
_, span := apitrace.GlobalTracer().Start(context.Background(), "StartSpan")
|
||||
defer span.End()
|
||||
if span == nil {
|
||||
t.Errorf("span not started")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetName(t *testing.T) {
|
||||
samplerIsCalled := false
|
||||
fooSampler := Sampler(func(p SamplingParameters) SamplingDecision {
|
||||
|
||||
Reference in New Issue
Block a user