MCPcopy
hub / github.com/grafana/dskit / assertTracingSpans

Function assertTracingSpans

server/internal/oteltest/server_otel_test.go:255–279  ·  view source on GitHub ↗
(t *testing.T, expectedAttributesByOpName map[string][]attribute.KeyValue, unexpectedAttributesByOpName map[string][]attribute.Key)

Source from the content-addressed store, hash-verified

253}
254
255func assertTracingSpans(t *testing.T, expectedAttributesByOpName map[string][]attribute.KeyValue, unexpectedAttributesByOpName map[string][]attribute.Key) {
256 allSpans := spanExporter.GetSpans()
257 require.NotEmpty(t, allSpans, "expected spans to be recorded")
258
259 for op, expectedAttributes := range expectedAttributesByOpName {
260 sp, ok := findSpanByName(allSpans, op)
261 require.True(t, ok, "expected span with operation name %q to be present, spans present were: %v", op, spanNames(allSpans))
262
263 for _, attr := range expectedAttributes {
264 val, ok := findAttributeByKey(sp.Attributes, attr.Key)
265 require.True(t, ok, "expected attribute with key %q with value %q to be present on span %q, got attributes: %v", attr.Key, attr.Value.AsString(), op, sp.Attributes)
266 require.Equal(t, attr.Value.AsString(), val.AsString(), "expected attribute value for key %q to match on span %q", attr.Key, op)
267 }
268 }
269
270 for op, unexpectedAttributes := range unexpectedAttributesByOpName {
271 sp, ok := findSpanByName(allSpans, op)
272 require.True(t, ok, "expected span with operation name %q to be present, spans present were: %v", op, spanNames(allSpans))
273
274 for _, attrKey := range unexpectedAttributes {
275 _, ok := findAttributeByKey(sp.Attributes, attrKey)
276 require.False(t, ok, "expected attribute with key %q to NOT be present on span %q, got attributes: %v", attrKey, op, sp.Attributes)
277 }
278 }
279}
280
281func spanNames(spans tracetest.SpanStubs) []string {
282 names := make([]string, len(spans))

Callers 1

TestOTelTracingFunction · 0.70

Calls 4

findSpanByNameFunction · 0.85
spanNamesFunction · 0.85
findAttributeByKeyFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected