Skip to content

fixed the bug of EmfMetricLoggingPublisher not properly publishing Long metrics #6210

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
merged 4 commits into from
Jun 26, 2025
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
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-17f90b1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "EmfMetricLoggingPublisher",
"contributor": "",
"description": "Fixed the bug that EmfMetricLoggingPublisher not properly publishing Long type metrics"
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@ private void processAndWriteValue(JsonWriter jsonWriter, MetricRecord<?> mRecord
return;
}

if (Integer.class.isAssignableFrom(valueClass) || Long.class.isAssignableFrom(valueClass)) {
if (Integer.class.isAssignableFrom(valueClass)) {
jsonWriter.writeValue((Integer) value);
}

if (Long.class.isAssignableFrom(valueClass)) {
jsonWriter.writeValue((Long) value);
}
}

private List<String> createEmfStrings(Map<SdkMetric<?>, List<MetricRecord<?>>> aggregatedMetrics) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,21 @@ void ConvertMetricCollectionToEMF_shouldConformToSchema() throws Exception {

assertThat(errors).isEmpty();
}

@Test
void ConvertMetricCollectionToEMF_longValueShouldSucceed() {
SdkMetric<Long> metric = SdkMetric.create("TestMetric",
Long.class,
MetricLevel.INFO,
MetricCategory.CUSTOM);

MetricCollector metricCollector = MetricCollector.create("test");
Long metricValue = 42L;
metricCollector.reportMetric(metric, metricValue);
List<String> emfLogs = metricEmfConverterDefault.convertMetricCollectionToEmf(metricCollector.collect());

assertThat(emfLogs).containsOnly("{\"_aws\":{\"Timestamp\":12345678,\"LogGroupName\":\"my_log_group_name\","
+ "\"CloudWatchMetrics\":[{\"Namespace\":\"AwsSdk/JavaSdk2\",\"Dimensions\":[[]],"
+ "\"Metrics\":[{\"Name\":\"TestMetric\"}]}]},\"TestMetric\":42}");
}
}
Loading