Skip to content

Commit

Permalink
Pass context to content length http metrics meters (#7506)
Browse files Browse the repository at this point in the history
Closes
#7505

Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
  • Loading branch information
anuragagarwal561994 and opentelemetrybot committed Jan 18, 2023
1 parent b9c10c9 commit 7c4f99c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
getAttribute(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
if (requestLength != null) {
requestSize.record(requestLength, durationAndSizeAttributes);
requestSize.record(requestLength, durationAndSizeAttributes, context);
}
Long responseLength =
getAttribute(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
endAttributes,
state.startAttributes());
if (responseLength != null) {
responseSize.record(responseLength, durationAndSizeAttributes);
responseSize.record(responseLength, durationAndSizeAttributes, context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
getAttribute(
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes());
if (requestLength != null) {
requestSize.record(requestLength, durationAndSizeAttributes);
requestSize.record(requestLength, durationAndSizeAttributes, context);
}
Long responseLength =
getAttribute(
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
endAttributes,
state.startAttributes());
if (responseLength != null) {
responseSize.record(responseLength, durationAndSizeAttributes);
responseSize.record(responseLength, durationAndSizeAttributes, context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ void collectsMetrics() {
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")
Expand All @@ -131,7 +136,12 @@ void collectsMetrics() {
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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ void collectsMetrics() {
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")
Expand All @@ -200,7 +205,12 @@ void collectsMetrics() {
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));

Expand All @@ -210,7 +220,16 @@ void collectsMetrics() {
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")
Expand All @@ -230,13 +249,29 @@ void collectsMetrics() {
.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
Expand Down

0 comments on commit 7c4f99c

Please sign in to comment.