diff --git a/collector/receiver/telemetryapireceiver/receiver.go b/collector/receiver/telemetryapireceiver/receiver.go index 6fbc8a6774..758bc16fad 100644 --- a/collector/receiver/telemetryapireceiver/receiver.go +++ b/collector/receiver/telemetryapireceiver/receiver.go @@ -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 { diff --git a/collector/receiver/telemetryapireceiver/receiver_test.go b/collector/receiver/telemetryapireceiver/receiver_test.go index 691d3fa7c1..1bc856971d 100644 --- a/collector/receiver/telemetryapireceiver/receiver_test.go +++ b/collector/receiver/telemetryapireceiver/receiver_test.go @@ -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) {