Skip to content

Commit 568bd93

Browse files
committed
use types
1 parent 4dd17cd commit 568bd93

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

collector/internal/telemetryapi/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,15 @@ type Event struct {
9797
Type string `json:"type"`
9898
Record map[string]any `json:"record"`
9999
}
100+
101+
// MetricType represents the type of metric in the platform.report event
102+
// see https://docs.aws.amazon.com/lambda/latest/dg/telemetry-schema-reference.html#ReportMetrics
103+
type MetricType string
104+
105+
const (
106+
MetricBilledDurationMs MetricType = "billedDurationMs"
107+
MetricDurationMs MetricType = "durationMs"
108+
MetricMaxMemoryUsedMB MetricType = "maxMemoryUsedMB"
109+
MetricMemorySizeMB MetricType = "memorySizeMB"
110+
MetricInitDurationMs MetricType = "initDurationMs"
111+
)

collector/receiver/telemetryapireceiver/receiver.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,7 @@ import (
4444
const (
4545
initialQueueSize = 5
4646
scopeName = "github.com/open-telemetry/opentelemetry-lambda/collector/receiver/telemetryapi"
47-
48-
logReportFmt = "REPORT RequestId: %s Duration: %.2f ms Billed Duration: %.0f ms Memory Size: %.0f MB Max Memory Used: %.0f MB"
49-
metricBilledDurationMs = "billedDurationMs"
50-
metricDurationMs = "durationMs"
51-
metricMaxMemoryUsedMB = "maxMemoryUsedMB"
52-
metricMemorySizeMB = "memorySizeMB"
53-
metricInitDurationMs = "initDurationMs"
47+
logReportFmt = "REPORT RequestId: %s Duration: %.2f ms Billed Duration: %.0f ms Memory Size: %.0f MB Max Memory Used: %.0f MB"
5448
)
5549

5650
type telemetryAPIReceiver struct {
@@ -279,16 +273,16 @@ func createReportLogRecord(scopeLog *plog.ScopeLogs, record map[string]interface
279273
return nil
280274
}
281275
var durationMs, billedDurationMs, memorySizeMB, maxMemoryUsedMB float64
282-
if durationMs, ok = metrics[metricDurationMs].(float64); !ok {
276+
if durationMs, ok = metrics[string(telemetryapi.MetricDurationMs)].(float64); !ok {
283277
return nil
284278
}
285-
if billedDurationMs, ok = metrics[metricBilledDurationMs].(float64); !ok {
279+
if billedDurationMs, ok = metrics[string(telemetryapi.MetricBilledDurationMs)].(float64); !ok {
286280
return nil
287281
}
288-
if memorySizeMB, ok = metrics[metricMemorySizeMB].(float64); !ok {
282+
if memorySizeMB, ok = metrics[string(telemetryapi.MetricMemorySizeMB)].(float64); !ok {
289283
return nil
290284
}
291-
if maxMemoryUsedMB, ok = metrics[metricMaxMemoryUsedMB].(float64); !ok {
285+
if maxMemoryUsedMB, ok = metrics[string(telemetryapi.MetricMaxMemoryUsedMB)].(float64); !ok {
292286
return nil
293287
}
294288

collector/receiver/telemetryapireceiver/receiver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ func TestCreateLogsWithLogReport(t *testing.T) {
527527
expectedType string
528528
expectedTimestamp string
529529
expectedBody string
530+
expectedAttributes map[string]interface{}
530531
expectError bool
531532
}{
532533
{

0 commit comments

Comments
 (0)