Pass context to content length http metrics meters (#7506)

Closes
https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7505

Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
This commit is contained in:
Anurag Agarwal 2023-01-18 11:01:31 +05:30 committed by GitHub
parent b9c10c9607
commit 7c4f99c093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 11 deletions

View File

@ -98,7 +98,7 @@ public final class HttpClientMetrics implements OperationListener {
getAttribute(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
if (requestLength != null) {
requestSize.record(requestLength, durationAndSizeAttributes);
requestSize.record(requestLength, durationAndSizeAttributes, context);
}
Long responseLength =
getAttribute(
@ -106,7 +106,7 @@ public final class HttpClientMetrics implements OperationListener {
endAttributes,
state.startAttributes());
if (responseLength != null) {
responseSize.record(responseLength, durationAndSizeAttributes);
responseSize.record(responseLength, durationAndSizeAttributes, context);
}
}

View File

@ -111,7 +111,7 @@ public final class HttpServerMetrics implements OperationListener {
getAttribute(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
if (requestLength != null) {
requestSize.record(requestLength, durationAndSizeAttributes);
requestSize.record(requestLength, durationAndSizeAttributes, context);
}
Long responseLength =
getAttribute(
@ -119,7 +119,7 @@ public final class HttpServerMetrics implements OperationListener {
endAttributes,
state.startAttributes());
if (responseLength != null) {
responseSize.record(responseLength, durationAndSizeAttributes);
responseSize.record(responseLength, durationAndSizeAttributes, context);
}
}

View File

@ -114,7 +114,12 @@ class HttpClientMetricsTest {
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
equalTo(stringKey("net.peer.sock.addr"), "1.2.3.4")))),
equalTo(stringKey("net.peer.sock.addr"), "1.2.3.4"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))),
metric ->
assertThat(metric)
.hasName("http.client.response.size")
@ -131,7 +136,12 @@ class HttpClientMetricsTest {
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
equalTo(stringKey("net.peer.sock.addr"), "1.2.3.4")))));
equalTo(stringKey("net.peer.sock.addr"), "1.2.3.4"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));
listener.onEnd(context2, responseAttributes, nanos(300));

View File

@ -183,7 +183,12 @@ class HttpServerMetricsTest {
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
equalTo(SemanticAttributes.NET_HOST_PORT, 1234)))),
equalTo(SemanticAttributes.NET_HOST_PORT, 1234))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId(spanContext1.getTraceId())
.hasSpanId(spanContext1.getSpanId())))),
metric ->
assertThat(metric)
.hasName("http.server.response.size")
@ -200,7 +205,12 @@ class HttpServerMetricsTest {
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
equalTo(SemanticAttributes.NET_HOST_PORT, 1234)))));
equalTo(SemanticAttributes.NET_HOST_PORT, 1234))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId(spanContext1.getTraceId())
.hasSpanId(spanContext1.getSpanId())))));
listener.onEnd(context2, responseAttributes, nanos(300));
@ -210,7 +220,16 @@ class HttpServerMetricsTest {
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(0))),
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(0)
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId(spanContext2.getTraceId())
.hasSpanId(spanContext2.getSpanId())))),
metric ->
assertThat(metric)
.hasName("http.server.duration")
@ -230,13 +249,29 @@ class HttpServerMetricsTest {
.hasName("http.server.request.size")
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(point -> point.hasSum(200 /* bytes */))),
histogram.hasPointsSatisfying(
point ->
point
.hasSum(200 /* bytes */)
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId(spanContext2.getTraceId())
.hasSpanId(spanContext2.getSpanId())))),
metric ->
assertThat(metric)
.hasName("http.server.response.size")
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(point -> point.hasSum(400 /* bytes */))));
histogram.hasPointsSatisfying(
point ->
point
.hasSum(400 /* bytes */)
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId(spanContext2.getTraceId())
.hasSpanId(spanContext2.getSpanId())))));
}
@Test