15
15
package esmodeltranslator
16
16
17
17
import (
18
- "encoding/binary"
19
18
"fmt"
20
19
"testing"
21
20
"time"
@@ -30,8 +29,8 @@ import (
30
29
)
31
30
32
31
var (
33
- traceID = pdata .NewTraceID ([] byte ("0123456789abcdef" ))
34
- spanID = pdata .NewSpanID ([] byte ("01234567" ))
32
+ traceID = pdata .NewTraceID (Byte16ArrayFromString ("0123456789abcdef" ))
33
+ spanID = pdata .NewSpanID (Byte8ArrayFromString ("01234567" ))
35
34
)
36
35
37
36
func TestAttributeToKeyValue (t * testing.T ) {
@@ -151,7 +150,7 @@ func TestConvertSpan(t *testing.T) {
151
150
StartTimeMillis : 1 ,
152
151
Tags : []dbmodel.KeyValue {
153
152
{Key : "span.kind" , Type : dbmodel .StringType , Value : "client" },
154
- {Key : "status.code" , Type : dbmodel .StringType , Value : "STATUS_CODE_CANCELLED " },
153
+ {Key : "status.code" , Type : dbmodel .StringType , Value : "STATUS_CODE_OK " },
155
154
{Key : "error" , Type : dbmodel .BoolType , Value : "true" },
156
155
{Key : "status.message" , Type : dbmodel .StringType , Value : "messagetext" },
157
156
{Key : "foo" , Type : dbmodel .BoolType , Value : "true" },
@@ -196,9 +195,15 @@ func TestSpanEmptyRef(t *testing.T) {
196
195
Duration : 1000 ,
197
196
OperationName : "root" ,
198
197
StartTimeMillis : 1 ,
199
- Tags : []dbmodel.KeyValue {}, // should not be nil
200
- Logs : []dbmodel.Log {}, // should not be nil
201
- References : []dbmodel.Reference {}, // should not be nil
198
+ Tags : []dbmodel.KeyValue {}, // should not be nil
199
+ Logs : []dbmodel.Log {}, // should not be nil
200
+ References : []dbmodel.Reference {
201
+ {
202
+ RefType : "CHILD_OF" ,
203
+ TraceID : "30313233343536373839616263646566" ,
204
+ SpanID : "3031323334353637" ,
205
+ },
206
+ },
202
207
Process : dbmodel.Process {
203
208
ServiceName : "myservice" ,
204
209
Tags : nil ,
@@ -215,26 +220,16 @@ func TestEmpty(t *testing.T) {
215
220
}
216
221
217
222
func TestErrorIDs (t * testing.T ) {
218
- zero64Bytes := make ([]byte , 16 )
219
- binary .LittleEndian .PutUint64 (zero64Bytes , 0 )
220
- binary .LittleEndian .PutUint64 (zero64Bytes , 0 )
223
+ var zero64Bytes [16 ]byte
224
+ var zero32Bytes [8 ]byte
221
225
tests := []struct {
222
226
spanID pdata.SpanID
223
227
traceID pdata.TraceID
224
228
err string
225
229
}{
226
- {
227
- traceID : pdata .NewTraceID ([]byte ("invalid-%" )),
228
- err : "TraceID does not have 16 bytes" ,
229
- },
230
- {
231
- traceID : traceID ,
232
- spanID : pdata .NewSpanID ([]byte ("invalid-%" )),
233
- err : "SpanID does not have 8 bytes" ,
234
- },
235
230
{
236
231
traceID : traceID ,
237
- spanID : pdata .NewSpanID (zero64Bytes [: 8 ] ),
232
+ spanID : pdata .NewSpanID (zero32Bytes ),
238
233
err : errZeroSpanID .Error (),
239
234
},
240
235
{
@@ -274,7 +269,18 @@ func addSpan(traces pdata.Traces, name string, traceID pdata.TraceID, spanID pda
274
269
span .SetName (name )
275
270
span .SetTraceID (traceID )
276
271
span .SetSpanID (spanID )
272
+ span .SetParentSpanID (spanID )
277
273
span .SetStartTime (pdata .TimestampUnixNano (time .Now ().UnixNano ()))
278
274
span .SetEndTime (pdata .TimestampUnixNano (time .Now ().UnixNano ()))
279
275
return span
280
276
}
277
+
278
+ func Byte16ArrayFromString (s string ) (result [16 ]byte ) {
279
+ copy (result [:], s )
280
+ return
281
+ }
282
+
283
+ func Byte8ArrayFromString (s string ) (result [8 ]byte ) {
284
+ copy (result [:], s )
285
+ return
286
+ }
0 commit comments