Skip to content
Open
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
13 changes: 13 additions & 0 deletions collector/internal/telemetryapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,16 @@ const (
MetricMemorySizeMB MetricType = "memorySizeMB"
MetricInitDurationMs MetricType = "initDurationMs"
)

// PlatformReportStatus is the status field found on Telemetry API `platform.report` events.
//
// Valid status values – success|failure|error|timeout
// See https://docs.aws.amazon.com/lambda/latest/dg/telemetry-schema-reference.html#Status
type PlatformReportStatus string

const (
PlatformReportStatusSuccess PlatformReportStatus = "success"
PlatformReportStatusFailure PlatformReportStatus = "failure"
PlatformReportStatusError PlatformReportStatus = "error"
PlatformReportStatusTimeout PlatformReportStatus = "timeout"
)
10 changes: 10 additions & 0 deletions collector/receiver/telemetryapireceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ func createPlatformReportMessage(requestId string, record map[string]interface{}
}
}

// checking status
reportStatus := string(telemetryapi.PlatformReportStatusSuccess)
if status, ok := record["status"].(string); ok {
reportStatus = status
}

message := fmt.Sprintf(
platformReportLogFmt,
requestId,
Expand All @@ -408,6 +414,10 @@ func createPlatformReportMessage(requestId string, record map[string]interface{}
if initDurationMs > 0 {
message += fmt.Sprintf(" Init Duration: %.2f ms", initDurationMs)
}
// AWS does not log success status, let's conform to that
if reportStatus != string(telemetryapi.PlatformReportStatusSuccess) {
message += fmt.Sprintf(" Status: %s", reportStatus)
}

return message
}
Expand Down
58 changes: 58 additions & 0 deletions collector/receiver/telemetryapireceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ func TestCreateLogsWithLogReport(t *testing.T) {
Type: "platform.report",
Record: map[string]any{
"requestId": "test-request-id-123",
"status": "success",
"metrics": map[string]any{
"durationMs": 123.45,
"billedDurationMs": float64(124),
Expand All @@ -686,6 +687,31 @@ func TestCreateLogsWithLogReport(t *testing.T) {
expectedBody: "REPORT RequestId: test-request-id-123 Duration: 123.45 ms Billed Duration: 124 ms Memory Size: 512 MB Max Memory Used: 256 MB",
expectError: false,
},
{
desc: "platform.report with logReport enabled - status failure adds Status suffix",
slice: []event{
{
Time: "2022-10-12T00:03:50.000Z",
Type: "platform.report",
Record: map[string]any{
"requestId": "test-request-id-123",
"status": "failure",
"metrics": map[string]any{
"durationMs": 123.45,
"billedDurationMs": float64(124),
"memorySizeMB": float64(512),
"maxMemoryUsedMB": float64(256),
},
},
},
},
logReport: true,
expectedLogRecords: 1,
expectedType: "platform.report",
expectedTimestamp: "2022-10-12T00:03:50.000Z",
expectedBody: "REPORT RequestId: test-request-id-123 Duration: 123.45 ms Billed Duration: 124 ms Memory Size: 512 MB Max Memory Used: 256 MB Status: failure",
expectError: false,
},
{
desc: "platform.report with logReport disabled",
slice: []event{
Expand Down Expand Up @@ -963,6 +989,38 @@ func TestCreatePlatformMessage(t *testing.T) {
},
expected: "REPORT RequestId: test-request-id Duration: 100.50 ms Billed Duration: 101 ms Memory Size: 128 MB Max Memory Used: 64 MB",
},
{
desc: "platform.report with status success does not add Status suffix",
requestId: "test-request-id",
functionVersion: "$LATEST",
eventType: "platform.report",
record: map[string]interface{}{
"status": "success",
"metrics": map[string]interface{}{
"durationMs": 100.5,
"billedDurationMs": 101.0,
"memorySizeMB": 128.0,
"maxMemoryUsedMB": 64.0,
},
},
expected: "REPORT RequestId: test-request-id Duration: 100.50 ms Billed Duration: 101 ms Memory Size: 128 MB Max Memory Used: 64 MB",
},
{
desc: "platform.report with status timeout adds Status suffix",
requestId: "test-request-id",
functionVersion: "$LATEST",
eventType: "platform.report",
record: map[string]interface{}{
"status": "timeout",
"metrics": map[string]interface{}{
"durationMs": 100.5,
"billedDurationMs": 101.0,
"memorySizeMB": 128.0,
"maxMemoryUsedMB": 64.0,
},
},
expected: "REPORT RequestId: test-request-id Duration: 100.50 ms Billed Duration: 101 ms Memory Size: 128 MB Max Memory Used: 64 MB Status: timeout",
},
{
desc: "platform.report with missing metrics",
requestId: "test-request-id",
Expand Down
Loading