Skip to content

Conversation

harsimar
Copy link
Member

This PR will read the following env vars so that the MetricDataMapper can append the necessary attribute to metric / send the metrics to the right places:

OTEL_METRICS_EXPORTER
OTEL_METRICS_EXPORTER_OTLP_ENDPOINT
APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED

Note: still in draft mode because this depends on the azure-sdk-for-java pr, and won't build until I build on top of this pr. I also need to test the e2e behavior once I have a built java agent.

@trask trask force-pushed the harskaur/aksMetrics branch from 732a57f to 0f009a6 Compare September 20, 2025 00:48
@trask trask changed the base branch from main to trask/update-to-azure-sdk-latest September 20, 2025 01:03
@trask trask force-pushed the harskaur/aksMetrics branch from 1e05ccc to 9aec7b3 Compare September 20, 2025 01:09
@xiang17 xiang17 changed the base branch from trask/update-to-azure-sdk-latest to main September 25, 2025 20:43
@xiang17 xiang17 marked this pull request as ready for review September 25, 2025 21:00
Comment on lines +54 to +75
// sort metrics based on result code
metrics.sort(
Comparator.comparing(
obj -> {
MetricData metricData = (MetricData) ((Data<?>) obj.getData()).getBaseData();
return metricData.getProperties().get("dependency/resultCode");
}));

// 1st pre-aggregated metric
Envelope envelope1 = metrics.get(0);
MetricData md1 = (MetricData) ((Data<?>) envelope1.getData()).getBaseData();
validateMetricData(md1);

// 2nd pre-aggregated metric
Envelope envelope2 = metrics.get(1);
MetricData md2 = (MetricData) ((Data<?>) envelope2.getData()).getBaseData();
validateMetricData(md2);

// 3rd pre-aggregated metric
Envelope envelope3 = metrics.get(2);
MetricData md3 = (MetricData) ((Data<?>) envelope3.getData()).getBaseData();
validateMetricData(md3);
Copy link
Member

Choose a reason for hiding this comment

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

is sorting needed? looks like same verification is performed for all 3

Suggested change
// sort metrics based on result code
metrics.sort(
Comparator.comparing(
obj -> {
MetricData metricData = (MetricData) ((Data<?>) obj.getData()).getBaseData();
return metricData.getProperties().get("dependency/resultCode");
}));
// 1st pre-aggregated metric
Envelope envelope1 = metrics.get(0);
MetricData md1 = (MetricData) ((Data<?>) envelope1.getData()).getBaseData();
validateMetricData(md1);
// 2nd pre-aggregated metric
Envelope envelope2 = metrics.get(1);
MetricData md2 = (MetricData) ((Data<?>) envelope2.getData()).getBaseData();
validateMetricData(md2);
// 3rd pre-aggregated metric
Envelope envelope3 = metrics.get(2);
MetricData md3 = (MetricData) ((Data<?>) envelope3.getData()).getBaseData();
validateMetricData(md3);
for (Envelope envelope : metrics) {
MetricData md = (MetricData) ((Data<?>) envelope.getData()).getBaseData();
validateMetricData(md);
}

private static void verifyHttpServerPreAggregatedMetrics(List<Envelope> metrics) {
assertThat(metrics.size()).isEqualTo(1);
// 1st pre-aggregated metric
Copy link
Member

Choose a reason for hiding this comment

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

(there's only 1)

Suggested change
// 1st pre-aggregated metric
List<Metric> otlpMetrics =
testing.mockedOtlpIngestion.extractMetricsFromRequests(otlpRequests);

assertThat(otlpMetrics).hasSizeGreaterThanOrEqualTo(3);
Copy link
Member

Choose a reason for hiding this comment

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

it may be worth adding assertions about the name and attributes of these 3 metrics

@xiang17 xiang17 enabled auto-merge (squash) September 26, 2025 00:17
@xiang17 xiang17 merged commit d0d252a into main Sep 26, 2025
140 checks passed
@xiang17 xiang17 deleted the harskaur/aksMetrics branch September 26, 2025 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants