Skip to content

Commit 11a0f10

Browse files
author
brunnert
committed
Improve Metric Parsing
1 parent dae65b7 commit 11a0f10

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

extension/src/test/java/io/retit/opentelemetry/javaagent/extension/JavaAgentExtensionIntegrationTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ void testAllAttributes() {
182182
// no network demand
183183
Assertions.assertEquals(0.0, metricDemandResult.get().metricValue);
184184
}
185-
186185
}
187186
}
188187

@@ -435,22 +434,31 @@ private static List<MetricDemand> extractMetricValuesFromLog(String logMessage)
435434

436435
List<MetricDemand> demands = new ArrayList<>();
437436
String valueAttributeInLog = "value=";
437+
String sampleApplicationName = "io.retit.opentelemetry.SampleApplication";
438+
439+
String emissionMetricNotTransactionRelated = "io.retit.emissions";
438440

439-
String[] seperateMetrics = logMessage.split("ImmutableLongPointData");
440441
for (String key : METRIC_NAMES) {
441-
for (String metricData : seperateMetrics) {
442-
if (metricData.contains(key) && metricData.indexOf(valueAttributeInLog) != -1) {
442+
if (logMessage.contains(key)) {
443+
String dataForCurrentMetric = logMessage.substring(logMessage.indexOf(key) + 1);
444+
445+
if (!key.startsWith(emissionMetricNotTransactionRelated) && dataForCurrentMetric.contains(sampleApplicationName)) {
446+
dataForCurrentMetric = dataForCurrentMetric.substring(dataForCurrentMetric.indexOf(sampleApplicationName));
447+
}
448+
449+
if (dataForCurrentMetric.indexOf(valueAttributeInLog) != -1) {
443450

444451
MetricDemand metricDemand = new MetricDemand();
445-
int valueIndex = metricData.indexOf(valueAttributeInLog);
452+
int valueIndex = dataForCurrentMetric.indexOf(valueAttributeInLog);
446453

447-
String valueString = metricData.substring(valueIndex + valueAttributeInLog.length(), metricData.indexOf(",", valueIndex));
454+
String valueString = dataForCurrentMetric.substring(valueIndex + valueAttributeInLog.length(), dataForCurrentMetric.indexOf(",", valueIndex));
448455
double value = Double.parseDouble(valueString);
449456

450457
metricDemand.metricName = key;
451458
metricDemand.metricValue = value;
452459
demands.add(metricDemand);
453460
}
461+
454462
}
455463

456464
}

0 commit comments

Comments
 (0)