generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reporting of errors sent through Error Processor
- Loading branch information
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...er/src/main/java/io/micronaut/http/server/exceptions/response/ErrorResponseProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.micronaut.http.server.exceptions.response; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.MutableHttpResponse; | ||
|
||
@Weave(type = MatchType.Interface) | ||
public abstract class ErrorResponseProcessor<T> { | ||
|
||
public MutableHttpResponse<T> processResponse(ErrorContext errorContext, MutableHttpResponse<?> baseResponse) { | ||
if(errorContext.hasErrors()) { | ||
HttpRequest<?> request = errorContext.getRequest(); | ||
HashMap<String, Object> attributes = new HashMap<>(); | ||
List<Error> errorList = errorContext.getErrors(); | ||
attributes.put("NumberOfErrors", errorList.size()); | ||
attributes.put("Request-Path", request.getPath()); | ||
attributes.put("Request-URI", request.getUri()); | ||
attributes.put("Request-Method", request.getMethod()); | ||
attributes.put("Request-ServerName", request.getServerName()); | ||
Optional<Throwable> rootCause = errorContext.getRootCause(); | ||
if(rootCause.isPresent()) NewRelic.noticeError(rootCause.get(), attributes); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
} |