Skip to content
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 @@ -111,6 +111,10 @@ public static Transaction<?> getOrCreateTransaction(Tracer tracer, ServerWebExch
return null;
}

if (!fromServlet) {
// Errors captured during dispatch copy the request context immediately.
fillRequest(transaction, exchange);
}
transaction.withType("request").activate();

// store transaction in exchange to make it easy to retrieve from other handlers
Expand Down Expand Up @@ -172,17 +176,15 @@ public static void endTransaction(@Nullable Throwable thrown, @Nullable Transact
return;
}

transaction.captureException(thrown);

// Fill request/response details if they haven't been already by another HTTP plugin (servlet or other).
if (!transaction.getContext().getRequest().hasContent()) {
fillRequest(transaction, exchange);
boolean fromServlet = isServletTransaction(exchange);
if (!fromServlet) {
fillResponse(transaction, exchange);
}
transaction.captureException(thrown);

// In case transaction has been created by Servlet, we should not terminate it as the Servlet instrumentation
// will take care of this.
if (!WebfluxHelper.isServletTransaction(exchange)) {
if (!fromServlet) {
transaction.end();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ void dispatchHello() {
hello(true);
}

@ParameterizedTest
@CsvSource({"01, true", "00, false"})
void unmappedRequestErrorIncludesHttpContext(String traceFlags, boolean sampled) {
client.setHeader("traceparent", "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-" + traceFlags);
StepVerifier.create(client.getMappingError404())
.expectErrorMatches(expectClientError(404))
.verify();

ErrorCaptureImpl error = getFirstError();
assertThat(error.getTransactionInfo().isSampled()).isEqualTo(sampled);
RequestImpl request = error.getContext().getRequest();
assertThat(request.getMethod()).isEqualTo("GET");
assertThat(request.getUrl().getHostname()).isEqualTo("localhost");
assertThat(request.getUrl().getPathname()).isEqualTo(client.getPathPrefix() + "/error-404");
assertThat(error.getContext().getResponse().getStatusCode()).isEqualTo(404);
}

private void hello(boolean expectHeaders) {
client.setHeader("random-value", "12345");
client.setCookie("cookie", "gdpr-compliant-no-chocolate-here");
Expand Down
Loading