Skip to content

Commit

Permalink
Fixed empty log record bug by platform events (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrytfleung authored Sep 24, 2024
1 parent e06aa18 commit c9e67c4
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 9 deletions.
18 changes: 9 additions & 9 deletions collector/receiver/telemetryapireceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ func (r *telemetryAPIReceiver) createLogs(slice []event) (plog.Logs, error) {
scopeLog.Scope().SetName(scopeName)
for _, el := range slice {
r.logger.Debug(fmt.Sprintf("Event: %s", el.Type), zap.Any("event", el))
logRecord := scopeLog.LogRecords().AppendEmpty()
logRecord.Attributes().PutStr("type", el.Type)
if t, err := time.Parse(time.RFC3339, el.Time); err == nil {
logRecord.SetTimestamp(pcommon.NewTimestampFromTime(t))
logRecord.SetObservedTimestamp(pcommon.NewTimestampFromTime(time.Now()))
} else {
r.logger.Error("error parsing time", zap.Error(err))
return plog.Logs{}, err
}
if el.Type == string(telemetryapi.Function) || el.Type == string(telemetryapi.Extension) {
logRecord := scopeLog.LogRecords().AppendEmpty()
logRecord.Attributes().PutStr("type", el.Type)
if t, err := time.Parse(time.RFC3339, el.Time); err == nil {
logRecord.SetTimestamp(pcommon.NewTimestampFromTime(t))
logRecord.SetObservedTimestamp(pcommon.NewTimestampFromTime(time.Now()))
} else {
r.logger.Error("error parsing time", zap.Error(err))
return plog.Logs{}, err
}
if record, ok := el.Record.(map[string]interface{}); ok {
// in JSON format https://docs.aws.amazon.com/lambda/latest/dg/telemetry-schema-reference.html#telemetry-api-function
if timestamp, ok := record["timestamp"].(string); ok {
Expand Down
132 changes: 132 additions & 0 deletions collector/receiver/telemetryapireceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,138 @@ func TestCreateLogs(t *testing.T) {
expectedSeverityNumber: plog.SeverityNumberUnspecified,
expectError: false,
},
{
desc: "platform.initStart anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.initStart",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.initRuntimeDone anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.initRuntimeDone",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.initReport anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.initReport",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.start anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.start",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.runtimeDone anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.runtimeDone",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.report anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.report",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.restoreStart anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.restoreStart",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.restoreRuntimeDone anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.restoreRuntimeDone",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.restoreReport anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.restoreStart",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.telemetrySubscription anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.telemetrySubscription",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
{
desc: "platform.logsDropped anything",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.logsDropped",
Record: map[string]any{},
},
},
expectedLogRecords: 0,
expectError: false,
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
Expand Down

0 comments on commit c9e67c4

Please sign in to comment.