Exemplo n.º 1
0
// MockTracerSampledSpans is a helper function that returns only sampled spans from MockTracer
func MockTracerSampledSpans(tracer *mocktracer.MockTracer) []*mocktracer.MockSpan {
	var spans []*mocktracer.MockSpan
	for _, span := range tracer.FinishedSpans() {
		if span.Context().(mocktracer.MockSpanContext).Sampled {
			spans = append(spans, span)
		}
	}
	return spans
}
Exemplo n.º 2
0
func AssertDepth2Spans(t *testing.T, tracer *mocktracer.MockTracer) {
	if !assert.Equal(t, 4, len(tracer.FinishedSpans()), "generates inbound and outband spans") {
		return
	}
	spans := tracer.FinishedSpans()
	ids := mapContexts(spans)
	assert.Equal(t, []int{ids[0], ids[0], ids[0], ids[0]}, ids, "spans share a trace id")
	assert.Equal(t, "echo", spans[0].OperationName, "span has correct operation name")
	assert.Equal(t, "echo", spans[1].OperationName, "span has correct operation name")
	assert.Equal(t, "echoecho", spans[2].OperationName, "span has correct operation name")
	assert.Equal(t, "echoecho", spans[3].OperationName, "span has correct operation name")
}
Exemplo n.º 3
0
func AssertDepth1Spans(t *testing.T, tracer *mocktracer.MockTracer) {
	assert.Equal(t, 2, len(tracer.FinishedSpans()), "generates inbound and outband spans")
	if len(tracer.FinishedSpans()) != 2 {
		return
	}
	spans := tracer.FinishedSpans()
	parent := spans[0]
	child := spans[1]
	parentctx := parent.Context().(mocktracer.MockSpanContext)
	childctx := child.Context().(mocktracer.MockSpanContext)
	assert.Equal(t, parentctx.TraceID, childctx.TraceID, "parent and child trace ID do not match")
	// Whether the parent and child have the same span id is an implementation
	// detail of the tracer.
	assert.Equal(t, "echo", parent.OperationName, "span has correct operation name")
	assert.Equal(t, "echo", child.OperationName, "span has correct operation name")
}