Skip to content
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

NH-76996 - Disabled platform events log processing #25

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 19 additions & 18 deletions collector/receiver/telemetryapireceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,16 @@ func (r *telemetryAPIReceiver) createLogs(slice []telemetryapi.Event) (plog.Logs
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(timeFormatLayout, 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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we agreed not to forward Extension events as logs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Can we just not subscribe to anything other than Function events for this round to minimize overhead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Done

logRecord := scopeLog.LogRecords().AppendEmpty()
logRecord.Attributes().PutStr("type", el.Type)
if t, err := time.Parse(timeFormatLayout, 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 Expand Up @@ -307,16 +307,17 @@ func (r *telemetryAPIReceiver) createLogs(slice []telemetryapi.Event) (plog.Logs
logRecord.Body().SetStr(line)
}
}
} else {
logRecord.SetSeverityNumber(9)
logRecord.SetSeverityText(logRecord.SeverityNumber().String())
if j, err := json.Marshal(el.Record); err == nil {
logRecord.Body().SetStr(string(j))
} else {
r.logger.Error("error stringify record", zap.Error(err))
return plog.Logs{}, err
}
}
//} else {
// logRecord.SetSeverityNumber(9)
// logRecord.SetSeverityText(logRecord.SeverityNumber().String())
// if j, err := json.Marshal(el.Record); err == nil {
// logRecord.Body().SetStr(string(j))
// } else {
// r.logger.Error("error stringify record", zap.Error(err))
// return plog.Logs{}, err
// }
//}
}
return log, nil
}
Expand Down
2 changes: 1 addition & 1 deletion collector/receiver/telemetryapireceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestCreateLogs(t *testing.T) {
},
},
},
expectedLogRecords: 1,
expectedLogRecords: 0,
expectedType: "platform.initReport",
expectedTimestamp: "2024-05-15T23:58:26.858Z",
expectedBody: "{\"initializationType\":\"on-demand\",\"metrics\":{\"durationMs\":1819.081},\"phase\":\"init\",\"status\":\"success\"}",
Expand Down