ApplicationInsights-Java icon indicating copy to clipboard operation
ApplicationInsights-Java copied to clipboard

Application Insights Java Agent does not track Request in a Server Server Event Rest API

Open apescione opened this issue 1 year ago • 4 comments

Context

I'm using a Spring Boot Application (Java) and WebFlux as the web layer (Reactor), and Reactor Netty is used as an Embedded web server. In my application, I've Server-Sent-Event API like this:

  @RequestMapping(value = "/messages",
        produces = {"text/event-stream", "application/stream+json"},
        method = RequestMethod.GET)
    public Mono<ResponseEntity<Flux<ServerSentEvent<String>>>> getSseMessages() {

This API sends events to clients using a HOT Stream. I'm using the Application Insights java agent to instrument my application deployed into a docker container. I cannot see in Application insights, Log section the requests through this API. I can see other API's requests. This behavior is only with netty (default embedded web server for spring webflux), but not with undertow and tomcat.

Expected behavior I am seeing the invocation request in Application insight for Server Sent Event API.

Actual behavior Java Agent cannot send Request log to application insight ... To Reproduce It's very simple, create with web flux a server sent event api that produces an event every few seconds, connect the client (browser is enough).

Sample Application
@RestController
@RequestMapping("/api")
public class ServerSentEventApi {
...


    @RequestMapping(value = "/messages",
        produces = {"text/event-stream", "application/stream+json"},
        method = RequestMethod.GET)
    public Mono<ResponseEntity<Flux<ServerSentEvent<String>>>> getSseMessages() {
        Flux<ServerSentEvent<String>> sseFlux = Flux.interval(Duration.ofSeconds(5))
            .map(i -> ServerSentEvent.<String>builder().event("ping")
                .data(i.toString()).id(RandomStringUtils.randomAlphanumeric(8)).build());
        return Mono.just(ResponseEntity.ok().body(sseFlux));
    }
...

}

System information Please provide the following information:

SDK Version: Java 8 Zulu, Spring Boot 2.6.8, Webflux 5.3.20, netty 4.1.77 OS type and version: Container Linux alphine Application Insight Java Agent version 3.4.9

Many thanks for considering my request.

apescione avatar Mar 01 '23 15:03 apescione