Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always pass Context when recording HttpServerMetrics #6223

Merged
Merged
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 @@ -82,7 +82,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
context);
return;
}
activeRequests.add(-1, applyActiveRequestsView(state.startAttributes()));
activeRequests.add(-1, applyActiveRequestsView(state.startAttributes()), context);
duration.record(
(endNanos - state.startTimeNanos()) / NANOS_PER_MS,
applyServerDurationView(state.startAttributes(), endAttributes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ void collectsMetrics() {
.put("http.status_code", 200)
.build();

Context parent =
Context.root()
.with(
Span.wrap(
SpanContext.create(
"ff01020304050600ff0a0b0c0d0e0f00",
"090a0b0c0d0e0f00",
TraceFlags.getSampled(),
TraceState.getDefault())));

Context context1 = listener.onStart(parent, requestAttributes, nanos(100));
SpanContext spanContext1 =
SpanContext.create(
"ff01020304050600ff0a0b0c0d0e0f00",
"090a0b0c0d0e0f00",
TraceFlags.getSampled(),
TraceState.getDefault());
SpanContext spanContext2 =
SpanContext.create(
"123456789abcdef00000000000999999",
"abcde00000054321",
TraceFlags.getSampled(),
TraceState.getDefault());

Context parent1 = Context.root().with(Span.wrap(spanContext1));
Context context1 = listener.onStart(parent1, requestAttributes, nanos(100));

assertThat(metricReader.collectAllMetrics())
.satisfiesExactlyInAnyOrder(
Expand All @@ -81,18 +85,32 @@ void collectsMetrics() {
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));
.hasTraceId(spanContext1.getTraceId())
.hasSpanId(spanContext1.getSpanId())))));

Context context2 = listener.onStart(Context.root(), requestAttributes, nanos(150));
Context parent2 = Context.root().with(Span.wrap(spanContext2));
Context context2 = listener.onStart(parent2, requestAttributes, nanos(150));

assertThat(metricReader.collectAllMetrics())
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(2))));
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(2)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_HOST, "host"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId(spanContext2.getTraceId())
.hasSpanId(spanContext2.getSpanId())))));

listener.onEnd(context1, responseAttributes, nanos(250));

Expand All @@ -102,7 +120,20 @@ void collectsMetrics() {
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(1))),
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_HOST, "host"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId(spanContext1.getTraceId())
.hasSpanId(spanContext1.getSpanId())))),
metric ->
assertThat(metric)
.hasName("http.server.duration")
Expand All @@ -122,8 +153,8 @@ void collectsMetrics() {
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));
.hasTraceId(spanContext1.getTraceId())
.hasSpanId(spanContext1.getSpanId())))));

listener.onEnd(context2, responseAttributes, nanos(300));

Expand All @@ -140,7 +171,14 @@ void collectsMetrics() {
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point -> point.hasSum(300 /* millis */))));
point ->
point
.hasSum(300 /* millis */)
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId(spanContext2.getTraceId())
.hasSpanId(spanContext2.getSpanId())))));
}

@Test
Expand Down