Skip to content

Commit

Permalink
Fix NPE in request metrics when a finished request is missing a response
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-signal authored and jon-signal committed Dec 6, 2023
1 parent fc0bc85 commit 4fa10e5
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import org.glassfish.jersey.server.ContainerResponse;
import org.glassfish.jersey.server.monitoring.RequestEvent;
import org.glassfish.jersey.server.monitoring.RequestEventListener;
import org.whispersystems.textsecuregcm.storage.ClientReleaseManager;
Expand All @@ -20,6 +21,7 @@
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* Gathers and reports request-level metrics.
Expand Down Expand Up @@ -67,7 +69,10 @@ public void onEvent(final RequestEvent event) {
final List<Tag> tags = new ArrayList<>(5);
tags.add(Tag.of(PATH_TAG, UriInfoUtil.getPathTemplate(event.getUriInfo())));
tags.add(Tag.of(METHOD_TAG, event.getContainerRequest().getMethod()));
tags.add(Tag.of(STATUS_CODE_TAG, String.valueOf(event.getContainerResponse().getStatus())));
tags.add(Tag.of(STATUS_CODE_TAG, String.valueOf(Optional
.ofNullable(event.getContainerResponse())
.map(ContainerResponse::getStatus)
.orElse(499))));
tags.add(Tag.of(TRAFFIC_SOURCE_TAG, trafficSource.name().toLowerCase()));

@Nullable final String userAgent;
Expand Down

0 comments on commit 4fa10e5

Please sign in to comment.