| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package zipkin |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"net" |
| 9 |
"strconv" |
| 10 |
"testing" |
| 11 |
"time" |
| 12 |
|
| 13 |
"github.com/google/go-cmp/cmp" |
| 14 |
zkmodel "github.com/openzipkin/zipkin-go/model" |
| 15 |
"github.com/stretchr/testify/assert" |
| 16 |
"github.com/stretchr/testify/require" |
| 17 |
|
| 18 |
"go.opentelemetry.io/otel/attribute" |
| 19 |
"go.opentelemetry.io/otel/codes" |
| 20 |
"go.opentelemetry.io/otel/sdk/instrumentation" |
| 21 |
"go.opentelemetry.io/otel/sdk/resource" |
| 22 |
tracesdk "go.opentelemetry.io/otel/sdk/trace" |
| 23 |
"go.opentelemetry.io/otel/sdk/trace/tracetest" |
| 24 |
semconv125 "go.opentelemetry.io/otel/semconv/v1.25.0" |
| 25 |
semconv138 "go.opentelemetry.io/otel/semconv/v1.38.0" |
| 26 |
semconv "go.opentelemetry.io/otel/semconv/v1.40.0" |
| 27 |
"go.opentelemetry.io/otel/trace" |
| 28 |
) |
| 29 |
|
| 30 |
func TestModelConversion(t *testing.T) { |
| 31 |
res := resource.NewSchemaless( |
| 32 |
semconv.ServiceName("model-test"), |
| 33 |
semconv.ServiceVersion("0.1.0"), |
| 34 |
attribute.Int64("resource-attr1", 42), |
| 35 |
attribute.IntSlice("resource-attr2", []int{0, 1, 2}), |
| 36 |
) |
| 37 |
|
| 38 |
inputBatch := tracetest.SpanStubs{ |
| 39 |
// typical span data with UNSET status |
| 40 |
{ |
| 41 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 42 |
TraceID: trace.TraceID{ |
| 43 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 44 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 45 |
}, |
| 46 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 47 |
}), |
| 48 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 49 |
TraceID: trace.TraceID{ |
| 50 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 51 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 52 |
}, |
| 53 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 54 |
}), |
| 55 |
SpanKind: trace.SpanKindServer, |
| 56 |
Name: "foo", |
| 57 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 58 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 59 |
Attributes: []attribute.KeyValue{ |
| 60 |
attribute.Int64("attr1", 42), |
| 61 |
attribute.String("attr2", "bar"), |
| 62 |
attribute.IntSlice("attr3", []int{0, 1, 2}), |
| 63 |
attribute.BoolSlice("attr4", []bool{true, false, true}), |
| 64 |
attribute.Float64Slice("attr5", []float64{1.1, 2.2, 3.3}), |
| 65 |
attribute.StringSlice("attr6", []string{"bar1", "bar2", "bar3"}), |
| 66 |
}, |
| 67 |
Events: []tracesdk.Event{ |
| 68 |
{ |
| 69 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 70 |
Name: "ev1", |
| 71 |
Attributes: []attribute.KeyValue{ |
| 72 |
attribute.Int64("eventattr1", 123), |
| 73 |
}, |
| 74 |
}, |
| 75 |
{ |
| 76 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 77 |
Name: "ev2", |
| 78 |
Attributes: nil, |
| 79 |
}, |
| 80 |
}, |
| 81 |
Status: tracesdk.Status{ |
| 82 |
Code: codes.Unset, |
| 83 |
Description: "", |
| 84 |
}, |
| 85 |
Resource: res, |
| 86 |
}, |
| 87 |
// typical span data with OK status |
| 88 |
{ |
| 89 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 90 |
TraceID: trace.TraceID{ |
| 91 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 92 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 93 |
}, |
| 94 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 95 |
}), |
| 96 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 97 |
TraceID: trace.TraceID{ |
| 98 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 99 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 100 |
}, |
| 101 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 102 |
}), |
| 103 |
SpanKind: trace.SpanKindServer, |
| 104 |
Name: "foo", |
| 105 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 106 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 107 |
Attributes: []attribute.KeyValue{ |
| 108 |
attribute.Int64("attr1", 42), |
| 109 |
attribute.String("attr2", "bar"), |
| 110 |
attribute.IntSlice("attr3", []int{0, 1, 2}), |
| 111 |
}, |
| 112 |
Events: []tracesdk.Event{ |
| 113 |
{ |
| 114 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 115 |
Name: "ev1", |
| 116 |
Attributes: []attribute.KeyValue{ |
| 117 |
attribute.Int64("eventattr1", 123), |
| 118 |
}, |
| 119 |
}, |
| 120 |
{ |
| 121 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 122 |
Name: "ev2", |
| 123 |
Attributes: nil, |
| 124 |
}, |
| 125 |
}, |
| 126 |
Status: tracesdk.Status{ |
| 127 |
Code: codes.Ok, |
| 128 |
Description: "", |
| 129 |
}, |
| 130 |
Resource: res, |
| 131 |
}, |
| 132 |
// typical span data with ERROR status |
| 133 |
{ |
| 134 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 135 |
TraceID: trace.TraceID{ |
| 136 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 137 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 138 |
}, |
| 139 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 140 |
}), |
| 141 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 142 |
TraceID: trace.TraceID{ |
| 143 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 144 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 145 |
}, |
| 146 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 147 |
}), |
| 148 |
SpanKind: trace.SpanKindServer, |
| 149 |
Name: "foo", |
| 150 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 151 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 152 |
Attributes: []attribute.KeyValue{ |
| 153 |
attribute.Int64("attr1", 42), |
| 154 |
attribute.String("attr2", "bar"), |
| 155 |
attribute.IntSlice("attr3", []int{0, 1, 2}), |
| 156 |
}, |
| 157 |
Events: []tracesdk.Event{ |
| 158 |
{ |
| 159 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 160 |
Name: "ev1", |
| 161 |
Attributes: []attribute.KeyValue{ |
| 162 |
attribute.Int64("eventattr1", 123), |
| 163 |
}, |
| 164 |
}, |
| 165 |
{ |
| 166 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 167 |
Name: "ev2", |
| 168 |
Attributes: nil, |
| 169 |
}, |
| 170 |
}, |
| 171 |
Status: tracesdk.Status{ |
| 172 |
Code: codes.Error, |
| 173 |
Description: "404, file not found", |
| 174 |
}, |
| 175 |
Resource: res, |
| 176 |
}, |
| 177 |
// span data with no parent (same as typical, but has |
| 178 |
// invalid parent) |
| 179 |
{ |
| 180 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 181 |
TraceID: trace.TraceID{ |
| 182 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 183 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 184 |
}, |
| 185 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 186 |
}), |
| 187 |
SpanKind: trace.SpanKindServer, |
| 188 |
Name: "foo", |
| 189 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 190 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 191 |
Attributes: []attribute.KeyValue{ |
| 192 |
attribute.Int64("attr1", 42), |
| 193 |
attribute.String("attr2", "bar"), |
| 194 |
}, |
| 195 |
Events: []tracesdk.Event{ |
| 196 |
{ |
| 197 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 198 |
Name: "ev1", |
| 199 |
Attributes: []attribute.KeyValue{ |
| 200 |
attribute.Int64("eventattr1", 123), |
| 201 |
}, |
| 202 |
}, |
| 203 |
{ |
| 204 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 205 |
Name: "ev2", |
| 206 |
Attributes: nil, |
| 207 |
}, |
| 208 |
}, |
| 209 |
Status: tracesdk.Status{ |
| 210 |
Code: codes.Error, |
| 211 |
Description: "404, file not found", |
| 212 |
}, |
| 213 |
Resource: res, |
| 214 |
}, |
| 215 |
// span data of unspecified kind |
| 216 |
{ |
| 217 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 218 |
TraceID: trace.TraceID{ |
| 219 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 220 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 221 |
}, |
| 222 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 223 |
}), |
| 224 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 225 |
TraceID: trace.TraceID{ |
| 226 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 227 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 228 |
}, |
| 229 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 230 |
}), |
| 231 |
SpanKind: trace.SpanKindUnspecified, |
| 232 |
Name: "foo", |
| 233 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 234 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 235 |
Attributes: []attribute.KeyValue{ |
| 236 |
attribute.Int64("attr1", 42), |
| 237 |
attribute.String("attr2", "bar"), |
| 238 |
}, |
| 239 |
Events: []tracesdk.Event{ |
| 240 |
{ |
| 241 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 242 |
Name: "ev1", |
| 243 |
Attributes: []attribute.KeyValue{ |
| 244 |
attribute.Int64("eventattr1", 123), |
| 245 |
}, |
| 246 |
}, |
| 247 |
{ |
| 248 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 249 |
Name: "ev2", |
| 250 |
Attributes: nil, |
| 251 |
}, |
| 252 |
}, |
| 253 |
Status: tracesdk.Status{ |
| 254 |
Code: codes.Error, |
| 255 |
Description: "404, file not found", |
| 256 |
}, |
| 257 |
Resource: res, |
| 258 |
}, |
| 259 |
// span data of internal kind |
| 260 |
{ |
| 261 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 262 |
TraceID: trace.TraceID{ |
| 263 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 264 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 265 |
}, |
| 266 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 267 |
}), |
| 268 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 269 |
TraceID: trace.TraceID{ |
| 270 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 271 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 272 |
}, |
| 273 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 274 |
}), |
| 275 |
SpanKind: trace.SpanKindInternal, |
| 276 |
Name: "foo", |
| 277 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 278 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 279 |
Attributes: []attribute.KeyValue{ |
| 280 |
attribute.Int64("attr1", 42), |
| 281 |
attribute.String("attr2", "bar"), |
| 282 |
}, |
| 283 |
Events: []tracesdk.Event{ |
| 284 |
{ |
| 285 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 286 |
Name: "ev1", |
| 287 |
Attributes: []attribute.KeyValue{ |
| 288 |
attribute.Int64("eventattr1", 123), |
| 289 |
}, |
| 290 |
}, |
| 291 |
{ |
| 292 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 293 |
Name: "ev2", |
| 294 |
Attributes: nil, |
| 295 |
}, |
| 296 |
}, |
| 297 |
Status: tracesdk.Status{ |
| 298 |
Code: codes.Error, |
| 299 |
Description: "404, file not found", |
| 300 |
}, |
| 301 |
Resource: res, |
| 302 |
}, |
| 303 |
// span data of client kind |
| 304 |
{ |
| 305 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 306 |
TraceID: trace.TraceID{ |
| 307 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 308 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 309 |
}, |
| 310 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 311 |
}), |
| 312 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 313 |
TraceID: trace.TraceID{ |
| 314 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 315 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 316 |
}, |
| 317 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 318 |
}), |
| 319 |
SpanKind: trace.SpanKindClient, |
| 320 |
Name: "foo", |
| 321 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 322 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 323 |
Attributes: []attribute.KeyValue{ |
| 324 |
attribute.Int64("attr1", 42), |
| 325 |
attribute.String("attr2", "bar"), |
| 326 |
attribute.String("peer.hostname", "test-peer-hostname"), |
| 327 |
attribute.String("network.peer.address", "1.2.3.4"), |
| 328 |
attribute.Int64("network.peer.port", 9876), |
| 329 |
}, |
| 330 |
Events: []tracesdk.Event{ |
| 331 |
{ |
| 332 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 333 |
Name: "ev1", |
| 334 |
Attributes: []attribute.KeyValue{ |
| 335 |
attribute.Int64("eventattr1", 123), |
| 336 |
}, |
| 337 |
}, |
| 338 |
{ |
| 339 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 340 |
Name: "ev2", |
| 341 |
Attributes: nil, |
| 342 |
}, |
| 343 |
}, |
| 344 |
Status: tracesdk.Status{ |
| 345 |
Code: codes.Error, |
| 346 |
Description: "404, file not found", |
| 347 |
}, |
| 348 |
Resource: res, |
| 349 |
}, |
| 350 |
// span data of producer kind |
| 351 |
{ |
| 352 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 353 |
TraceID: trace.TraceID{ |
| 354 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 355 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 356 |
}, |
| 357 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 358 |
}), |
| 359 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 360 |
TraceID: trace.TraceID{ |
| 361 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 362 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 363 |
}, |
| 364 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 365 |
}), |
| 366 |
SpanKind: trace.SpanKindProducer, |
| 367 |
Name: "foo", |
| 368 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 369 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 370 |
Attributes: []attribute.KeyValue{ |
| 371 |
attribute.Int64("attr1", 42), |
| 372 |
attribute.String("attr2", "bar"), |
| 373 |
}, |
| 374 |
Events: []tracesdk.Event{ |
| 375 |
{ |
| 376 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 377 |
Name: "ev1", |
| 378 |
Attributes: []attribute.KeyValue{ |
| 379 |
attribute.Int64("eventattr1", 123), |
| 380 |
}, |
| 381 |
}, |
| 382 |
{ |
| 383 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 384 |
Name: "ev2", |
| 385 |
Attributes: nil, |
| 386 |
}, |
| 387 |
}, |
| 388 |
Status: tracesdk.Status{ |
| 389 |
Code: codes.Error, |
| 390 |
Description: "404, file not found", |
| 391 |
}, |
| 392 |
Resource: res, |
| 393 |
}, |
| 394 |
// span data of consumer kind |
| 395 |
{ |
| 396 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 397 |
TraceID: trace.TraceID{ |
| 398 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 399 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 400 |
}, |
| 401 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 402 |
}), |
| 403 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 404 |
TraceID: trace.TraceID{ |
| 405 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 406 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 407 |
}, |
| 408 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 409 |
}), |
| 410 |
SpanKind: trace.SpanKindConsumer, |
| 411 |
Name: "foo", |
| 412 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 413 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 414 |
Attributes: []attribute.KeyValue{ |
| 415 |
attribute.Int64("attr1", 42), |
| 416 |
attribute.String("attr2", "bar"), |
| 417 |
}, |
| 418 |
Events: []tracesdk.Event{ |
| 419 |
{ |
| 420 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 421 |
Name: "ev1", |
| 422 |
Attributes: []attribute.KeyValue{ |
| 423 |
attribute.Int64("eventattr1", 123), |
| 424 |
}, |
| 425 |
}, |
| 426 |
{ |
| 427 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 428 |
Name: "ev2", |
| 429 |
Attributes: nil, |
| 430 |
}, |
| 431 |
}, |
| 432 |
Status: tracesdk.Status{ |
| 433 |
Code: codes.Error, |
| 434 |
Description: "404, file not found", |
| 435 |
}, |
| 436 |
Resource: res, |
| 437 |
}, |
| 438 |
// span data with no events |
| 439 |
{ |
| 440 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 441 |
TraceID: trace.TraceID{ |
| 442 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 443 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 444 |
}, |
| 445 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 446 |
}), |
| 447 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 448 |
TraceID: trace.TraceID{ |
| 449 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 450 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 451 |
}, |
| 452 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 453 |
}), |
| 454 |
SpanKind: trace.SpanKindServer, |
| 455 |
Name: "foo", |
| 456 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 457 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 458 |
Attributes: []attribute.KeyValue{ |
| 459 |
attribute.Int64("attr1", 42), |
| 460 |
attribute.String("attr2", "bar"), |
| 461 |
}, |
| 462 |
Events: nil, |
| 463 |
Status: tracesdk.Status{ |
| 464 |
Code: codes.Error, |
| 465 |
Description: "404, file not found", |
| 466 |
}, |
| 467 |
Resource: res, |
| 468 |
}, |
| 469 |
// span data with an "error" attribute set to "false" |
| 470 |
{ |
| 471 |
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ |
| 472 |
TraceID: trace.TraceID{ |
| 473 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 474 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 475 |
}, |
| 476 |
SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, |
| 477 |
}), |
| 478 |
Parent: trace.NewSpanContext(trace.SpanContextConfig{ |
| 479 |
TraceID: trace.TraceID{ |
| 480 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 481 |
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
| 482 |
}, |
| 483 |
SpanID: trace.SpanID{0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38}, |
| 484 |
}), |
| 485 |
SpanKind: trace.SpanKindServer, |
| 486 |
Name: "foo", |
| 487 |
StartTime: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 488 |
EndTime: time.Date(2020, time.March, 11, 19, 25, 0, 0, time.UTC), |
| 489 |
Attributes: []attribute.KeyValue{ |
| 490 |
attribute.String("error", "false"), |
| 491 |
}, |
| 492 |
Events: []tracesdk.Event{ |
| 493 |
{ |
| 494 |
Time: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 495 |
Name: "ev1", |
| 496 |
Attributes: []attribute.KeyValue{ |
| 497 |
attribute.Int64("eventattr1", 123), |
| 498 |
}, |
| 499 |
}, |
| 500 |
{ |
| 501 |
Time: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 502 |
Name: "ev2", |
| 503 |
Attributes: nil, |
| 504 |
}, |
| 505 |
}, |
| 506 |
Resource: res, |
| 507 |
}, |
| 508 |
}.Snapshots() |
| 509 |
|
| 510 |
expectedOutputBatch := []zkmodel.SpanModel{ |
| 511 |
// model for typical span data with UNSET status |
| 512 |
{ |
| 513 |
SpanContext: zkmodel.SpanContext{ |
| 514 |
TraceID: zkmodel.TraceID{ |
| 515 |
High: 0x001020304050607, |
| 516 |
Low: 0x8090a0b0c0d0e0f, |
| 517 |
}, |
| 518 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 519 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 520 |
Debug: false, |
| 521 |
Sampled: nil, |
| 522 |
Err: nil, |
| 523 |
}, |
| 524 |
Name: "foo", |
| 525 |
Kind: "SERVER", |
| 526 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 527 |
Duration: time.Minute, |
| 528 |
Shared: false, |
| 529 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 530 |
ServiceName: "model-test", |
| 531 |
}, |
| 532 |
RemoteEndpoint: nil, |
| 533 |
Annotations: []zkmodel.Annotation{ |
| 534 |
{ |
| 535 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 536 |
Value: `ev1: {"eventattr1":123}`, |
| 537 |
}, |
| 538 |
{ |
| 539 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 540 |
Value: "ev2", |
| 541 |
}, |
| 542 |
}, |
| 543 |
Tags: map[string]string{ |
| 544 |
"attr1": "42", |
| 545 |
"attr2": "bar", |
| 546 |
"attr3": "[0,1,2]", |
| 547 |
"attr4": "[true,false,true]", |
| 548 |
"attr5": "[1.1,2.2,3.3]", |
| 549 |
"attr6": "[\"bar1\",\"bar2\",\"bar3\"]", |
| 550 |
"service.name": "model-test", |
| 551 |
"service.version": "0.1.0", |
| 552 |
"resource-attr1": "42", |
| 553 |
"resource-attr2": "[0,1,2]", |
| 554 |
}, |
| 555 |
}, |
| 556 |
// model for typical span data with OK status |
| 557 |
{ |
| 558 |
SpanContext: zkmodel.SpanContext{ |
| 559 |
TraceID: zkmodel.TraceID{ |
| 560 |
High: 0x001020304050607, |
| 561 |
Low: 0x8090a0b0c0d0e0f, |
| 562 |
}, |
| 563 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 564 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 565 |
Debug: false, |
| 566 |
Sampled: nil, |
| 567 |
Err: nil, |
| 568 |
}, |
| 569 |
Name: "foo", |
| 570 |
Kind: "SERVER", |
| 571 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 572 |
Duration: time.Minute, |
| 573 |
Shared: false, |
| 574 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 575 |
ServiceName: "model-test", |
| 576 |
}, |
| 577 |
RemoteEndpoint: nil, |
| 578 |
Annotations: []zkmodel.Annotation{ |
| 579 |
{ |
| 580 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 581 |
Value: `ev1: {"eventattr1":123}`, |
| 582 |
}, |
| 583 |
{ |
| 584 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 585 |
Value: "ev2", |
| 586 |
}, |
| 587 |
}, |
| 588 |
Tags: map[string]string{ |
| 589 |
"attr1": "42", |
| 590 |
"attr2": "bar", |
| 591 |
"attr3": "[0,1,2]", |
| 592 |
"otel.status_code": "OK", |
| 593 |
"service.name": "model-test", |
| 594 |
"service.version": "0.1.0", |
| 595 |
"resource-attr1": "42", |
| 596 |
"resource-attr2": "[0,1,2]", |
| 597 |
}, |
| 598 |
}, |
| 599 |
// model for typical span data with ERROR status |
| 600 |
{ |
| 601 |
SpanContext: zkmodel.SpanContext{ |
| 602 |
TraceID: zkmodel.TraceID{ |
| 603 |
High: 0x001020304050607, |
| 604 |
Low: 0x8090a0b0c0d0e0f, |
| 605 |
}, |
| 606 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 607 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 608 |
Debug: false, |
| 609 |
Sampled: nil, |
| 610 |
Err: nil, |
| 611 |
}, |
| 612 |
Name: "foo", |
| 613 |
Kind: "SERVER", |
| 614 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 615 |
Duration: time.Minute, |
| 616 |
Shared: false, |
| 617 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 618 |
ServiceName: "model-test", |
| 619 |
}, |
| 620 |
RemoteEndpoint: nil, |
| 621 |
Annotations: []zkmodel.Annotation{ |
| 622 |
{ |
| 623 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 624 |
Value: `ev1: {"eventattr1":123}`, |
| 625 |
}, |
| 626 |
{ |
| 627 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 628 |
Value: "ev2", |
| 629 |
}, |
| 630 |
}, |
| 631 |
Tags: map[string]string{ |
| 632 |
"attr1": "42", |
| 633 |
"attr2": "bar", |
| 634 |
"attr3": "[0,1,2]", |
| 635 |
"otel.status_code": "ERROR", |
| 636 |
"error": "404, file not found", |
| 637 |
"service.name": "model-test", |
| 638 |
"service.version": "0.1.0", |
| 639 |
"resource-attr1": "42", |
| 640 |
"resource-attr2": "[0,1,2]", |
| 641 |
}, |
| 642 |
}, |
| 643 |
// model for span data with no parent |
| 644 |
{ |
| 645 |
SpanContext: zkmodel.SpanContext{ |
| 646 |
TraceID: zkmodel.TraceID{ |
| 647 |
High: 0x001020304050607, |
| 648 |
Low: 0x8090a0b0c0d0e0f, |
| 649 |
}, |
| 650 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 651 |
ParentID: nil, |
| 652 |
Debug: false, |
| 653 |
Sampled: nil, |
| 654 |
Err: nil, |
| 655 |
}, |
| 656 |
Name: "foo", |
| 657 |
Kind: "SERVER", |
| 658 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 659 |
Duration: time.Minute, |
| 660 |
Shared: false, |
| 661 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 662 |
ServiceName: "model-test", |
| 663 |
}, |
| 664 |
RemoteEndpoint: nil, |
| 665 |
Annotations: []zkmodel.Annotation{ |
| 666 |
{ |
| 667 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 668 |
Value: `ev1: {"eventattr1":123}`, |
| 669 |
}, |
| 670 |
{ |
| 671 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 672 |
Value: "ev2", |
| 673 |
}, |
| 674 |
}, |
| 675 |
Tags: map[string]string{ |
| 676 |
"attr1": "42", |
| 677 |
"attr2": "bar", |
| 678 |
"otel.status_code": "ERROR", |
| 679 |
"error": "404, file not found", |
| 680 |
"service.name": "model-test", |
| 681 |
"service.version": "0.1.0", |
| 682 |
"resource-attr1": "42", |
| 683 |
"resource-attr2": "[0,1,2]", |
| 684 |
}, |
| 685 |
}, |
| 686 |
// model for span data of unspecified kind |
| 687 |
{ |
| 688 |
SpanContext: zkmodel.SpanContext{ |
| 689 |
TraceID: zkmodel.TraceID{ |
| 690 |
High: 0x001020304050607, |
| 691 |
Low: 0x8090a0b0c0d0e0f, |
| 692 |
}, |
| 693 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 694 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 695 |
Debug: false, |
| 696 |
Sampled: nil, |
| 697 |
Err: nil, |
| 698 |
}, |
| 699 |
Name: "foo", |
| 700 |
Kind: "", |
| 701 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 702 |
Duration: time.Minute, |
| 703 |
Shared: false, |
| 704 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 705 |
ServiceName: "model-test", |
| 706 |
}, |
| 707 |
RemoteEndpoint: nil, |
| 708 |
Annotations: []zkmodel.Annotation{ |
| 709 |
{ |
| 710 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 711 |
Value: `ev1: {"eventattr1":123}`, |
| 712 |
}, |
| 713 |
{ |
| 714 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 715 |
Value: "ev2", |
| 716 |
}, |
| 717 |
}, |
| 718 |
Tags: map[string]string{ |
| 719 |
"attr1": "42", |
| 720 |
"attr2": "bar", |
| 721 |
"otel.status_code": "ERROR", |
| 722 |
"error": "404, file not found", |
| 723 |
"service.name": "model-test", |
| 724 |
"service.version": "0.1.0", |
| 725 |
"resource-attr1": "42", |
| 726 |
"resource-attr2": "[0,1,2]", |
| 727 |
}, |
| 728 |
}, |
| 729 |
// model for span data of internal kind |
| 730 |
{ |
| 731 |
SpanContext: zkmodel.SpanContext{ |
| 732 |
TraceID: zkmodel.TraceID{ |
| 733 |
High: 0x001020304050607, |
| 734 |
Low: 0x8090a0b0c0d0e0f, |
| 735 |
}, |
| 736 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 737 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 738 |
Debug: false, |
| 739 |
Sampled: nil, |
| 740 |
Err: nil, |
| 741 |
}, |
| 742 |
Name: "foo", |
| 743 |
Kind: "", |
| 744 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 745 |
Duration: time.Minute, |
| 746 |
Shared: false, |
| 747 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 748 |
ServiceName: "model-test", |
| 749 |
}, |
| 750 |
RemoteEndpoint: nil, |
| 751 |
Annotations: []zkmodel.Annotation{ |
| 752 |
{ |
| 753 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 754 |
Value: `ev1: {"eventattr1":123}`, |
| 755 |
}, |
| 756 |
{ |
| 757 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 758 |
Value: "ev2", |
| 759 |
}, |
| 760 |
}, |
| 761 |
Tags: map[string]string{ |
| 762 |
"attr1": "42", |
| 763 |
"attr2": "bar", |
| 764 |
"otel.status_code": "ERROR", |
| 765 |
"error": "404, file not found", |
| 766 |
"service.name": "model-test", |
| 767 |
"service.version": "0.1.0", |
| 768 |
"resource-attr1": "42", |
| 769 |
"resource-attr2": "[0,1,2]", |
| 770 |
}, |
| 771 |
}, |
| 772 |
// model for span data of client kind |
| 773 |
{ |
| 774 |
SpanContext: zkmodel.SpanContext{ |
| 775 |
TraceID: zkmodel.TraceID{ |
| 776 |
High: 0x001020304050607, |
| 777 |
Low: 0x8090a0b0c0d0e0f, |
| 778 |
}, |
| 779 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 780 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 781 |
Debug: false, |
| 782 |
Sampled: nil, |
| 783 |
Err: nil, |
| 784 |
}, |
| 785 |
Name: "foo", |
| 786 |
Kind: "CLIENT", |
| 787 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 788 |
Duration: time.Minute, |
| 789 |
Shared: false, |
| 790 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 791 |
ServiceName: "model-test", |
| 792 |
}, |
| 793 |
RemoteEndpoint: &zkmodel.Endpoint{ |
| 794 |
IPv4: net.ParseIP("1.2.3.4"), |
| 795 |
Port: 9876, |
| 796 |
}, |
| 797 |
Annotations: []zkmodel.Annotation{ |
| 798 |
{ |
| 799 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 800 |
Value: `ev1: {"eventattr1":123}`, |
| 801 |
}, |
| 802 |
{ |
| 803 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 804 |
Value: "ev2", |
| 805 |
}, |
| 806 |
}, |
| 807 |
Tags: map[string]string{ |
| 808 |
"attr1": "42", |
| 809 |
"attr2": "bar", |
| 810 |
"network.peer.address": "1.2.3.4", |
| 811 |
"network.peer.port": "9876", |
| 812 |
"peer.hostname": "test-peer-hostname", |
| 813 |
"otel.status_code": "ERROR", |
| 814 |
"error": "404, file not found", |
| 815 |
"service.name": "model-test", |
| 816 |
"service.version": "0.1.0", |
| 817 |
"resource-attr1": "42", |
| 818 |
"resource-attr2": "[0,1,2]", |
| 819 |
}, |
| 820 |
}, |
| 821 |
// model for span data of producer kind |
| 822 |
{ |
| 823 |
SpanContext: zkmodel.SpanContext{ |
| 824 |
TraceID: zkmodel.TraceID{ |
| 825 |
High: 0x001020304050607, |
| 826 |
Low: 0x8090a0b0c0d0e0f, |
| 827 |
}, |
| 828 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 829 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 830 |
Debug: false, |
| 831 |
Sampled: nil, |
| 832 |
Err: nil, |
| 833 |
}, |
| 834 |
Name: "foo", |
| 835 |
Kind: "PRODUCER", |
| 836 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 837 |
Duration: time.Minute, |
| 838 |
Shared: false, |
| 839 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 840 |
ServiceName: "model-test", |
| 841 |
}, |
| 842 |
RemoteEndpoint: nil, |
| 843 |
Annotations: []zkmodel.Annotation{ |
| 844 |
{ |
| 845 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 846 |
Value: `ev1: {"eventattr1":123}`, |
| 847 |
}, |
| 848 |
{ |
| 849 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 850 |
Value: "ev2", |
| 851 |
}, |
| 852 |
}, |
| 853 |
Tags: map[string]string{ |
| 854 |
"attr1": "42", |
| 855 |
"attr2": "bar", |
| 856 |
"otel.status_code": "ERROR", |
| 857 |
"error": "404, file not found", |
| 858 |
"service.name": "model-test", |
| 859 |
"service.version": "0.1.0", |
| 860 |
"resource-attr1": "42", |
| 861 |
"resource-attr2": "[0,1,2]", |
| 862 |
}, |
| 863 |
}, |
| 864 |
// model for span data of consumer kind |
| 865 |
{ |
| 866 |
SpanContext: zkmodel.SpanContext{ |
| 867 |
TraceID: zkmodel.TraceID{ |
| 868 |
High: 0x001020304050607, |
| 869 |
Low: 0x8090a0b0c0d0e0f, |
| 870 |
}, |
| 871 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 872 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 873 |
Debug: false, |
| 874 |
Sampled: nil, |
| 875 |
Err: nil, |
| 876 |
}, |
| 877 |
Name: "foo", |
| 878 |
Kind: "CONSUMER", |
| 879 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 880 |
Duration: time.Minute, |
| 881 |
Shared: false, |
| 882 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 883 |
ServiceName: "model-test", |
| 884 |
}, |
| 885 |
RemoteEndpoint: nil, |
| 886 |
Annotations: []zkmodel.Annotation{ |
| 887 |
{ |
| 888 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 889 |
Value: `ev1: {"eventattr1":123}`, |
| 890 |
}, |
| 891 |
{ |
| 892 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 893 |
Value: "ev2", |
| 894 |
}, |
| 895 |
}, |
| 896 |
Tags: map[string]string{ |
| 897 |
"attr1": "42", |
| 898 |
"attr2": "bar", |
| 899 |
"otel.status_code": "ERROR", |
| 900 |
"error": "404, file not found", |
| 901 |
"service.name": "model-test", |
| 902 |
"service.version": "0.1.0", |
| 903 |
"resource-attr1": "42", |
| 904 |
"resource-attr2": "[0,1,2]", |
| 905 |
}, |
| 906 |
}, |
| 907 |
// model for span data with no events |
| 908 |
{ |
| 909 |
SpanContext: zkmodel.SpanContext{ |
| 910 |
TraceID: zkmodel.TraceID{ |
| 911 |
High: 0x001020304050607, |
| 912 |
Low: 0x8090a0b0c0d0e0f, |
| 913 |
}, |
| 914 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 915 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 916 |
Debug: false, |
| 917 |
Sampled: nil, |
| 918 |
Err: nil, |
| 919 |
}, |
| 920 |
Name: "foo", |
| 921 |
Kind: "SERVER", |
| 922 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 923 |
Duration: time.Minute, |
| 924 |
Shared: false, |
| 925 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 926 |
ServiceName: "model-test", |
| 927 |
}, |
| 928 |
RemoteEndpoint: nil, |
| 929 |
Annotations: nil, |
| 930 |
Tags: map[string]string{ |
| 931 |
"attr1": "42", |
| 932 |
"attr2": "bar", |
| 933 |
"otel.status_code": "ERROR", |
| 934 |
"error": "404, file not found", |
| 935 |
"service.name": "model-test", |
| 936 |
"service.version": "0.1.0", |
| 937 |
"resource-attr1": "42", |
| 938 |
"resource-attr2": "[0,1,2]", |
| 939 |
}, |
| 940 |
}, |
| 941 |
// model for span data with an "error" attribute set to "false" |
| 942 |
{ |
| 943 |
SpanContext: zkmodel.SpanContext{ |
| 944 |
TraceID: zkmodel.TraceID{ |
| 945 |
High: 0x001020304050607, |
| 946 |
Low: 0x8090a0b0c0d0e0f, |
| 947 |
}, |
| 948 |
ID: zkmodel.ID(0xfffefdfcfbfaf9f8), |
| 949 |
ParentID: zkmodelIDPtr(0x3f3e3d3c3b3a3938), |
| 950 |
Debug: false, |
| 951 |
Sampled: nil, |
| 952 |
Err: nil, |
| 953 |
}, |
| 954 |
Name: "foo", |
| 955 |
Kind: "SERVER", |
| 956 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 0, 0, time.UTC), |
| 957 |
Duration: time.Minute, |
| 958 |
Shared: false, |
| 959 |
LocalEndpoint: &zkmodel.Endpoint{ |
| 960 |
ServiceName: "model-test", |
| 961 |
}, |
| 962 |
RemoteEndpoint: nil, |
| 963 |
Annotations: []zkmodel.Annotation{ |
| 964 |
{ |
| 965 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 30, 0, time.UTC), |
| 966 |
Value: `ev1: {"eventattr1":123}`, |
| 967 |
}, |
| 968 |
{ |
| 969 |
Timestamp: time.Date(2020, time.March, 11, 19, 24, 45, 0, time.UTC), |
| 970 |
Value: "ev2", |
| 971 |
}, |
| 972 |
}, |
| 973 |
Tags: map[string]string{ |
| 974 |
"service.name": "model-test", |
| 975 |
"service.version": "0.1.0", |
| 976 |
"resource-attr1": "42", |
| 977 |
"resource-attr2": "[0,1,2]", |
| 978 |
}, // only resource tags should be included |
| 979 |
}, |
| 980 |
} |
| 981 |
gottenOutputBatch := SpanModels(inputBatch) |
| 982 |
require.Equal(t, expectedOutputBatch, gottenOutputBatch) |
| 983 |
} |
| 984 |
|
| 985 |
func zkmodelIDPtr(n uint64) *zkmodel.ID { |
| 986 |
id := zkmodel.ID(n) |
| 987 |
return &id |
| 988 |
} |
| 989 |
|
| 990 |
func TestTagsTransformation(t *testing.T) { |
| 991 |
keyValue := "value" |
| 992 |
doubleValue := 123.456 |
| 993 |
uintValue := int64(123) |
| 994 |
statusMessage := "this is a problem" |
| 995 |
instrLibName := "instrumentation-library" |
| 996 |
instrLibVersion := "semver:1.0.0" |
| 997 |
|
| 998 |
tests := []struct { |
| 999 |
name string |
| 1000 |
data tracetest.SpanStub |
| 1001 |
want map[string]string |
| 1002 |
}{ |
| 1003 |
{ |
| 1004 |
name: "attributes", |
| 1005 |
data: tracetest.SpanStub{ |
| 1006 |
Attributes: []attribute.KeyValue{ |
| 1007 |
attribute.String("key", keyValue), |
| 1008 |
attribute.Float64("double", doubleValue), |
| 1009 |
attribute.Int64("uint", uintValue), |
| 1010 |
attribute.Bool("ok", true), |
| 1011 |
}, |
| 1012 |
}, |
| 1013 |
want: map[string]string{ |
| 1014 |
"double": fmt.Sprint(doubleValue), |
| 1015 |
"key": keyValue, |
| 1016 |
"ok": "true", |
| 1017 |
"uint": strconv.FormatInt(uintValue, 10), |
| 1018 |
}, |
| 1019 |
}, |
| 1020 |
{ |
| 1021 |
name: "no attributes", |
| 1022 |
data: tracetest.SpanStub{}, |
| 1023 |
want: nil, |
| 1024 |
}, |
| 1025 |
{ |
| 1026 |
name: "omit-noerror", |
| 1027 |
data: tracetest.SpanStub{ |
| 1028 |
Attributes: []attribute.KeyValue{ |
| 1029 |
attribute.Bool("error", false), |
| 1030 |
}, |
| 1031 |
}, |
| 1032 |
want: nil, |
| 1033 |
}, |
| 1034 |
{ |
| 1035 |
name: "statusCode UNSET", |
| 1036 |
data: tracetest.SpanStub{ |
| 1037 |
Attributes: []attribute.KeyValue{ |
| 1038 |
attribute.String("key", keyValue), |
| 1039 |
}, |
| 1040 |
Status: tracesdk.Status{ |
| 1041 |
Code: codes.Unset, |
| 1042 |
Description: "", |
| 1043 |
}, |
| 1044 |
}, |
| 1045 |
want: map[string]string{ |
| 1046 |
"key": keyValue, |
| 1047 |
}, |
| 1048 |
}, |
| 1049 |
{ |
| 1050 |
name: "statusCode OK", |
| 1051 |
data: tracetest.SpanStub{ |
| 1052 |
Attributes: []attribute.KeyValue{ |
| 1053 |
attribute.String("key", keyValue), |
| 1054 |
attribute.Bool("ok", true), |
| 1055 |
}, |
| 1056 |
Status: tracesdk.Status{ |
| 1057 |
Code: codes.Ok, |
| 1058 |
Description: "", |
| 1059 |
}, |
| 1060 |
}, |
| 1061 |
want: map[string]string{ |
| 1062 |
"key": keyValue, |
| 1063 |
"ok": "true", |
| 1064 |
"otel.status_code": "OK", |
| 1065 |
}, |
| 1066 |
}, |
| 1067 |
{ |
| 1068 |
name: "statusCode ERROR", |
| 1069 |
data: tracetest.SpanStub{ |
| 1070 |
Attributes: []attribute.KeyValue{ |
| 1071 |
attribute.String("key", keyValue), |
| 1072 |
attribute.Bool("error", true), |
| 1073 |
}, |
| 1074 |
Status: tracesdk.Status{ |
| 1075 |
Code: codes.Error, |
| 1076 |
Description: statusMessage, |
| 1077 |
}, |
| 1078 |
}, |
| 1079 |
want: map[string]string{ |
| 1080 |
"error": statusMessage, |
| 1081 |
"key": keyValue, |
| 1082 |
"otel.status_code": "ERROR", |
| 1083 |
}, |
| 1084 |
}, |
| 1085 |
{ |
| 1086 |
name: "instrLib-empty", |
| 1087 |
data: tracetest.SpanStub{ |
| 1088 |
InstrumentationScope: instrumentation.Scope{}, |
| 1089 |
}, |
| 1090 |
want: nil, |
| 1091 |
}, |
| 1092 |
{ |
| 1093 |
name: "instrLib-noversion", |
| 1094 |
data: tracetest.SpanStub{ |
| 1095 |
Attributes: []attribute.KeyValue{}, |
| 1096 |
InstrumentationScope: instrumentation.Scope{ |
| 1097 |
Name: instrLibName, |
| 1098 |
}, |
| 1099 |
}, |
| 1100 |
want: map[string]string{ |
| 1101 |
"otel.scope.name": instrLibName, |
| 1102 |
}, |
| 1103 |
}, |
| 1104 |
{ |
| 1105 |
name: "instrLib-with-version", |
| 1106 |
data: tracetest.SpanStub{ |
| 1107 |
Attributes: []attribute.KeyValue{}, |
| 1108 |
InstrumentationScope: instrumentation.Scope{ |
| 1109 |
Name: instrLibName, |
| 1110 |
Version: instrLibVersion, |
| 1111 |
}, |
| 1112 |
}, |
| 1113 |
want: map[string]string{ |
| 1114 |
"otel.scope.name": instrLibName, |
| 1115 |
"otel.scope.version": instrLibVersion, |
| 1116 |
}, |
| 1117 |
}, |
| 1118 |
} |
| 1119 |
for _, tt := range tests { |
| 1120 |
t.Run(tt.name, func(t *testing.T) { |
| 1121 |
got := toZipkinTags(tt.data.Snapshot()) |
| 1122 |
if diff := cmp.Diff(got, tt.want); diff != "" { |
| 1123 |
t.Errorf("Diff%v", diff) |
| 1124 |
} |
| 1125 |
}) |
| 1126 |
} |
| 1127 |
} |
| 1128 |
|
| 1129 |
func TestRemoteEndpointTransformation(t *testing.T) { |
| 1130 |
tests := []struct { |
| 1131 |
name string |
| 1132 |
data tracetest.SpanStub |
| 1133 |
want *zkmodel.Endpoint |
| 1134 |
}{ |
| 1135 |
{ |
| 1136 |
name: "nil-not-applicable", |
| 1137 |
data: tracetest.SpanStub{ |
| 1138 |
SpanKind: trace.SpanKindClient, |
| 1139 |
Attributes: []attribute.KeyValue{}, |
| 1140 |
}, |
| 1141 |
want: nil, |
| 1142 |
}, |
| 1143 |
{ |
| 1144 |
name: "nil-not-found", |
| 1145 |
data: tracetest.SpanStub{ |
| 1146 |
SpanKind: trace.SpanKindConsumer, |
| 1147 |
Attributes: []attribute.KeyValue{ |
| 1148 |
attribute.String("attr", "test"), |
| 1149 |
}, |
| 1150 |
}, |
| 1151 |
want: nil, |
| 1152 |
}, |
| 1153 |
{ |
| 1154 |
name: "peer.service-rank", |
| 1155 |
data: tracetest.SpanStub{ |
| 1156 |
SpanKind: trace.SpanKindProducer, |
| 1157 |
Attributes: []attribute.KeyValue{ |
| 1158 |
semconv138.PeerService("peer-service-test"), |
| 1159 |
semconv.ServerAddress("server-address-test"), |
| 1160 |
semconv.NetworkPeerAddress("10.1.2.80"), |
| 1161 |
}, |
| 1162 |
}, |
| 1163 |
want: &zkmodel.Endpoint{ |
| 1164 |
ServiceName: "peer-service-test", |
| 1165 |
}, |
| 1166 |
}, |
| 1167 |
{ |
| 1168 |
name: "server.address-rank", |
| 1169 |
data: tracetest.SpanStub{ |
| 1170 |
SpanKind: trace.SpanKindProducer, |
| 1171 |
Attributes: []attribute.KeyValue{ |
| 1172 |
semconv.ServerAddress("server-address-test"), |
| 1173 |
attribute.String("net.peer.name", "net-peer-name-test"), |
| 1174 |
semconv.NetworkPeerAddress("10.1.2.80"), |
| 1175 |
}, |
| 1176 |
}, |
| 1177 |
want: &zkmodel.Endpoint{ |
| 1178 |
ServiceName: "server-address-test", |
| 1179 |
}, |
| 1180 |
}, |
| 1181 |
{ |
| 1182 |
name: "net.peer.name-rank", |
| 1183 |
data: tracetest.SpanStub{ |
| 1184 |
SpanKind: trace.SpanKindProducer, |
| 1185 |
Attributes: []attribute.KeyValue{ |
| 1186 |
attribute.String("net.peer.name", "net-peer-name-test"), |
| 1187 |
semconv.NetworkPeerAddress("10.1.2.80"), |
| 1188 |
}, |
| 1189 |
}, |
| 1190 |
want: &zkmodel.Endpoint{ |
| 1191 |
ServiceName: "net-peer-name-test", |
| 1192 |
}, |
| 1193 |
}, |
| 1194 |
{ |
| 1195 |
name: "network.peer.address-rank", |
| 1196 |
data: tracetest.SpanStub{ |
| 1197 |
SpanKind: trace.SpanKindProducer, |
| 1198 |
Attributes: []attribute.KeyValue{ |
| 1199 |
keyPeerHostname.String("peer-hostname-test"), |
| 1200 |
semconv.NetworkPeerAddress("10.1.2.80"), |
| 1201 |
semconv125.DBName("db-name-test"), |
| 1202 |
attribute.String("server.socket.domain", "server-socket-domain-test"), |
| 1203 |
}, |
| 1204 |
}, |
| 1205 |
want: &zkmodel.Endpoint{ |
| 1206 |
IPv4: net.ParseIP("10.1.2.80"), |
| 1207 |
}, |
| 1208 |
}, |
| 1209 |
{ |
| 1210 |
name: "server.socket.domain-rank", |
| 1211 |
data: tracetest.SpanStub{ |
| 1212 |
SpanKind: trace.SpanKindProducer, |
| 1213 |
Attributes: []attribute.KeyValue{ |
| 1214 |
keyPeerHostname.String("peer-hostname-test"), |
| 1215 |
semconv125.DBName("db-name-test"), |
| 1216 |
attribute.String("server.socket.domain", "server-socket-domain-test"), |
| 1217 |
attribute.String("server.socket.address", "10.2.3.4"), |
| 1218 |
}, |
| 1219 |
}, |
| 1220 |
want: &zkmodel.Endpoint{ |
| 1221 |
ServiceName: "server-socket-domain-test", |
| 1222 |
}, |
| 1223 |
}, |
| 1224 |
{ |
| 1225 |
name: "server.socket.address-rank", |
| 1226 |
data: tracetest.SpanStub{ |
| 1227 |
SpanKind: trace.SpanKindProducer, |
| 1228 |
Attributes: []attribute.KeyValue{ |
| 1229 |
keyPeerHostname.String("peer-hostname-test"), |
| 1230 |
semconv125.DBName("db-name-test"), |
| 1231 |
attribute.String("net.sock.peer.name", "server-socket-domain-test"), |
| 1232 |
attribute.String("server.socket.address", "10.2.3.4"), |
| 1233 |
}, |
| 1234 |
}, |
| 1235 |
want: &zkmodel.Endpoint{ |
| 1236 |
IPv4: net.ParseIP("10.2.3.4"), |
| 1237 |
}, |
| 1238 |
}, |
| 1239 |
{ |
| 1240 |
name: "net.sock.peer.name-rank", |
| 1241 |
data: tracetest.SpanStub{ |
| 1242 |
SpanKind: trace.SpanKindProducer, |
| 1243 |
Attributes: []attribute.KeyValue{ |
| 1244 |
keyPeerHostname.String("peer-hostname-test"), |
| 1245 |
semconv125.DBName("db-name-test"), |
| 1246 |
attribute.String("net.sock.peer.name", "net-sock-peer-name-test"), |
| 1247 |
attribute.String("net.sock.peer.addr", "10.4.8.12"), |
| 1248 |
}, |
| 1249 |
}, |
| 1250 |
want: &zkmodel.Endpoint{ |
| 1251 |
ServiceName: "net-sock-peer-name-test", |
| 1252 |
}, |
| 1253 |
}, |
| 1254 |
{ |
| 1255 |
name: "net.sock.peer.addr-rank", |
| 1256 |
data: tracetest.SpanStub{ |
| 1257 |
SpanKind: trace.SpanKindProducer, |
| 1258 |
Attributes: []attribute.KeyValue{ |
| 1259 |
keyPeerHostname.String("peer-hostname-test"), |
| 1260 |
semconv125.DBName("db-name-test"), |
| 1261 |
attribute.String("net.sock.peer.addr", "10.4.8.12"), |
| 1262 |
}, |
| 1263 |
}, |
| 1264 |
want: &zkmodel.Endpoint{ |
| 1265 |
IPv4: net.ParseIP("10.4.8.12"), |
| 1266 |
}, |
| 1267 |
}, |
| 1268 |
{ |
| 1269 |
name: "peer.hostname-rank", |
| 1270 |
data: tracetest.SpanStub{ |
| 1271 |
SpanKind: trace.SpanKindProducer, |
| 1272 |
Attributes: []attribute.KeyValue{ |
| 1273 |
keyPeerHostname.String("peer-hostname-test"), |
| 1274 |
keyPeerAddress.String("peer-address-test"), |
| 1275 |
semconv125.DBName("http-host-test"), |
| 1276 |
}, |
| 1277 |
}, |
| 1278 |
want: &zkmodel.Endpoint{ |
| 1279 |
ServiceName: "peer-hostname-test", |
| 1280 |
}, |
| 1281 |
}, |
| 1282 |
{ |
| 1283 |
name: "peer.address-rank", |
| 1284 |
data: tracetest.SpanStub{ |
| 1285 |
SpanKind: trace.SpanKindProducer, |
| 1286 |
Attributes: []attribute.KeyValue{ |
| 1287 |
keyPeerAddress.String("peer-address-test"), |
| 1288 |
semconv125.DBName("http-host-test"), |
| 1289 |
}, |
| 1290 |
}, |
| 1291 |
want: &zkmodel.Endpoint{ |
| 1292 |
ServiceName: "peer-address-test", |
| 1293 |
}, |
| 1294 |
}, |
| 1295 |
{ |
| 1296 |
name: "db.name-rank", |
| 1297 |
data: tracetest.SpanStub{ |
| 1298 |
SpanKind: trace.SpanKindProducer, |
| 1299 |
Attributes: []attribute.KeyValue{ |
| 1300 |
attribute.String("foo", "bar"), |
| 1301 |
semconv125.DBName("db-name-test"), |
| 1302 |
}, |
| 1303 |
}, |
| 1304 |
want: &zkmodel.Endpoint{ |
| 1305 |
ServiceName: "db-name-test", |
| 1306 |
}, |
| 1307 |
}, |
| 1308 |
{ |
| 1309 |
name: "network.peer.address-invalid-ip", |
| 1310 |
data: tracetest.SpanStub{ |
| 1311 |
SpanKind: trace.SpanKindProducer, |
| 1312 |
Attributes: []attribute.KeyValue{ |
| 1313 |
semconv.NetworkPeerAddress("INVALID"), |
| 1314 |
}, |
| 1315 |
}, |
| 1316 |
want: nil, |
| 1317 |
}, |
| 1318 |
{ |
| 1319 |
name: "network.peer.address-ipv6-no-port", |
| 1320 |
data: tracetest.SpanStub{ |
| 1321 |
SpanKind: trace.SpanKindProducer, |
| 1322 |
Attributes: []attribute.KeyValue{ |
| 1323 |
semconv.NetworkPeerAddress("0:0:1:5ee:bad:c0de:0:0"), |
| 1324 |
}, |
| 1325 |
}, |
| 1326 |
want: &zkmodel.Endpoint{ |
| 1327 |
IPv6: net.ParseIP("0:0:1:5ee:bad:c0de:0:0"), |
| 1328 |
}, |
| 1329 |
}, |
| 1330 |
{ |
| 1331 |
name: "network.peer.address-ipv4-port", |
| 1332 |
data: tracetest.SpanStub{ |
| 1333 |
SpanKind: trace.SpanKindProducer, |
| 1334 |
Attributes: []attribute.KeyValue{ |
| 1335 |
semconv.NetworkPeerAddress("1.2.3.4"), |
| 1336 |
semconv.NetworkPeerPort(9876), |
| 1337 |
attribute.Int("server.socket.port", 5432), |
| 1338 |
attribute.Int("net.sock.peer.port", 2345), |
| 1339 |
}, |
| 1340 |
}, |
| 1341 |
want: &zkmodel.Endpoint{ |
| 1342 |
IPv4: net.ParseIP("1.2.3.4"), |
| 1343 |
Port: 9876, |
| 1344 |
}, |
| 1345 |
}, |
| 1346 |
{ |
| 1347 |
name: "server.socket.address-ipv4-port", |
| 1348 |
data: tracetest.SpanStub{ |
| 1349 |
SpanKind: trace.SpanKindProducer, |
| 1350 |
Attributes: []attribute.KeyValue{ |
| 1351 |
attribute.String("server.socket.address", "1.2.3.4"), |
| 1352 |
semconv.NetworkPeerPort(9876), |
| 1353 |
attribute.Int("server.socket.port", 5432), |
| 1354 |
attribute.Int("net.sock.peer.port", 2345), |
| 1355 |
}, |
| 1356 |
}, |
| 1357 |
want: &zkmodel.Endpoint{ |
| 1358 |
IPv4: net.ParseIP("1.2.3.4"), |
| 1359 |
Port: 5432, |
| 1360 |
}, |
| 1361 |
}, |
| 1362 |
{ |
| 1363 |
name: "net.sock.peer.addr-ipv4-port", |
| 1364 |
data: tracetest.SpanStub{ |
| 1365 |
SpanKind: trace.SpanKindProducer, |
| 1366 |
Attributes: []attribute.KeyValue{ |
| 1367 |
attribute.String("net.sock.peer.addr", "1.2.3.4"), |
| 1368 |
semconv.NetworkPeerPort(9876), |
| 1369 |
attribute.Int("server.socket.port", 5432), |
| 1370 |
attribute.Int("net.sock.peer.port", 2345), |
| 1371 |
}, |
| 1372 |
}, |
| 1373 |
want: &zkmodel.Endpoint{ |
| 1374 |
IPv4: net.ParseIP("1.2.3.4"), |
| 1375 |
Port: 2345, |
| 1376 |
}, |
| 1377 |
}, |
| 1378 |
} |
| 1379 |
for _, tt := range tests { |
| 1380 |
t.Run(tt.name, func(t *testing.T) { |
| 1381 |
got := toZipkinRemoteEndpoint(tt.data.Snapshot()) |
| 1382 |
if diff := cmp.Diff(got, tt.want); diff != "" { |
| 1383 |
t.Errorf("Diff%v", diff) |
| 1384 |
} |
| 1385 |
}) |
| 1386 |
} |
| 1387 |
} |
| 1388 |
|
| 1389 |
func TestServiceName(t *testing.T) { |
| 1390 |
attrs := []attribute.KeyValue{} |
| 1391 |
assert.Equal(t, defaultServiceName, getServiceName(attrs)) |
| 1392 |
|
| 1393 |
attrs = append(attrs, attribute.String("test_key", "test_value")) |
| 1394 |
assert.Equal(t, defaultServiceName, getServiceName(attrs)) |
| 1395 |
|
| 1396 |
attrs = append(attrs, semconv.ServiceName("my_service")) |
| 1397 |
assert.Equal(t, "my_service", getServiceName(attrs)) |
| 1398 |
} |