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:
parent
b9c10c9607
commit
7c4f99c093
|
@ -98,7 +98,7 @@ public final class HttpClientMetrics implements OperationListener {
|
||||||
getAttribute(
|
getAttribute(
|
||||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
|
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
|
||||||
if (requestLength != null) {
|
if (requestLength != null) {
|
||||||
requestSize.record(requestLength, durationAndSizeAttributes);
|
requestSize.record(requestLength, durationAndSizeAttributes, context);
|
||||||
}
|
}
|
||||||
Long responseLength =
|
Long responseLength =
|
||||||
getAttribute(
|
getAttribute(
|
||||||
|
@ -106,7 +106,7 @@ public final class HttpClientMetrics implements OperationListener {
|
||||||
endAttributes,
|
endAttributes,
|
||||||
state.startAttributes());
|
state.startAttributes());
|
||||||
if (responseLength != null) {
|
if (responseLength != null) {
|
||||||
responseSize.record(responseLength, durationAndSizeAttributes);
|
responseSize.record(responseLength, durationAndSizeAttributes, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ public final class HttpServerMetrics implements OperationListener {
|
||||||
getAttribute(
|
getAttribute(
|
||||||
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
|
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
|
||||||
if (requestLength != null) {
|
if (requestLength != null) {
|
||||||
requestSize.record(requestLength, durationAndSizeAttributes);
|
requestSize.record(requestLength, durationAndSizeAttributes, context);
|
||||||
}
|
}
|
||||||
Long responseLength =
|
Long responseLength =
|
||||||
getAttribute(
|
getAttribute(
|
||||||
|
@ -119,7 +119,7 @@ public final class HttpServerMetrics implements OperationListener {
|
||||||
endAttributes,
|
endAttributes,
|
||||||
state.startAttributes());
|
state.startAttributes());
|
||||||
if (responseLength != null) {
|
if (responseLength != null) {
|
||||||
responseSize.record(responseLength, durationAndSizeAttributes);
|
responseSize.record(responseLength, durationAndSizeAttributes, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,12 @@ class HttpClientMetricsTest {
|
||||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
|
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
|
||||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||||
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
|
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 ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasName("http.client.response.size")
|
.hasName("http.client.response.size")
|
||||||
|
@ -131,7 +136,12 @@ class HttpClientMetricsTest {
|
||||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
|
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
|
||||||
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
|
||||||
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
|
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));
|
listener.onEnd(context2, responseAttributes, nanos(300));
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,12 @@ class HttpServerMetricsTest {
|
||||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
|
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
|
||||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
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 ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasName("http.server.response.size")
|
.hasName("http.server.response.size")
|
||||||
|
@ -200,7 +205,12 @@ class HttpServerMetricsTest {
|
||||||
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
|
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
|
||||||
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
|
||||||
equalTo(SemanticAttributes.NET_HOST_NAME, "localhost"),
|
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));
|
listener.onEnd(context2, responseAttributes, nanos(300));
|
||||||
|
|
||||||
|
@ -210,7 +220,16 @@ class HttpServerMetricsTest {
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasName("http.server.active_requests")
|
.hasName("http.server.active_requests")
|
||||||
.hasLongSumSatisfying(
|
.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 ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasName("http.server.duration")
|
.hasName("http.server.duration")
|
||||||
|
@ -230,13 +249,29 @@ class HttpServerMetricsTest {
|
||||||
.hasName("http.server.request.size")
|
.hasName("http.server.request.size")
|
||||||
.hasHistogramSatisfying(
|
.hasHistogramSatisfying(
|
||||||
histogram ->
|
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 ->
|
metric ->
|
||||||
assertThat(metric)
|
assertThat(metric)
|
||||||
.hasName("http.server.response.size")
|
.hasName("http.server.response.size")
|
||||||
.hasHistogramSatisfying(
|
.hasHistogramSatisfying(
|
||||||
histogram ->
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue