Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.javaagent.instrumentation.avaje.jex.v3_0;

import static io.opentelemetry.instrumentation.testing.util.MetricAssertions.histogram;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
Expand Down Expand Up @@ -120,14 +121,10 @@ void testHttpRouteMetricWithPathParamResponseSuccessful() {

assertThat(content).isEqualTo(id);
assertThat(response.status().code()).isEqualTo(200);
testing.waitAndAssertMetrics(
testing.waitAndAssertMetricsExactly(
instrumentation,
metric ->
metric
.hasName("http.server.request.duration")
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point -> point.hasAttribute(HTTP_ROUTE, "/test/param/{id}"))));
histogram(
metric -> metric.hasName("http.server.request.duration"),
point -> point.hasAttribute(HTTP_ROUTE, "/test/param/{id}")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.instrumentation.awslambdaevents.v2_2;

import static io.opentelemetry.instrumentation.testing.util.MetricAssertions.histogram;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
Expand All @@ -14,7 +15,9 @@
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingSystemIncubatingValues.AWS_SQS;

import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.testing.assertj.HistogramPointAssert;
import io.opentelemetry.sdk.testing.assertj.MetricAssert;
import java.util.function.Consumer;

public class AwsLambdaSqsMetricsAssertions {

Expand Down Expand Up @@ -45,86 +48,63 @@ public static void assertMetrics(
String errorType,
long failedProcessCount,
String failedProcessErrorType) {
testing.waitAndAssertMetrics(
testing.waitAndAssertMetricsExactly(
instrumentationName,
"messaging.process.duration",
metrics ->
metrics.satisfiesExactly(
metric ->
assertThat(metric)
.hasUnit("s")
.hasDescription("Duration of processing operation.")
.hasHistogramSatisfying(
histogram -> {
if (failedProcessCount == 0) {
histogram.hasPointsSatisfying(
point ->
point
.satisfies(
data ->
assertThat(data.getCount())
.isEqualTo(processCount))
.hasSumGreaterThan(0.0)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "process"),
equalTo(MESSAGING_SYSTEM, AWS_SQS),
equalTo(MESSAGING_DESTINATION_NAME, destination),
equalTo(ERROR_TYPE, errorType)));
} else {
histogram.hasPointsSatisfying(
point ->
point
.satisfies(
data ->
assertThat(data.getCount())
.isEqualTo(processCount))
.hasSumGreaterThan(0.0)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "process"),
equalTo(MESSAGING_SYSTEM, AWS_SQS),
equalTo(MESSAGING_DESTINATION_NAME, destination),
equalTo(ERROR_TYPE, errorType)),
point ->
point
.satisfies(
data ->
assertThat(data.getCount())
.isEqualTo(failedProcessCount))
.hasSumGreaterThan(0.0)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "process"),
equalTo(MESSAGING_SYSTEM, AWS_SQS),
equalTo(MESSAGING_DESTINATION_NAME, destination),
equalTo(ERROR_TYPE, failedProcessErrorType)));
}
})));
testing.waitAndAssertMetrics(
instrumentationName,
"messaging.client.consumed.messages",
metrics ->
metrics.satisfiesExactly(
metric ->
assertThat(metric)
.hasUnit("{message}")
.hasDescription(
"Number of messages that were delivered to the application.")
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(consumedMessageCount)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "process"),
equalTo(MESSAGING_SYSTEM, AWS_SQS),
equalTo(MESSAGING_DESTINATION_NAME, destination),
equalTo(ERROR_TYPE, errorType))))));
assertThat(testing.metrics())
.filteredOn(
metric -> metric.getInstrumentationScopeInfo().getName().equals(instrumentationName))
.extracting(MetricData::getName)
.containsExactlyInAnyOrder(
"messaging.process.duration", "messaging.client.consumed.messages");
processingDurationAssertion(
destination, processCount, errorType, failedProcessCount, failedProcessErrorType),
metric ->
metric
.hasName("messaging.client.consumed.messages")
.hasUnit("{message}")
.hasDescription("Number of messages that were delivered to the application.")
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(consumedMessageCount)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "process"),
equalTo(MESSAGING_SYSTEM, AWS_SQS),
equalTo(MESSAGING_DESTINATION_NAME, destination),
equalTo(ERROR_TYPE, errorType)))));
}

private static Consumer<MetricAssert> processingDurationAssertion(
String destination,
long processCount,
String errorType,
long failedProcessCount,
String failedProcessErrorType) {
Consumer<MetricAssert> metricAssertion =
metric ->
metric
.hasName("messaging.process.duration")
.hasUnit("s")
.hasDescription("Duration of processing operation.");
Consumer<HistogramPointAssert> processPoint =
processPointAssertion(processCount, destination, errorType);

if (failedProcessCount == 0) {
return histogram(metricAssertion, processPoint);
}
return histogram(
metricAssertion,
processPoint,
processPointAssertion(failedProcessCount, destination, failedProcessErrorType));
}

private static Consumer<HistogramPointAssert> processPointAssertion(
long processCount, String destination, String errorType) {
return point ->
point
.satisfies(data -> assertThat(data.getCount()).isEqualTo(processCount))
.hasSumGreaterThan(0.0)
.hasAttributesSatisfyingExactly(
equalTo(MESSAGING_OPERATION_NAME, "process"),
equalTo(MESSAGING_SYSTEM, AWS_SQS),
equalTo(MESSAGING_DESTINATION_NAME, destination),
equalTo(ERROR_TYPE, errorType));
}

private AwsLambdaSqsMetricsAssertions() {}
Expand Down
Loading
Loading