15
15
package esmodeltranslator
16
16
17
17
import (
18
- "encoding/binary"
19
18
"fmt"
20
19
"testing"
21
20
"time"
@@ -30,8 +29,9 @@ import (
30
29
)
31
30
32
31
var (
33
- traceID = pdata .NewTraceID ([]byte ("0123456789abcdef" ))
34
- spanID = pdata .NewSpanID ([]byte ("01234567" ))
32
+ traceID = pdata .NewTraceID ([16 ]byte {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
33
+ 0x08 , 0x09 , 0x0A , 0x0B , 0x0C , 0x0D , 0x0E , 0x0F })
34
+ spanID = pdata .NewSpanID ([8 ]byte {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 })
35
35
)
36
36
37
37
func TestAttributeToKeyValue (t * testing.T ) {
@@ -129,7 +129,9 @@ func TestConvertSpan(t *testing.T) {
129
129
span .Links ().Resize (1 )
130
130
span .Links ().At (0 ).InitEmpty ()
131
131
span .Links ().At (0 ).SetSpanID (spanID )
132
- span .Links ().At (0 ).SetTraceID (traceID )
132
+ traceIDZeroHigh := pdata .NewTraceID ([16 ]byte {0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
133
+ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 })
134
+ span .Links ().At (0 ).SetTraceID (traceIDZeroHigh )
133
135
134
136
c := & Translator {
135
137
tagKeysAsFields : map [string ]bool {"toTagMap" : true },
@@ -143,15 +145,15 @@ func TestConvertSpan(t *testing.T) {
143
145
Resource : resource ,
144
146
InstrumentationLibrary : traces .ResourceSpans ().At (0 ).InstrumentationLibrarySpans ().At (0 ).InstrumentationLibrary (),
145
147
DBSpan : & dbmodel.Span {
146
- TraceID : "30313233343536373839616263646566 " ,
147
- SpanID : "3031323334353637 " ,
148
+ TraceID : "000102030405060708090a0b0c0d0e0f " ,
149
+ SpanID : "0001020304050607 " ,
148
150
StartTime : 1000 ,
149
151
Duration : 1000 ,
150
152
OperationName : "root" ,
151
153
StartTimeMillis : 1 ,
152
154
Tags : []dbmodel.KeyValue {
153
155
{Key : "span.kind" , Type : dbmodel .StringType , Value : "client" },
154
- {Key : "status.code" , Type : dbmodel .StringType , Value : "STATUS_CODE_CANCELLED " },
156
+ {Key : "status.code" , Type : dbmodel .StringType , Value : "STATUS_CODE_OK " },
155
157
{Key : "error" , Type : dbmodel .BoolType , Value : "true" },
156
158
{Key : "status.message" , Type : dbmodel .StringType , Value : "messagetext" },
157
159
{Key : "foo" , Type : dbmodel .BoolType , Value : "true" },
@@ -163,8 +165,8 @@ func TestConvertSpan(t *testing.T) {
163
165
{Key : "event" , Value : "eventName" , Type : dbmodel .StringType },
164
166
{Key : "foo" , Value : "bar" , Type : dbmodel .StringType }}, Timestamp : 500 }},
165
167
References : []dbmodel.Reference {
166
- {SpanID : "3031323334353637 " , TraceID : "30313233343536373839616263646566 " , RefType : dbmodel .ChildOf },
167
- {SpanID : "3031323334353637 " , TraceID : "30313233343536373839616263646566 " , RefType : dbmodel .FollowsFrom }},
168
+ {SpanID : "0001020304050607 " , TraceID : "000102030405060708090a0b0c0d0e0f " , RefType : dbmodel .ChildOf },
169
+ {SpanID : "0001020304050607 " , TraceID : "0001020304050607 " , RefType : dbmodel .FollowsFrom }},
168
170
Process : dbmodel.Process {
169
171
ServiceName : "myservice" ,
170
172
Tags : []dbmodel.KeyValue {{Key : "num" , Value : "16.66" , Type : dbmodel .Float64Type }},
@@ -173,6 +175,12 @@ func TestConvertSpan(t *testing.T) {
173
175
}, spansData [0 ])
174
176
}
175
177
178
+ func BenchmarkConvertSpanID (b * testing.B ) {
179
+ for i := 0 ; i < b .N ; i ++ {
180
+ _ , _ = convertSpanID (spanID )
181
+ }
182
+ }
183
+
176
184
func TestSpanEmptyRef (t * testing.T ) {
177
185
traces := traces ("myservice" )
178
186
span := addSpan (traces , "root" , traceID , spanID )
@@ -190,8 +198,8 @@ func TestSpanEmptyRef(t *testing.T) {
190
198
Resource : traces .ResourceSpans ().At (0 ).Resource (),
191
199
InstrumentationLibrary : traces .ResourceSpans ().At (0 ).InstrumentationLibrarySpans ().At (0 ).InstrumentationLibrary (),
192
200
DBSpan : & dbmodel.Span {
193
- TraceID : "30313233343536373839616263646566 " ,
194
- SpanID : "3031323334353637 " ,
201
+ TraceID : "000102030405060708090a0b0c0d0e0f " ,
202
+ SpanID : "0001020304050607 " ,
195
203
StartTime : 1000 ,
196
204
Duration : 1000 ,
197
205
OperationName : "root" ,
@@ -215,26 +223,16 @@ func TestEmpty(t *testing.T) {
215
223
}
216
224
217
225
func TestErrorIDs (t * testing.T ) {
218
- zero64Bytes := make ([]byte , 16 )
219
- binary .LittleEndian .PutUint64 (zero64Bytes , 0 )
220
- binary .LittleEndian .PutUint64 (zero64Bytes , 0 )
226
+ var zero64Bytes [16 ]byte
227
+ var zero32Bytes [8 ]byte
221
228
tests := []struct {
222
229
spanID pdata.SpanID
223
230
traceID pdata.TraceID
224
231
err string
225
232
}{
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
233
{
236
234
traceID : traceID ,
237
- spanID : pdata .NewSpanID (zero64Bytes [: 8 ] ),
235
+ spanID : pdata .NewSpanID (zero32Bytes ),
238
236
err : errZeroSpanID .Error (),
239
237
},
240
238
{
0 commit comments