| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package testdata |
| 5 |
|
| 6 |
import ( |
| 7 |
"time" |
| 8 |
|
| 9 |
"go.opentelemetry.io/collector/pdata/pcommon" |
| 10 |
"go.opentelemetry.io/collector/pdata/plog" |
| 11 |
) |
| 12 |
|
| 13 |
var logTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC)) |
| 14 |
|
| 15 |
func GenerateLogs(count int) plog.Logs { |
| 16 |
ld := plog.NewLogs() |
| 17 |
initResource(ld.ResourceLogs().AppendEmpty().Resource()) |
| 18 |
logs := ld.ResourceLogs().At(0).ScopeLogs().AppendEmpty().LogRecords() |
| 19 |
logs.EnsureCapacity(count) |
| 20 |
for i := range count { |
| 21 |
switch i % 2 { |
| 22 |
case 0: |
| 23 |
fillLogOne(logs.AppendEmpty()) |
| 24 |
case 1: |
| 25 |
fillLogTwo(logs.AppendEmpty()) |
| 26 |
} |
| 27 |
} |
| 28 |
return ld |
| 29 |
} |
| 30 |
|
| 31 |
func fillLogOne(log plog.LogRecord) { |
| 32 |
log.SetTimestamp(logTimestamp) |
| 33 |
log.SetDroppedAttributesCount(1) |
| 34 |
log.SetSeverityNumber(plog.SeverityNumberInfo) |
| 35 |
log.SetSeverityText("Info") |
| 36 |
log.SetSpanID([8]byte{0x01, 0x02, 0x04, 0x08}) |
| 37 |
log.SetTraceID([16]byte{0x08, 0x04, 0x02, 0x01}) |
| 38 |
|
| 39 |
attrs := log.Attributes() |
| 40 |
attrs.PutStr("app", "server") |
| 41 |
attrs.PutInt("instance_num", 1) |
| 42 |
|
| 43 |
log.Body().SetStr("This is a log message") |
| 44 |
} |
| 45 |
|
| 46 |
func fillLogTwo(log plog.LogRecord) { |
| 47 |
log.SetTimestamp(logTimestamp) |
| 48 |
log.SetDroppedAttributesCount(1) |
| 49 |
log.SetSeverityNumber(plog.SeverityNumberInfo) |
| 50 |
log.SetSeverityText("Info") |
| 51 |
|
| 52 |
attrs := log.Attributes() |
| 53 |
attrs.PutStr("customer", "acme") |
| 54 |
attrs.PutStr("env", "dev") |
| 55 |
|
| 56 |
log.Body().SetStr("something happened") |
| 57 |
} |