|
| 1 | +// Copyright (c) 2024 The Jaeger Authors. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package jptrace |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + "go.opentelemetry.io/collector/pdata/pcommon" |
| 11 | + "go.opentelemetry.io/collector/pdata/ptrace" |
| 12 | + |
| 13 | + "github.com/jaegertracing/jaeger/model" |
| 14 | +) |
| 15 | + |
| 16 | +func TestProtoFromTraces_AddsWarnings(t *testing.T) { |
| 17 | + traces := ptrace.NewTraces() |
| 18 | + rs1 := traces.ResourceSpans().AppendEmpty() |
| 19 | + ss1 := rs1.ScopeSpans().AppendEmpty() |
| 20 | + span1 := ss1.Spans().AppendEmpty() |
| 21 | + span1.SetName("test-span-1") |
| 22 | + span1.SetSpanID(pcommon.SpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})) |
| 23 | + AddWarning(span1, "test-warning-1") |
| 24 | + AddWarning(span1, "test-warning-2") |
| 25 | + span1.Attributes().PutStr("key", "value") |
| 26 | + |
| 27 | + ss2 := rs1.ScopeSpans().AppendEmpty() |
| 28 | + span2 := ss2.Spans().AppendEmpty() |
| 29 | + span2.SetName("test-span-2") |
| 30 | + span2.SetSpanID(pcommon.SpanID([8]byte{9, 10, 11, 12, 13, 14, 15, 16})) |
| 31 | + |
| 32 | + rs2 := traces.ResourceSpans().AppendEmpty() |
| 33 | + ss3 := rs2.ScopeSpans().AppendEmpty() |
| 34 | + span3 := ss3.Spans().AppendEmpty() |
| 35 | + span3.SetName("test-span-3") |
| 36 | + span3.SetSpanID(pcommon.SpanID([8]byte{17, 18, 19, 20, 21, 22, 23, 24})) |
| 37 | + AddWarning(span3, "test-warning-3") |
| 38 | + |
| 39 | + batches := ProtoFromTraces(traces) |
| 40 | + |
| 41 | + assert.Len(t, batches, 2) |
| 42 | + |
| 43 | + assert.Len(t, batches[0].Spans, 2) |
| 44 | + assert.Equal(t, "test-span-1", batches[0].Spans[0].OperationName) |
| 45 | + assert.Equal(t, []string{"test-warning-1", "test-warning-2"}, batches[0].Spans[0].Warnings) |
| 46 | + assert.Equal(t, []model.KeyValue{{Key: "key", VStr: "value"}}, batches[0].Spans[0].Tags) |
| 47 | + assert.Equal(t, "test-span-2", batches[0].Spans[1].OperationName) |
| 48 | + assert.Empty(t, batches[0].Spans[1].Warnings) |
| 49 | + assert.Empty(t, batches[0].Spans[1].Tags) |
| 50 | + |
| 51 | + assert.Len(t, batches[1].Spans, 1) |
| 52 | + assert.Equal(t, "test-span-3", batches[1].Spans[0].OperationName) |
| 53 | + assert.Equal(t, []string{"test-warning-3"}, batches[1].Spans[0].Warnings) |
| 54 | + assert.Empty(t, batches[1].Spans[0].Tags) |
| 55 | +} |
0 commit comments