Skip to content

Fix telemetry API receiver: creating empty log record(s) by platform events #1522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading