@@ -25,10 +25,6 @@ import (
2525 "google.golang.org/protobuf/proto"
2626
2727 "go.opentelemetry.io/collector/consumer/pdata"
28- "go.opentelemetry.io/collector/internal/data"
29- otlpcommon "go.opentelemetry.io/collector/internal/data/protogen/common/v1"
30- otlpresource "go.opentelemetry.io/collector/internal/data/protogen/resource/v1"
31- otlptrace "go.opentelemetry.io/collector/internal/data/protogen/trace/v1"
3228 "go.opentelemetry.io/collector/translator/conventions"
3329 tracetranslator "go.opentelemetry.io/collector/translator/trace"
3430)
@@ -111,174 +107,49 @@ func TestConvertSpansToTraceSpans_protobuf(t *testing.T) {
111107 require .NoError (t , err , "Failed to parse convert Zipkin spans in Protobuf to Trace spans: %v" , err )
112108 require .Equal (t , reqs .ResourceSpans ().Len (), 2 , "Expecting exactly 2 requests since spans have different node/localEndpoint: %v" , reqs .ResourceSpans ().Len ())
113109
114- want := pdata .TracesFromOtlp ([]* otlptrace.ResourceSpans {
115- {
116- Resource : otlpresource.Resource {
117- Attributes : []otlpcommon.KeyValue {
118- {
119- Key : conventions .AttributeServiceName ,
120- Value : otlpcommon.AnyValue {
121- Value : & otlpcommon.AnyValue_StringValue {
122- StringValue : "svc-1" ,
123- },
124- },
125- },
126- },
127- },
128- InstrumentationLibrarySpans : []* otlptrace.InstrumentationLibrarySpans {
129- {
130- Spans : []* otlptrace.Span {
131- {
132- TraceId : data .NewTraceID ([16 ]byte {0x7F , 0x6F , 0x5F , 0x4F , 0x3F , 0x2F , 0x1F , 0x0F , 0xF7 , 0xF6 , 0xF5 , 0xF4 , 0xF3 , 0xF2 , 0xF1 , 0xF0 }),
133- SpanId : data .NewSpanID ([8 ]byte {0xF7 , 0xF6 , 0xF5 , 0xF4 , 0xF3 , 0xF2 , 0xF1 , 0xF0 }),
134- ParentSpanId : data .NewSpanID ([8 ]byte {0xF7 , 0xF6 , 0xF5 , 0xF4 , 0xF3 , 0xF2 , 0xF1 , 0xF0 }),
135- Name : "ProtoSpan1" ,
136- StartTimeUnixNano : uint64 (now .UnixNano ()),
137- EndTimeUnixNano : uint64 (now .Add (12 * time .Second ).UnixNano ()),
138- Attributes : []otlpcommon.KeyValue {
139- {
140- Key : conventions .AttributeNetHostIP ,
141- Value : otlpcommon.AnyValue {
142- Value : & otlpcommon.AnyValue_StringValue {
143- StringValue : "192.168.0.1" ,
144- },
145- },
146- },
147- {
148- Key : conventions .AttributeNetHostPort ,
149- Value : otlpcommon.AnyValue {
150- Value : & otlpcommon.AnyValue_IntValue {
151- IntValue : 8009 ,
152- },
153- },
154- },
155- {
156- Key : conventions .AttributeNetPeerName ,
157- Value : otlpcommon.AnyValue {
158- Value : & otlpcommon.AnyValue_StringValue {
159- StringValue : "memcached" ,
160- },
161- },
162- },
163- {
164- Key : conventions .AttributeNetPeerIP ,
165- Value : otlpcommon.AnyValue {
166- Value : & otlpcommon.AnyValue_StringValue {
167- StringValue : "fe80::1453:a77c:da4d:d21b" ,
168- },
169- },
170- },
171- {
172- Key : conventions .AttributeNetPeerPort ,
173- Value : otlpcommon.AnyValue {
174- Value : & otlpcommon.AnyValue_IntValue {
175- IntValue : 11211 ,
176- },
177- },
178- },
179- {
180- Key : tracetranslator .TagSpanKind ,
181- Value : otlpcommon.AnyValue {
182- Value : & otlpcommon.AnyValue_StringValue {
183- StringValue : string (tracetranslator .OpenTracingSpanKindConsumer ),
184- },
185- },
186- },
187- },
188- },
189- },
190- },
191- },
192- },
193- {
194- Resource : otlpresource.Resource {
195- Attributes : []otlpcommon.KeyValue {
196- {
197- Key : conventions .AttributeServiceName ,
198- Value : otlpcommon.AnyValue {
199- Value : & otlpcommon.AnyValue_StringValue {
200- StringValue : "search" ,
201- },
202- },
203- },
204- },
205- },
206- InstrumentationLibrarySpans : []* otlptrace.InstrumentationLibrarySpans {
207- {
208- Spans : []* otlptrace.Span {
209- {
210- TraceId : data .NewTraceID ([16 ]byte {0x7A , 0x6A , 0x5A , 0x4A , 0x3A , 0x2A , 0x1A , 0x0A , 0xC7 , 0xC6 , 0xC5 , 0xC4 , 0xC3 , 0xC2 , 0xC1 , 0xC0 }),
211- SpanId : data .NewSpanID ([8 ]byte {0x67 , 0x66 , 0x65 , 0x64 , 0x63 , 0x62 , 0x61 , 0x60 }),
212- ParentSpanId : data .NewSpanID ([8 ]byte {0x17 , 0x16 , 0x15 , 0x14 , 0x13 , 0x12 , 0x11 , 0x10 }),
213- Name : "CacheWarmUp" ,
214- StartTimeUnixNano : uint64 (now .Add (- 10 * time .Hour ).UnixNano ()),
215- EndTimeUnixNano : uint64 (now .Add (- 10 * time .Hour ).Add (7 * time .Second ).UnixNano ()),
216- Attributes : []otlpcommon.KeyValue {
217- {
218- Key : conventions .AttributeNetHostIP ,
219- Value : otlpcommon.AnyValue {
220- Value : & otlpcommon.AnyValue_StringValue {
221- StringValue : "10.0.0.13" ,
222- },
223- },
224- },
225- {
226- Key : conventions .AttributeNetHostPort ,
227- Value : otlpcommon.AnyValue {
228- Value : & otlpcommon.AnyValue_IntValue {
229- IntValue : 8009 ,
230- },
231- },
232- },
233- {
234- Key : conventions .AttributeNetPeerName ,
235- Value : otlpcommon.AnyValue {
236- Value : & otlpcommon.AnyValue_StringValue {
237- StringValue : "redis" ,
238- },
239- },
240- },
241- {
242- Key : conventions .AttributeNetPeerIP ,
243- Value : otlpcommon.AnyValue {
244- Value : & otlpcommon.AnyValue_StringValue {
245- StringValue : "fe80::1453:a77c:da4d:d21b" ,
246- },
247- },
248- },
249- {
250- Key : conventions .AttributeNetPeerPort ,
251- Value : otlpcommon.AnyValue {
252- Value : & otlpcommon.AnyValue_IntValue {
253- IntValue : 6379 ,
254- },
255- },
256- },
257- {
258- Key : tracetranslator .TagSpanKind ,
259- Value : otlpcommon.AnyValue {
260- Value : & otlpcommon.AnyValue_StringValue {
261- StringValue : string (tracetranslator .OpenTracingSpanKindProducer ),
262- },
263- },
264- },
265- },
266- Events : []* otlptrace.Span_Event {
267- {
268- TimeUnixNano : uint64 (now .Add (- 10 * time .Hour ).UnixNano ()),
269- Name : "DB reset" ,
270- },
271- {
272- TimeUnixNano : uint64 (now .Add (- 10 * time .Hour ).UnixNano ()),
273- Name : "GC Cycle 39" ,
274- },
275- },
276- },
277- },
278- },
279- },
280- },
281- })
110+ want := pdata .NewTraces ()
111+ want .ResourceSpans ().Resize (2 )
112+
113+ // First span/resource
114+ want .ResourceSpans ().At (0 ).Resource ().Attributes ().UpsertString (conventions .AttributeServiceName , "svc-1" )
115+ want .ResourceSpans ().At (0 ).InstrumentationLibrarySpans ().Resize (1 )
116+ want .ResourceSpans ().At (0 ).InstrumentationLibrarySpans ().At (0 ).Spans ().Resize (1 )
117+ span0 := want .ResourceSpans ().At (0 ).InstrumentationLibrarySpans ().At (0 ).Spans ().At (0 )
118+ span0 .SetTraceID (pdata .NewTraceID ([16 ]byte {0x7F , 0x6F , 0x5F , 0x4F , 0x3F , 0x2F , 0x1F , 0x0F , 0xF7 , 0xF6 , 0xF5 , 0xF4 , 0xF3 , 0xF2 , 0xF1 , 0xF0 }))
119+ span0 .SetSpanID (pdata .NewSpanID ([8 ]byte {0xF7 , 0xF6 , 0xF5 , 0xF4 , 0xF3 , 0xF2 , 0xF1 , 0xF0 }))
120+ span0 .SetParentSpanID (pdata .NewSpanID ([8 ]byte {0xF7 , 0xF6 , 0xF5 , 0xF4 , 0xF3 , 0xF2 , 0xF1 , 0xF0 }))
121+ span0 .SetName ("ProtoSpan1" )
122+ span0 .SetStartTime (pdata .TimestampFromTime (now ))
123+ span0 .SetEndTime (pdata .TimestampFromTime (now .Add (12 * time .Second )))
124+ span0 .Attributes ().UpsertString (conventions .AttributeNetHostIP , "192.168.0.1" )
125+ span0 .Attributes ().UpsertInt (conventions .AttributeNetHostPort , 8009 )
126+ span0 .Attributes ().UpsertString (conventions .AttributeNetPeerName , "memcached" )
127+ span0 .Attributes ().UpsertString (conventions .AttributeNetPeerIP , "fe80::1453:a77c:da4d:d21b" )
128+ span0 .Attributes ().UpsertInt (conventions .AttributeNetPeerPort , 11211 )
129+ span0 .Attributes ().UpsertString (tracetranslator .TagSpanKind , string (tracetranslator .OpenTracingSpanKindConsumer ))
130+
131+ // Second span/resource
132+ want .ResourceSpans ().At (1 ).Resource ().Attributes ().UpsertString (conventions .AttributeServiceName , "search" )
133+ want .ResourceSpans ().At (1 ).InstrumentationLibrarySpans ().Resize (1 )
134+ want .ResourceSpans ().At (1 ).InstrumentationLibrarySpans ().At (0 ).Spans ().Resize (1 )
135+ span1 := want .ResourceSpans ().At (0 ).InstrumentationLibrarySpans ().At (0 ).Spans ().At (0 )
136+ span1 .SetTraceID (pdata .NewTraceID ([16 ]byte {0x7A , 0x6A , 0x5A , 0x4A , 0x3A , 0x2A , 0x1A , 0x0A , 0xC7 , 0xC6 , 0xC5 , 0xC4 , 0xC3 , 0xC2 , 0xC1 , 0xC0 }))
137+ span1 .SetSpanID (pdata .NewSpanID ([8 ]byte {0x67 , 0x66 , 0x65 , 0x64 , 0x63 , 0x62 , 0x61 , 0x60 }))
138+ span1 .SetParentSpanID (pdata .NewSpanID ([8 ]byte {0x17 , 0x16 , 0x15 , 0x14 , 0x13 , 0x12 , 0x11 , 0x10 }))
139+ span1 .SetName ("CacheWarmUp" )
140+ span1 .SetStartTime (pdata .TimestampFromTime (now .Add (- 10 * time .Hour )))
141+ span1 .SetEndTime (pdata .TimestampFromTime (now .Add (- 10 * time .Hour ).Add (7 * time .Second )))
142+ span1 .Attributes ().UpsertString (conventions .AttributeNetHostIP , "10.0.0.13" )
143+ span1 .Attributes ().UpsertInt (conventions .AttributeNetHostPort , 8009 )
144+ span1 .Attributes ().UpsertString (conventions .AttributeNetPeerName , "redis" )
145+ span1 .Attributes ().UpsertString (conventions .AttributeNetPeerIP , "fe80::1453:a77c:da4d:d21b" )
146+ span1 .Attributes ().UpsertInt (conventions .AttributeNetPeerPort , 6379 )
147+ span1 .Attributes ().UpsertString (tracetranslator .TagSpanKind , string (tracetranslator .OpenTracingSpanKindProducer ))
148+ span1 .Events ().Resize (2 )
149+ span1 .Events ().At (0 ).SetName ("DB reset" )
150+ span1 .Events ().At (0 ).SetTimestamp (pdata .TimestampFromTime (now .Add (- 10 * time .Hour )))
151+ span1 .Events ().At (1 ).SetName ("GC Cycle 39" )
152+ span1 .Events ().At (1 ).SetTimestamp (pdata .TimestampFromTime (now .Add (- 10 * time .Hour )))
282153
283154 assert .Equal (t , want .SpanCount (), reqs .SpanCount ())
284155 assert .Equal (t , want .ResourceSpans ().Len (), reqs .ResourceSpans ().Len ())
0 commit comments